Course contents · Lesson 10 of 21

Grafana Dashboard Design: Panels, Variables, Layout

Grafana · Lesson 10 of 21 · 11 min Hands-on

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.

Wireframe of the Shop Overview (improved) dashboard. A top bar holds the Route drop-down set to All, the Deploys annotation toggle and the time picker set to Last 30 minutes. Row 1, Health, asks whether it is working: stat tiles show Shop up UP, 5.1 req/s, error ratio 0.71% and p95 latency 230 ms, all green. Row 2, Traffic, errors, latency, asks what changed: request rate by route, error ratio with a 1% threshold line and p95 latency with a 0.5 s threshold line, all crossed by an orange deploy marker. Row 3, Resources, asks whether the host is the cause: a memory gauge and a CPU busy graph that ignores the Route drop-down but shows the same deploy marker. Values are illustrative.
Each row answers the next question, and the deploy marker crosses every graph at the same moment, so cause and effect line up.

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:

VisualizationShowsUse it for
Time seriesLines over timeTrends: rate, errors, p95, CPU
StatOne number, colouredThe health row
GaugeOne value on a dialA value with a fixed range, like memory
HeatmapA distribution over timeLatency buckets: a fast and a slow group
TableRows and columnsLists, 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.

Before and after. Left, before: eight panels in the order they were added, including a raw counter of 18342 requests, an error value of 0.0071 with no unit, latency shown once as 0.23 and once as 230 ms, a memory panel saying No data and one still called Panel Title. Right, after: the same signals in three rows: Health stats UP, 5.1 req/s, 0.71% and 230 ms; rate, error ratio and p95 graphs with threshold lines; then memory and CPU. Values are illustrative.
The right side has no new data: order, titles and one unit per signal are what make it readable.

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.

Flowchart. 1: add a variable from label_values(http_requests_total, route). 2: use it in every panel's PromQL as route=~"$route". 3: filter, chosen route only, or repeat, a copy per value. 4: save, then test by picking /checkout, then All, and watching every panel redraw. Question: do the panels change? Yes: done, one dashboard now serves every route. No: check that the matcher is =~ and not =, and that the All value is .*, fix it, then test again.
The variable only matters once every query uses it, and switching values is the test that proves it.

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.