123DevOps··5 min read

Building Grafana dashboards that help during incidents: from the first panel to dashboards as code

A step-by-step guide to building a RED dashboard in Grafana with PromQL, variables, units, thresholds, and links to logs and runbooks — and how to version it with provisioning or Terraform.

Observability

Everyone has seen the dashboard with 60 colorful panels that nobody knows how to read. It looks impressive on the office TV, but in the middle of an incident it can’t answer the most basic question: is the service healthy?

A good dashboard tells a story from top to bottom: first what the user feels, then the details that explain why. In this guide, we build a dashboard like that in Grafana and, at the end, turn the result into code.

Prerequisites: Grafana with a Prometheus data source (see installing Grafana and configuring Prometheus).

The plan: the RED method in three rows

Row Question Panels
1. Overview Is the service healthy right now? Request rate, error % and p95 latency (Stat panels)
2. Trend Since when, and on which routes? Time series by route and status
3. Resources and dependencies Why? CPU, memory, database connections, dependency latency

Step 1: create the dashboard and the first visualization

  1. Go to Dashboards → New → New dashboard → Add visualization.
  2. Choose the Prometheus data source.
  3. In the query editor, switch to Code mode and type the query.
  4. Pick the visualization type on the right (Time series, Stat, Gauge, Table…).

Request rate by route

Using the HTTP metric from the OpenTelemetry semantic conventions:

sum by (http_route) (
  rate(http_server_request_duration_seconds_count{service_name="$service"}[$__rate_interval])
)
  • $__rate_interval is a Grafana variable that automatically picks a safe window for rate() based on the scrape interval and the graph’s zoom level.
  • Under Legend, use {{http_route}} to show the route name on each line.
  • Under Standard options → Unit, choose requests/sec (rps).

Error percentage

sum(rate(http_server_request_duration_seconds_count{service_name="$service", http_response_status_code=~"5.."}[$__rate_interval]))
/
sum(rate(http_server_request_duration_seconds_count{service_name="$service"}[$__rate_interval]))

Use the Stat visualization, unit Percent (0.0-1.0), and Thresholds: green below 1%, yellow up to 5%, red above that. The colors should reflect your SLO, not some arbitrary value.

p95 latency

histogram_quantile(0.95,
  sum by (le) (
    rate(http_server_request_duration_seconds_bucket{service_name="$service"}[$__rate_interval])
  )
)

Unit seconds (s). With exemplars enabled, the dots on the graph take you straight to the trace of a slow request (see correlating signals).

Step 2: variables to reuse the dashboard

Instead of one dashboard per service, build one dashboard with variables:

  1. Dashboard settings → Variables → New variable.
  2. Type Query, name service, Prometheus data source.
  3. Query:
label_values(http_server_request_duration_seconds_count, service_name)
  1. Enable Include All option if you want to see all services together.

Also create variables for environment and cluster. The queries above already use $service, and a selector shows up at the top of the dashboard.

  • Rows (collapsible) separate the overview, trend, and resources sections.
  • A description on every panel (the Description field): what the metric means and which value is concerning. Whoever is on call at 3 a.m. will thank you.
  • Data links: under Data links, add links from the errors panel to Explore with the service’s logs for the same time range, and to the runbook.
  • Deploy annotations: under Dashboard settings → Annotations, add a query that marks deploys and configuration changes on the graph.
  • A logs panel in the last row: a Logs panel with the LogQL query for the service’s errors (see querying logs).

Design best practices

  • Top to bottom, general to specific: the top answers “is everything OK?” in 5 seconds.
  • Few panels: if it doesn’t help you make a decision, remove it.
  • Always set units: “0.2” could be 200 ms or 20% — the reader shouldn’t have to guess.
  • Meaningful colors: red only for “bad”, and aligned with the SLO.
  • Same time range and consistent axes across comparable panels.
  • Lightweight queries: use recording rules for expensive calculations that show up in many dashboards.

Step 4: dashboards as code

Hand-built dashboards get lost, drift between environments, and go unreviewed. Once it’s ready, export the JSON via Share → Export → Save to file and put it under version control.

Option A: file provisioning

# /etc/grafana/provisioning/dashboards/services.yaml
apiVersion: 1
providers:
  - name: services
    folder: Services
    type: file
    disableDeletion: true
    options:
      path: /var/lib/grafana/dashboards

Any JSON placed in the configured folder shows up in Grafana automatically. On Kubernetes, the Grafana chart loads dashboards from ConfigMaps with a specific label, using a sidecar container.

Option B: Terraform

resource "grafana_folder" "services" {
  title = "Services"
}

resource "grafana_dashboard" "red_services" {
  folder      = grafana_folder.services.uid
  config_json = file("${path.module}/dashboards/red-services.json")
}

With Terraform, dashboards, folders, data sources, permissions, and alert rules follow the same PR and review workflow as the rest of your infrastructure. If you’d rather generate the JSON with code, there are libraries such as Grafonnet (Jsonnet) and the Grafana Foundation SDKs.

Checklist

  • Overview row with rate, errors, and latency
  • Service, environment, and cluster variables
  • Units, thresholds, and descriptions on every panel
  • Links to logs, traces, and runbooks
  • Deploy annotations
  • JSON versioned and published via provisioning or Terraform

A good dashboard doesn’t show everything you collect. It shows, in seconds, whether there’s a problem — and where to look next.

Get updates on new posts and stay in the loop!