Dashboards with Grafana
Build Grafana dashboards that answer questions: connect Prometheus, chart rates and percentiles, follow RED and USE, and know what a histogram p99 hides.
Dashboards with Grafana
The player loads from youtube-nocookie.com when you press play. Nothing reaches YouTube before that.
Not started
What you'll learn
- Grafana stores no metrics. It sends queries to data sources such as Prometheus and draws the answers as panels on a dashboard.
- A good service dashboard starts with RED (rate, errors, duration), and a good host dashboard with USE (utilization, saturation, errors). Everything else goes further down or on another page.
- Graph percentiles, not just averages. A mean latency can look healthy while one request in a hundred takes a second.
- histogram_quantile() estimates a percentile by interpolating inside a bucket, so its accuracy depends on having bucket bounds near the values you care about.
- Keep dashboards as code in Git, as JSON or through provisioning, so they are reviewed, versioned and rebuilt the same way everywhere.
The problem: data nobody looks at
Prometheus now holds thousands of time series. Its own query page can graph one expression at a time, which is fine for exploring and no good at 3 a.m., when you need the state of the whole service in five seconds. A dashboard is a page of pre-built graphs that answers the first questions anyone asks during trouble: is traffic normal, are errors up, is it slow, and since when?
Grafana is the usual tool. Its current release when I checked was v13.3.2. It is worth being clear what it is: Grafana stores no metrics. It connects to data sources (Prometheus, Loki for logs, cloud monitoring APIs, SQL databases), sends them queries, and draws the results.
The parts of a dashboard
- Data source: where queries go. For Prometheus you give Grafana its URL.
- Panel: one query, or several, drawn one way: a time series graph, a single stat, a gauge, a table, a heatmap.
- Variable: a drop-down, such as
$instanceor$env, that is substituted into every query, so one dashboard serves every instance. - Time range: shared by every panel, so you can zoom into the incident window.
- Rows: collapsible groups of panels, so the top of the page stays short.
What to put on it
Many dashboards fail by showing everything that can be measured. Two short checklists help.
The RED method, for anything that serves requests:
- Rate:
sum(rate(http_requests_total[5m])) - Errors: the 5xx ratio
- Duration: latency percentiles, p50 and p99
The USE method, for resources such as hosts, disks and queues:
- Utilization: how busy, such as CPU percentage
- Saturation: how much is waiting, such as load average or queue length
- Errors: device and network errors
Put RED for the service at the top and USE for its hosts below it. Anything more detailed belongs further down or on a separate page linked from the panel.
A worked example: what a p99 panel really shows
Prometheus histograms keep bucket counts, not individual requests. The p99 panel is a query like this:
histogram_quantile(0.99,
sum by (le) (rate(http_request_duration_seconds_bucket[5m])))
histogram_quantile() finds which bucket the 99th percentile falls into and interpolates linearly inside it. I wanted to see how much that estimate could drift, so I generated 10,000 fake request latencies in Python, mostly fast with a 3% slow tail. I computed the true percentiles and then the histogram estimates the same way histogram_quantile() does. I did this twice: once with the Go client library’s default bucket bounds (5 ms up to 10 s), and once with only two buckets, at 0.1 s and 1 s:
$ python3 quantile.py
p50 true 51 ms default buckets 52 ms two buckets 59 ms
p90 true 118 ms default buckets 162 ms two buckets 400 ms
p99 true 860 ms default buckets 867 ms two buckets 972 ms
mean true 79 ms
Three things show up.
- The mean lies. At 79 ms it looks great, while one request in a hundred takes over 800 ms. Graph percentiles.
- Estimates are only as good as the buckets. The default buckets got p50 and p99 close, but p90 was 37% high because it fell in the wide 100–250 ms bucket. With two buckets, p90 came out at 400 ms against a true 118 ms. If your target is “90% under 200 ms”, put a bucket bound at 200 ms.
- You can’t add percentiles. Averaging each instance’s p99 is not the p99 of the service. Summing the buckets across instances first, as the query above does with
sum by (le), gives a correct estimate.
Prometheus 3 also has native histograms, with automatically placed, much finer buckets, which reduce this error. Check whether your client library and Prometheus version have them enabled before relying on that.
Dashboards as code
A dashboard edited by hand in the UI is a snowflake. Nobody knows who changed it, and staging and production drift apart. Grafana dashboards are JSON documents, and Grafana can load them from files at startup through provisioning. A minimal panel looks like this. I wrote it from the Grafana dashboard JSON model docs and did not load it into Grafana, which is not installed here:
{
"type": "timeseries",
"title": "p99 latency",
"datasource": {"type": "prometheus", "uid": "prom"},
"targets": [{
"expr": "histogram_quantile(0.99, sum by (le) (rate(http_request_duration_seconds_bucket{instance=~\"$instance\"}[5m])))"
}],
"fieldConfig": {"defaults": {"unit": "s"}}
}
Commit the JSON to Git with the service, review changes like code, and let provisioning or an infrastructure-as-code provider apply it.
About the video
“Creating Grafana Dashboards for Prometheus” is from PromLabs (Julius Volz, Prometheus co-founder), published January 2023, 13 minutes 51 seconds. Its chapters cover running Grafana from Docker or a binary, creating a Prometheus data source, and building a time series chart, a gauge and a table, then adding rows. It is the hands-on half of this lesson. It does not cover RED and USE, percentile accuracy or dashboards as code, and the Grafana UI has changed since it was recorded. English is judged from the title, description and channel. Grafana’s own short video on panels, queries and transformations is linked below, with their talk on dashboard design.
Where this fits
Metrics tell you that something is wrong. To find out what, you usually need the logs: log aggregation pipelines.
Check yourself
Why might a dashboard show a mean latency of 80 ms while users complain about slowness?
The mean hides the tail. A few percent of very slow requests barely move the average, but a p99 panel would show them.
What do the three RED panels show for a service?
Request rate, error rate or ratio, and duration, usually as latency percentiles.
Your histogram has buckets at 0.1 s and 1 s only. Why is the reported p90 unreliable?
histogram_quantile() interpolates linearly between bucket bounds, so any value between 0.1 and 1 second is a guess. Buckets near your latency targets are needed for an accurate estimate.
Why use a template variable such as $instance on a dashboard?
One dashboard can then show any instance, service or environment from a drop-down, instead of copying the dashboard for each one.
Go deeper
Notes
Notes are saved to your account.
Everything else on this page works without one — progress and bookmarks keep themselves in this browser and come with you when you sign in. Notes are the one thing worth not trusting to a browser you might clear.
Your notes could not be loaded.