🎓 A1Learner
🔍
0 of 50 lessons completed

Grafana: Dashboard Variables

A dashboard variable is a drop-down at the top of a dashboard that changes what every panel shows. One dashboard with a variable serves every instance and every route, instead of one dashboard per instance.

The $instance variable query

This query lists every instance that reports up.

label_values(up{job="shopsentry"}, instance)

The chained $route variable query

This query lists only routes served by the picked instance.

label_values(http_requests_total{instance="$instance"}, route)

Use the variable in a panel query

The panel shows traffic for the picked instance and route only.

sum(rate(http_requests_total{instance="$instance", route="$route"}[5m]))

Example

label_values(http_requests_total, route)

Key points

  • A dashboard variable holds the value picked in its drop-down, and panels use it inside their queries.
  • The $instance variable lists every ShopSentry instance from the up series.
  • The $route variable lists every route, and it changes with the instance picked above it.
  • A chained variable is a variable whose list depends on another variable, like $route depending on $instance.
  • The All option sets the variable to every value at once, so panels show the whole fleet.
  • A variable query runs against Prometheus, so new instances appear in the list on their own.

In this example, the $route variable query runs against the live ShopSentry data and returns the four routes the shop has served. Picking one route from the drop-down narrows every panel to that route. Picking All shows all four routes together.

Note

A variable only changes the query text. It never changes the data Prometheus stored.

Try it Yourself

Edit the code, then press Run.

Running is simulated · Rust Playground

Exercise

What does the All option do for a dashboard variable?