Learn Labs
Grafana

Data Sources & Panels

Visualisations, units, thresholds, and the query editor

Prometheus's own UI is for exploring. Grafana is for the dashboards you keep: it queries Prometheus (and dozens of other data sources), and gives you layout, units, colours, variables, links, and permissions.

Open http://localhost:3001 and log in with the credentials from prometheus/.env.

Data sources

A data source is a connection: type, URL, credentials. This stack provisions two from grafana/provisioning/datasources/datasources.yml:

- name: Prometheus
type: prometheus
uid: prometheus              # stable ID that dashboards reference
url: http://prometheus:9090  # resolved by Grafana's container, not your browser
access: proxy                # Grafana's server makes the request
isDefault: true
jsonData:
  timeInterval: 15s          # = scrape_interval; drives $__rate_interval

access: proxy means the Grafana server talks to Prometheus, so the URL uses the Docker network name prometheus, and Prometheus never has to be reachable from your browser. That's also what lets Grafana add auth headers without exposing them.

Grafana panelPrometheus APITSDBquery_range, step = $__intervalselect series by label indexsamples per seriesone point per step

Explore first

Before building a panel, use Explore (the compass icon): pick Prometheus, type a query, see the result. The metrics browser lists every metric and its labels; Code mode gives you autocompletion. Explore is also where you'll do incident investigation. It's a scratchpad, not a dashboard.

Anatomy of a panel

Every panel is: queries → optional transformations → a visualisation with field config (units, min/max, thresholds, mappings, overrides).

Query options you'll actually use:

OptionWhat it does
Legend{{route}} names each series by its label. "Auto" is often unreadable.
FormatTime series for graphs, Table for tables, Heatmap for histogram buckets
TypeRange for graphs; Instant for stats and tables showing only the current value
Min intervalLower bound on the step. Usually leave empty and let $__rate_interval work

Choosing a visualisation

VisualisationUse forExample from this stack
Time seriesAnything over time. The default.Requests by route
StatOne headline number, coloured by thresholdCurrent error ratio
Gauge / Bar gaugeA value against a known maximum; ranking a few itemsSeries per job
TableMany series' current values, labels as columnsTarget status, build info
HeatmapDistributions over time (histogram buckets)Latency distribution
State timelineDiscrete states over timeup per target
Logs / TracesLoki and Tempo dataBeyond Metrics

Avoid pie charts for anything that changes over time, and avoid gauges for values with no meaningful maximum.

Units, thresholds, mappings

Units make numbers readable and are the most-skipped setting. Set them on every panel:

DataUnit
*_secondsTime → seconds (s). Grafana shows 0.023 as "23 ms".
*_bytesData → bytes (IEC). 1073741824 becomes "1 GiB".
Ratios 0-1Misc → Percent (0.0-1.0)
Request ratesThroughput → requests/sec

Thresholds colour a value: green below 0.5%, orange to 5%, red above. The Error ratio stat panel on the RED dashboard uses exactly that. On time series panels you can draw them as lines with Show thresholds → As lines.

Value mappings turn numbers into words: 0 → DOWN (red), 1 → UP (green). Used on the Target status table.

Overrides apply settings to specific series only. For example, put the 500 status series in red regardless of palette, or move one series to a right-hand Y axis.

Transformations

Transformations reshape query results in the browser, after Prometheus returns them:

  • Labels to fields / Organize fields: turn a table of up into clean columns with job, instance, value.
  • Join by field: combine two queries into one table, for example current RPS and current error ratio per route.
  • Sort by / Limit: a "top 10" table that is stable, unlike topk on a graph.
  • Reduce: one row per series with last, mean, max. Good for summary tables.

Lab: build a node dashboard

Create a new dashboard (Dashboards → New) with four panels, all from node_exporter:

# 1. CPU busy (time series, unit percent 0-1, max 1)
1 - avg(rate(node_cpu_seconds_total{mode="idle"}[$__rate_interval]))

# 2. Memory used (stat, unit percent 0-1, thresholds 0.8 orange / 0.9 red)
1 - node_memory_MemAvailable_bytes / node_memory_MemTotal_bytes

# 3. Disk free by mountpoint (bar gauge, unit bytes IEC, legend {{mountpoint}})
node_filesystem_avail_bytes{fstype!~"tmpfs|overlay"}

# 4. Network in/out (time series, unit bytes/sec; negative-Y override on "out")
sum(rate(node_network_receive_bytes_total{device!~"lo|veth.*"}[$__rate_interval]))
sum(rate(node_network_transmit_bytes_total{device!~"lo|veth.*"}[$__rate_interval]))

For panel 4, add an override on the transmit series with Transform → Negative Y, a common convention so in and out mirror each other. Save it. In Dashboards as Code you'll export it into the repo.

On this page