Open-Source Wikis

/

Grafana

/

Backend

/

Live

grafana/grafana

Live streaming

pkg/services/live/ provides Grafana's WebSocket-backed pub/sub layer. It powers:

  • Live tail in Explore (logs/metrics streaming).
  • Real-time dashboard updates ("user X edited this dashboard").
  • Annotation broadcasts and other small UI events.
  • The Push API for external publishers.

Implementation

The transport is Centrifuge, embedded directly. Centrifuge handles WebSocket framing, presence, history, and per-channel access control hooks.

pkg/services/live/
├── live.go                # GrafanaLive service struct + lifecycle
├── feature/               # Per-feature channel handlers (dashboard, ds, push, ...)
├── managedstream/         # Stream registry that buffers live frames
├── pipeline/              # Channel pipeline (parsing/filtering rules)
├── pushhttp/, pushws/     # External publisher endpoints
├── liveplugin/            # Bridge between SDK plugins and Live
├── orgchannel/            # Per-org channel namespacing
├── runstream/             # Plugin-driven streaming
└── (more)

Channels

A channel is a string like grafana/dashboard/uid/<uid> or ds/<dsuid>/<query>. Each channel namespace (<scope>) maps to a feature handler that knows how to authorize subscriptions and (optionally) produce data.

Built-in scopes:

  • grafana/ — internal Grafana events (dashboard saved, plugin enabled, etc.)
  • plugin/ — events emitted by app plugins
  • ds/ — datasource plugin streams (e.g. Loki tail, Tempo Live)
  • stream/ — managed streams produced by external publishers
  • push/ — external HTTP/WS push targets

Subscribe flow

sequenceDiagram
    participant Browser as Frontend Live
    participant Centrifuge as Centrifuge node
    participant Live as live.GrafanaLive
    participant Handler as feature handler
    participant Plugin as plugin host (if ds:*)

    Browser->>Centrifuge: WS connect (token from Grafana)
    Centrifuge->>Live: OnSubscribe(channel)
    Live->>Handler: GetChannelHandler(channel)
    Handler->>Live: authorize identity for channel
    Live-->>Centrifuge: ok
    Plugin-->>Live: SubscribeStream (if backend stream)
    Plugin-->>Live: published frames
    Live-->>Centrifuge: publish
    Centrifuge-->>Browser: frames

Push API

External publishers can send measurements into Grafana via the Push API (pkg/services/live/pushhttp/ and pkg/services/live/pushws/). The pipeline can transform incoming data (e.g. parse a JSON path, regroup) before broadcasting it to subscribers.

HA

Centrifuge supports a Redis broker for horizontal scaling. Configure with [live] ha_engine = redis and ha_engine_address = redis://.... Without HA, each Grafana node operates independently and clients see only the events generated on the node they're connected to.

Frontend integration

The frontend datasource plugin SDK exposes streaming via runQuery returning an Observable; under the hood, datasources that support streaming open a Live channel and push DataFrames into the observable. See @grafana/runtime for the client API.

Key source files

File Purpose
pkg/services/live/live.go Service struct, channel router, lifecycle
pkg/services/live/feature/ Per-namespace channel handlers
pkg/services/live/pipeline/ Configurable channel pipelines
pkg/services/live/managedstream/ Buffered streams
pkg/services/live/pushhttp/ HTTP push endpoint
pkg/services/live/runstream/ Plugin-driven streams

Built by Factory AutoWiki from public repository content. It is a generated preview for codebase exploration, not source-maintained documentation.

Live – Grafana wiki | Factory