Grafana Dashboard Design: Panels, Variables, Layout
Checkout feels slow, and a teammate asks whether it is broken. Shop Overview shows three graphs with every route mixed together, an error ratio near 0.7% that nobody has marked as good or bad, and no sign of this morning's deploy. A good Grafana dashboard answers in one look. This lesson shows how to lay out panels, choose visualizations and units, add a route drop-down, mark deploys and keep the result in Git.
Lay out the window: health, then traffic, then resources
The Fundamentals lesson Monitoring Dashboards That Help During Incidents explained why a dashboard is read top down: status first, then RED (rate, errors, duration), then resources. Here you build that in Grafana. A row is a titled band of panels that you can collapse; in edit mode, Add new element > Add row/Group into rows creates one.
Row 1 answers "is it working?" with stat panels, each one big number coloured green, orange or red. Row 2 shows request rate, error ratio and p95 latency as time series, so you can see when a change began. Row 3 holds memory and CPU of the Docker host from the node exporter you added in lesson 4.
The lab now ships this design as a second dashboard, Shop Overview (improved), from dashboards/shop-overview-improved.json. Grafana's grid is 24 columns wide: each stat is 6 columns and each graph 8, so every row fills the screen.
Choose the visualization, then the unit
Pick the visualization from the panel's question. The five most common:
| Visualization | Shows | Use it for |
|---|---|---|
| Time series | Lines over time | Trends: rate, errors, p95, CPU |
| Stat | One number, coloured | The health row |
| Gauge | One value on a dial | A value with a fixed range, like memory |
| Heatmap | A distribution over time | Latency buckets: a fast and a slow group |
| Table | Rows and columns | Lists, such as errors by route |
A gauge shows only the current moment, so the improved dashboard pairs its memory gauge with a CPU graph. A heatmap colours each time slice by how many requests fell in each latency bucket, which shows a slow group that one p95 line hides.
A unit tells Grafana how to label a number. Query base units and let the unit format them. The histogram counts seconds, so set the unit to seconds: Grafana shows 0.23 as 230 ms by itself. An error ratio is a fraction such as 0.0071, so choose Percent (0.0-1.0), which shows 0.71%. Percent (0-100) expects 0.71 for that.
Variables: one dashboard for every route
A variable is a named value that a drop-down at the top of the dashboard sets, and that queries use as $name. Shop Overview has one called route. Its type is query: Grafana asks Prometheus for the list of values. Its definition in the JSON file, trimmed, with one panel query that uses it:
"name": "route",
"type": "query",
"query": "label_values(http_requests_total, route)",
"includeAll": true,
"allValue": ".*",
"expr": "sum by (route) (rate(http_requests_total{route=~\"$route\"}[5m]))"
label_values() returns every value of the route label on that metric: /, /checkout, /health, /metrics, /products and /report. includeAll adds an All entry, and the custom all value .* is the regex sent when you pick it.
That is why every query uses =~, the regex matcher from lesson 5: one query works for a single route and for .*. The same pattern builds an $instance drop-down from label_values(up, instance) when a service runs on many machines.
Besides filtering, a variable can repeat panels. A panel's Repeat options > Repeat by variable draws one copy per selected value, such as a p95 graph per route. That needs a multi-value variable, one with Multi-value turned on. Shop Overview's route takes one value, so its panels filter.
Thresholds, colours and deploy markers
A threshold turns a number into a verdict. New panels start with Base green and red at 80, which means nothing for an error ratio of 0.007. The improved error-ratio stat sets limits that matter, in the panel's unit:
"unit": "percentunit",
"color": { "mode": "thresholds" },
"thresholds": { "mode": "absolute", "steps": [
{ "color": "green", "value": null },
{ "color": "orange", "value": 0.01 },
{ "color": "red", "value": 0.05 } ] }
percentunit is the JSON name of Percent (0.0-1.0). null is the Base step, minus infinity, so the stat is green below 1%, orange from 1% and red from 5%. The matching graph uses the same steps with Show thresholds set to As lines. Keep colours meaningful: green is fine, orange needs a look, red needs action.
An annotation marks one moment on every time series panel. Real pipelines post a deploy annotation through Grafana's HTTP API, as the Fundamentals lesson showed. The lab has no pipeline, but a deploy restarts the app, so the improved dashboard has an annotation query named Deploys on Prometheus:
changes(process_start_time_seconds{job="shop-demo"}[2m]) > 0
process_start_time_seconds is when shop-demo started, and changes() counts how often that value changed in two minutes. After a restart it stays above 0 for about two minutes, and Grafana draws an orange marker at each point returned. You add one in edit mode with Add new element > Annotation query.
Keep the dashboard in Git as JSON
A dashboard is a JSON document: panels with their grid positions, queries, units, thresholds, variables and annotations. As lesson 9 showed, a provisioned dashboard is loaded from a file and Grafana refuses to save it from the UI. That is the point: the file in Git is the source of truth, so every change can be reviewed.
So change the dashboard in the UI, then click Save. In the Cannot save provisioned dashboard dialog, open Advanced options, choose the Classic model and click Copy JSON to Clipboard. Classic is the format of the lab's files; the other choice, V2 Resource, is Grafana 13's newer format. Paste the JSON over the file, then run:
docker compose restart grafana
git diff --stat
Grafana watches the folder for changes, but with Docker bind mounts those change events do not always arrive. A restart is the sure way, because Grafana reads every provisioning file when it starts. Reload the page: your change now comes from the file. git diff --stat lists the file as changed, ready to commit with a message that says why.
Check yourself
You pick /checkout and the memory gauge does not change. Is the dashboard broken?
No. A variable only changes the queries that use it, and the memory query cannot: node exporter metrics have no route label to filter on.
A new panel uses {route="$route"}. It works for /checkout but shows No data for All. Why?
With =, All's value .* is compared as a literal route name, which no series has. =~ treats it as a regex that matches every route.
Why set a latency panel's unit to seconds instead of multiplying by 1000 in PromQL and choosing milliseconds?
The query stays identical to the one in Prometheus rules, and Grafana scales the label itself, so panels never mix 0.23 and 230 for one signal.