Grafana: Data Sources & Panels
Grafana is the dashboard and exploration UI for everything in this course: it queries Prometheus with PromQL, Loki with LogQL and Tempo or Jaeger with TraceQL, and shows them side by side. It stores nothing itself except its own configuration (dashboards, users, alert rules), in SQLite by default or PostgreSQL/MySQL for HA.
Grafana is a web application and isn't in this course's sandbox, so its parts appear as configuration files (which you would keep in Git anyway) and sample screens.
Running it
# sample session: Grafana next to a local Prometheus
docker run -d --name grafana -p 3000:3000 \
-v "$PWD/provisioning:/etc/grafana/provisioning" \
grafana/grafana:13.2.0
# open http://localhost:3000 (admin / admin on first login, then change it)In Kubernetes, kube-prometheus-stack installs Grafana with the Prometheus data source and a set of cluster dashboards already provisioned. Grafana Cloud is the hosted option.
Data sources as code
Every query goes to a data source. Click-created data sources drift between environments; provisioning files in /etc/grafana/provisioning/datasources/ create them at startup:
# provisioning/datasources/observability.yaml
apiVersion: 1
datasources:
- name: Prometheus
uid: prometheus # stable uid: dashboards reference data sources by uid
type: prometheus
access: proxy # the Grafana server makes the requests, not the browser
url: http://prometheus:9090
isDefault: true
jsonData:
timeInterval: 15s # the scrape interval: used by $__rate_interval
exemplarTraceIdDestinations:
- name: trace_id
datasourceUid: tempo # click an exemplar dot → open the trace in Tempo
- name: Loki
uid: loki
type: loki
url: http://loki:3100
jsonData:
derivedFields: # turn trace_id=… in log lines into a link to Tempo
- name: TraceID
matcherRegex: '"trace_id":"(\w+)"'
datasourceUid: tempo
url: '${__value.raw}'
- name: Tempo
uid: tempo
type: tempo
url: http://tempo:3200The cross-links at the bottom are what make the signals work together: an exemplar on a latency graph opens the trace, a log line opens the trace, and a trace span can jump to that pod's logs. ($ escapes $ in provisioning files, which otherwise expand environment variables.)
Panels
A dashboard is a grid of panels; each panel has one or more queries, a visualisation and field options.
| Visualisation | Use for |
|---|---|
| Time series | rates, latencies, anything over time (the default) |
| Stat | one big number with a sparkline: current error ratio, requests/s |
| Gauge / Bar gauge | a value against a maximum: pool usage, disk usage per mountpoint |
| Table | many series with labels: per-pod restarts, top routes |
| Heatmap | histogram buckets over time: the whole latency distribution |
| State timeline / Status history | up/down, alert states, deploys |
| Logs | lines from Loki |
| Traces / Node graph | a trace, service dependency graphs |
The options that matter most:
- Unit: set
seconds,bytes(IEC),percent (0.0-1.0),requests/sec. Base-unit metrics (naming rules) make this one click. - Legend:
{{route}} {{code}}instead of the full label set. - Thresholds and colours: green/amber/red at your SLO numbers, not arbitrary ones.
- Min/max and decimals: an error-ratio panel with a 0–100% axis hides a jump from 0.1% to 2%.
- Min interval on the query: never smaller than the scrape interval.
The query editor for a RED panel
A "linkly requests by status" time series panel, as the JSON Grafana saves (trimmed to the essentials):
{
"type": "timeseries",
"title": "Requests / s by status",
"datasource": { "type": "prometheus", "uid": "prometheus" },
"targets": [
{
"refId": "A",
"expr": "sum by (code) (rate(http_requests_total{job=\"linkly\"}[$__rate_interval]))",
"legendFormat": "{{code}}"
}
],
"fieldConfig": {
"defaults": { "unit": "reqps" },
"overrides": [
{ "matcher": { "id": "byRegexp", "options": "5.." },
"properties": [ { "id": "color", "value": { "mode": "fixed", "fixedColor": "red" } } ] }
]
}
}$__rate_interval is a Grafana variable chosen so rate() always sees enough samples at any zoom level (next lesson).
Explore
Explore is the ad-hoc query page: no dashboard, just a query box per data source, with split view (metrics left, logs right, same time range). During an incident, start in a dashboard, then "Explore" a panel to modify its query without breaking the shared dashboard. Correlations and the data-source links above let you jump between signals with one click.
Test yourself
Why give provisioned data sources a fixed uid?
- Grafana requires it
- Dashboards reference data sources by uid; a stable uid makes dashboards portable between environments
- It sets the scrape interval
- For authentication
Which panel type shows the full latency distribution over time from histogram buckets?
- Stat
- Heatmap
- Gauge
- Table
What does access: proxy on a data source mean?
- The browser queries Prometheus directly
- The Grafana server makes the requests to the data source
- Grafana uses an HTTP proxy
- The data source is read-only