Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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 :)

like image 608
Mr. Boy Avatar asked Dec 28 '25 16:12

Mr. Boy


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.

like image 97
Marcelo Ávila de Oliveira Avatar answered Dec 30 '25 06:12

Marcelo Ávila de Oliveira



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!