Grafana: Dashboards & visualization

This content was generated with the assistance of AI and should be verified against the official documentation before being relied on in production.

Prometheus stores and evaluates time series; it does not itself build dashboards — the expression browser’s Graph tab is deliberately minimal, meant for ad-hoc queries rather than a shared operational view. Grafana is the visualization layer almost every Prometheus deployment sits behind: it queries Prometheus (and other backends) over HTTP, arranges the results into panels on a dashboard, and lets those dashboards be parameterized and shared. This page covers installing Grafana, connecting it to a Prometheus server, the panel types a dashboard is built from, and template variables that make one dashboard work across many jobs or instances.

The running example is the orders-api service from Recording & Alerting Rules: a provisioned data source, a provisioned dashboard whose panels read the recorded series job:http_requests_errors:ratio_rate5m and job_status:http_requests:rate5m, and a job variable. All of it was loaded into a real Grafana 13.3 container and verified through Grafana’s HTTP API.

flowchart LR U["Browser"] -->|"dashboard JSON, variables"| GF["Grafana server"] GF -->|"access: proxy
PromQL over HTTP"| PR["Prometheus
/api/v1/query_range"] PR --> TS[("TSDB and
recorded series")] FILES["provisioning/
datasources, dashboards"] -->|"read at startup"| GF DJ["dashboards/*.json"] -->|"polled every N seconds"| GF

Because the browser never talks to Prometheus directly with access: proxy, the Prometheus server does not need to be reachable from user machines and its credentials (if any) stay inside the Grafana configuration.

For a deeper treatment of the same topics, see the Grafana subsection of Monitoring & Alerting: Building Dashboards, Variables and Graphs & Charts.

Installing Grafana

Grafana ships as a binary package, a Docker image, or an OS package, and always listens on :3000 with a default admin/admin login that it forces you to change on first sign-in. See Install Grafana for every installation method and platform in full, including the Windows and macOS installers not shown here.

Docker

The official image is published as grafana/grafana-oss (open-source edition) on Docker Hub. Publish port 3000 and bind-mount a volume so dashboards and users survive a container restart:

docker run -d --name grafana -p 3000:3000 \
  -v grafana-storage:/var/lib/grafana \
  grafana/grafana-oss
# http://localhost:3000, default login admin/admin
# https://grafana.com/docs/grafana/latest/setup-grafana/installation/

Package manager / binary

On Debian/Ubuntu, Grafana’s own APT repository installs and manages the service:

sudo apt-get install -y apt-transport-https software-properties-common
sudo mkdir -p /etc/apt/keyrings/
wget -q -O - https://apt.grafana.com/gpg.key | gpg --dearmor | sudo tee /etc/apt/keyrings/grafana.gpg > /dev/null
echo "deb [signed-by=/etc/apt/keyrings/grafana.gpg] https://apt.grafana.com stable main" | sudo tee /etc/apt/sources.list.d/grafana.list
sudo apt-get update && sudo apt-get install -y grafana
sudo systemctl enable --now grafana-server
# https://grafana.com/docs/grafana/latest/setup-grafana/installation/

A complete, reproducible start for the lab combines the data source and dashboard provisioning directories with the container (the folders are mounted read-only, so a UI edit cannot drift from what is in version control):

docker run -d --name grafana -p 3000:3000 \
  -v "$PWD/provisioning":/etc/grafana/provisioning:ro \
  -v "$PWD/dashboards":/var/lib/grafana/dashboards:ro \
  grafana/grafana-oss
curl -s localhost:3000/api/health
{ "database": "ok", "version": "13.3.0", "commit": "6f8ce3c693b493043ebcd4787566d2b6b118b0f0" }

The health endpoint needs no login and is what a container orchestrator should probe. On first start Grafana runs its database migrations and (in current releases) may install bundled plugins, so allow tens of seconds before the API answers; the lab saw requests time out for the first minute on a busy machine.

The standalone binary archive (no root, no service manager) works the same way as Prometheus’s own tarball install described in Getting Started: extract it and run ./bin/grafana server from the extracted directory. Whichever method is used, the first sign-in at http://localhost:3000 prompts for a new admin password before anything else is usable.

Adding the Prometheus data source

A data source tells Grafana where to send queries. Prometheus is a first-class data source type — its query editor understands PromQL directly, including autocomplete against the metrics and labels the target server actually has. See Prometheus data source for every configuration field.

Via the UI

Connections > Data sources > Add data source > Prometheus, then set the Prometheus server URL (http://localhost:9090 for a local server, or the in-cluster service DNS name when both run in Kubernetes) and Save & test. Grafana confirms the connection by querying the target’s /api/v1/query endpoint before saving.

Via provisioning

Clicking through the UI does not survive a redeployed container or a fresh environment. Grafana reads any YAML file dropped into provisioning/datasources/ at startup and creates or updates data sources from it — the infrastructure-as-code equivalent of the UI form above:

apiVersion: 1

datasources:
  - name: Prometheus
    type: prometheus
    access: proxy
    url: http://prometheus:9090
    isDefault: true
    jsonData:
      httpMethod: POST
      timeInterval: 15s
# https://grafana.com/docs/grafana/latest/datasources/prometheus/

Giving the data source a fixed uid matters: dashboards and alert rules refer to a data source by its uid, and a provisioned uid is the same in every environment, whereas a generated one differs. After startup the data source was visible through the API as read-only (a provisioned data source cannot be edited in the UI), and its health check queried Prometheus:

curl -s -u admin:admin localhost:3000/api/datasources/uid/prometheus-uid/health
{ "details": { "application": "Prometheus", "features": { "rulerApiEnabled": false } },
  "message": "Successfully queried the Prometheus API.", "status": "OK" }

access: proxy routes the browser’s query through the Grafana server rather than calling Prometheus directly from the client — the setting almost every deployment wants. Mount this file at /etc/grafana/provisioning/datasources/prometheus.yaml in the Docker image above (or the Kubernetes-native equivalent, a ConfigMap) and it is present on every container start with no manual step; dashboards can be provisioned the same way, covered next.

Dashboards and panel types

A dashboard is a grid of panels, each running its own query (or queries) against a data source and rendering the result with a chosen visualization. See Dashboards for creating, organizing, and sharing them, and Panels & visualizations for the full visualization catalog beyond the five below.

Panel type When to use it

Time series

The default choice for anything with a meaningful time axis — request rate, latency, memory over time. Plots one or more series as lines or bars against wall-clock time; the panel most Prometheus dashboards are built from.

Stat

A single current number, optionally with a sparkline and threshold-driven color — "requests per second right now," "error rate this hour." Reduces a query down to one value per series rather than plotting a time axis.

Gauge

The same single-value reduction as Stat, drawn as an arc against a min/max range — best when the position within a bounded range matters more than the raw number, such as disk usage approaching 100%.

Table

Tabular results — one row per label combination, one column per field — for browsing raw series values or an instant-vector query’s full label set rather than a trend.

Bar gauge

Like Gauge but one bar per series instead of one arc for the whole panel — comparing a bounded value (queue depth against a configured max, disk usage) across many instances or jobs at once.

Panels compose into a dashboard through Grafana’s own editor — drag to resize, add a panel, pick its visualization and query — but every dashboard is, underneath, one JSON document (the dashboard model): panels, their queries, layout, and variables as a single serializable object. Building through the UI and hand-editing (or generating) that JSON are two views of the same thing, and both remain fully compatible — a dashboard built by hand can be exported to JSON for version control, and a JSON file authored or generated elsewhere (a provisioning pipeline, a dashboard shared from Grafana’s public dashboard library) imports and edits in the UI exactly like one built there from scratch. Provisioning dashboards from files works the same way as the data source YAML above, via provisioning/dashboards/ pointing at a directory of these JSON files, so a dashboard ships with its data source rather than being recreated by hand in each environment.

A provisioned dashboard for the example

The provider file tells Grafana where the JSON files live, which folder to place them in, and how often to re-read them:

# provisioning/dashboards/orders.yaml
apiVersion: 1

providers:
  - name: orders
    folder: Orders API
    type: file
    disableDeletion: false
    allowUiUpdates: false
    updateIntervalSeconds: 30
    options:
      path: /var/lib/grafana/dashboards

and the dashboard itself is one JSON file with a job variable, a stat panel reading the recorded error ratio, and a time series panel reading the recorded per-status request rate:

{
  "uid": "orders-api-overview",
  "title": "Orders API overview",
  "schemaVersion": 41,
  "refresh": "10s",
  "time": { "from": "now-30m", "to": "now" },
  "templating": {
    "list": [
      {
        "name": "job",
        "type": "query",
        "datasource": { "type": "prometheus", "uid": "prometheus-uid" },
        "query": { "query": "label_values(job:http_requests:rate5m, job)", "refId": "job" },
        "refresh": 2,
        "includeAll": true,
        "multi": true
      }
    ]
  },
  "panels": [
    {
      "id": 1,
      "type": "stat",
      "title": "Error ratio (5m)",
      "gridPos": { "x": 0, "y": 0, "w": 6, "h": 5 },
      "datasource": { "type": "prometheus", "uid": "prometheus-uid" },
      "targets": [
        { "refId": "A", "expr": "job:http_requests_errors:ratio_rate5m{job=~\"$job\"}", "instant": true }
      ],
      "fieldConfig": {
        "defaults": {
          "unit": "percentunit",
          "thresholds": {
            "mode": "absolute",
            "steps": [ { "color": "green", "value": null }, { "color": "red", "value": 0.05 } ]
          }
        }
      }
    },
    {
      "id": 2,
      "type": "timeseries",
      "title": "Requests per second by status",
      "gridPos": { "x": 6, "y": 0, "w": 18, "h": 8 },
      "datasource": { "type": "prometheus", "uid": "prometheus-uid" },
      "targets": [
        { "refId": "A", "expr": "job_status:http_requests:rate5m{job=~\"$job\"}", "legendFormat": "{{status}}" }
      ],
      "fieldConfig": { "defaults": { "unit": "reqps" } }
    }
  ]
}

The stat panel’s red threshold at 0.05 mirrors the alert rule’s 5% threshold, so the number on screen turns red at the moment the alert would start counting down. legendFormat names each line after its status label (Grafana substitutes the label value between double braces).

After the lab started, the dashboard was registered and marked as provisioned, in the Orders API folder, with both panels:

provisioned: True   folder: Orders API   panels: ['Error ratio (5m)', 'Requests per second by status']

Grafana’s variable query was exercised through the data-source proxy, which is exactly the request the dropdown makes: it returned ["orders-api"] for label_values(job:http_requests:rate5m, job), and a panel query with $job substituted returned one frame per status (200, 201, 500).

Because allowUiUpdates is false, a change made in the UI is not saved to the file and is lost on the next provisioning pass; to change a provisioned dashboard, edit the JSON (the editor’s Export > Export as JSON gives the model of a UI-built one) and wait for updateIntervalSeconds to elapse.

Template variables

A dashboard hard-coded to one job or instance only ever shows that one target. A template variable turns part of a panel’s query into a dropdown the viewer picks from, so one dashboard serves every job, instance, or namespace scraped by Prometheus. See Variables for every variable type beyond the query-backed one below.

A query-type variable, backed by Prometheus’s label_values() helper, lists every distinct value a label takes across a metric (or across the whole TSDB, if the metric argument is omitted):

label_values(up, instance)

Define instance as a dashboard variable with that query, enable Multi-value and Include All if every target should be selectable at once, and reference it from a panel’s PromQL with $instance (or ${instance} where the surrounding syntax needs braces):

up{instance=~"$instance"}

Against the lab server the same label_values lookup on up returned both scraped instances:

["host.docker.internal:27411", "localhost:9090"]

=~ is required, not =, because a multi-value selection expands to a regex alternation ("web-1|web-2") rather than a single string — the same regex matcher covered in PromQL: Basics & Selectors. Variables can also chain: a job variable’s label_values() query can itself be scoped so a dependent instance variable only lists instances belonging to the currently selected job, keeping large multi-team dashboards navigable instead of listing every instance in the cluster at once.

Continue with Grafana Alerting for alerting rules defined and evaluated inside Grafana itself, as distinct from the Prometheus-side rules covered in Recording & Alerting Rules and routed by Alertmanager.

For Grafana dashboards of Apache JMeter load-test metrics next to these server metrics, see Real-time Monitoring with Backend Listener.