PromQL query to select metrics whose values are included in a given multiple selection variable

Viewed 2660

In Grafana I need to create a PromQL query to select some metrics whose values are included in a given multiple selection variable.

For example:

  • I have a custom variable selectedStatus which values are 1, 2 and 3 with an "Include All option" (not sure what to specify as a custom value for this)

  • And a metric status

and I want to select only those status which are selected in the selectedStatus (variable) dropdown.

For metrics

status{} 1
status{} 2
status{} 3

If I select to show status with value 1 (variable selectedStatus = 1)

I could write something like this (which works if I want to select each status independently):

status == $selectedStatus # this filters out status whose value is not equal to the selected one

Now, If I would like to select statuses which values are any of 1, 2 or 3 (selectedStatus = All), how could I write the PromQL? (something like an equivalent to an OR in SQL)

3 Answers

There is nothing in PromQL I can think of that would support this out of the box. But you could put whole PromQL expressions into Grafana variables you can then choose from in your dashboard.

I was looking for negative example of not equals to any of X when I get into this page

found a solution:

(((status != 1) != 2) != 3)
Related