Can I apply a query/filter to all panel queries at dashboard level?

Viewed 930

I have a Prometheus server gathering metrics from several software installations. Each installation applies labels "Customer" & "System" to all metrics in the Prometheus relabel phase, and I have a Grafana dashboard which uses template variables $Customer, $System so my dashboard shows graphs for a single customer-system.

e.g. I can choose "Google/Test" or "Microsoft/Live" combinations.

This means all my queries are like my_counter_total{Customer='$Customer', System='$System'} which is rather tiring. Is there anyway to apply {Customer='$Customer', System='$System'} at dashboard level to all queries? The Grafana documentation hints it can be done but doesn't say how, and I cannot find a single example.

edit: As noted 'ad hoc queries' seem to be able to do this but the entire documentation is:

Ad hoc filters are one of the most complex and flexible variable options available. Instead of a regular list of variable options, this variable allows you to build a dashboard-wide ad hoc query. Filters you apply in this manner are applied to all panels on the dashboard.

So they tell me it's very complicated and leave me hanging :)

1 Answers

You can do that using an "Ad hoc filter" variable.

  1. Go to Dashboard settings > Variables > New

  2. Fill the options like the following example and click on Add

enter image description here

  1. In this example, an Ad hoc filter variable called "Disk" will show in your dashboard:

enter image description here

  1. You can choose how many label/value pair expressions you want to be used in this filter. In the following example, it was chosen "mountpoint=/home/cds/tool/bitbucket" so, magically, only the disk with this mountpoint was showed:

enter image description here

Note: The "mountpoint=/home/cds/tool/bitbucket" will automatically be used for all query expressions of all panes in the dashboard.

See more details in Grafana documentation here.

Related