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_intervalaccess: 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.
timeInterval must match your real scrape interval. If it says 15s but
you scrape every 60s, $__rate_interval comes out as 1 minute, which
holds only one sample, and every rate() panel has gaps.
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:
| Option | What it does |
|---|---|
| Legend | {{route}} names each series by its label. "Auto" is often unreadable. |
| Format | Time series for graphs, Table for tables, Heatmap for histogram buckets |
| Type | Range for graphs; Instant for stats and tables showing only the current value |
| Min interval | Lower bound on the step. Usually leave empty and let $__rate_interval work |
Choosing a visualisation
| Visualisation | Use for | Example from this stack |
|---|---|---|
| Time series | Anything over time. The default. | Requests by route |
| Stat | One headline number, coloured by threshold | Current error ratio |
| Gauge / Bar gauge | A value against a known maximum; ranking a few items | Series per job |
| Table | Many series' current values, labels as columns | Target status, build info |
| Heatmap | Distributions over time (histogram buckets) | Latency distribution |
| State timeline | Discrete states over time | up per target |
| Logs / Traces | Loki and Tempo data | Beyond 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:
| Data | Unit |
|---|---|
*_seconds | Time → seconds (s). Grafana shows 0.023 as "23 ms". |
*_bytes | Data → bytes (IEC). 1073741824 becomes "1 GiB". |
| Ratios 0-1 | Misc → Percent (0.0-1.0) |
| Request rates | Throughput → 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
upinto clean columns withjob,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
topkon a graph. - Reduce: one row per series with last, mean, max. Good for summary tables.
Prefer doing work in PromQL over transformations when you can. PromQL results can be reused by recording rules and alerts; transformations only exist in that one panel, and they run in every viewer's browser.
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.