1

I have just started working on Grafana and Prometheus to develop a dashboard. In my Grafana dashboard, I am trying to add an Ad-hoc Filter that allows users to select the values from dropdown.

Following is sample Prometheus data

Element                                                                                                                                ,  Value
default_jenkins_builds_last_build_result{instance="jenkins-m1.abc.com",jenkins_m1_prod="XXX/YYYY/AAA",job="jenkins-m1",repo="ABC"}, 0
default_jenkins_builds_last_build_result{instance="jenkins-m2.abc.com",jenkins_m2_prod="XXX/YYYY/BBB",job="jenkins-m2",repo="BCD"}, 0
default_jenkins_builds_last_build_result{instance="jenkins-m1.abc.com",jenkins_m1_prod="XXX/YYYY/CCC",job="jenkins-m1",repo="ABCD"},    0

I want to add an Ad-hoc filter for the instance label in Grafana. Below is an example of my current progress. You can see that I am not getting any results in the dropdown. I have also added the snippet of the configuration of the ad-hoc variable.

enter image description here

enter image description here

I am assuming that somehow my query is incorrect which is why it is not returning any results. So, Can someone help me to get on the correct path where the dropdown should display two options from the above sample data "jenkins-m1.abc.com" and "jenkins-m2.abc.com"?

Thanks

Mike
  • 512
  • 3
  • 16

2 Answers2

1

Two things:

  1. The screenshot you provided shows the variable type as Query and not Ad Hoc Filter. You will have what you need if you set it to ad-hoc filter (would recommend this only if you are going to perform complex queries every time with some difference in them.).

  2. Another way to go about this is to Marcelo's answer where you leave the variable type to Query and set the query to : label_values(default_jenkins_builds_last_build_result,instance)

Since you are only looking to have a drop down for the instance label I would recommend the second way as it is more easier for a dashboard user.

Dharman
  • 30,962
  • 25
  • 85
  • 135
0

Use the following query in the variable definition:

label_values(default_jenkins_builds_last_build_result,instance)

Better than that, I recommend to use the following query instead:

label_values(default_jenkins_up,instance)
  • I don't know what version of grafana you're using, but in mine there is no variable definition field for ad-hoc filters – Jason May 11 '23 at 23:09