Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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)

like image 925
jbuddy Avatar asked Nov 17 '25 10:11

jbuddy


2 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.

like image 94
trallnag Avatar answered Nov 19 '25 03:11

trallnag


Try the following query:

status == 1 or status == 2 or status == 3

It should return status time series with values equal only to (1, 2 or 3).

The query uses or operator - see more details about this operator at https://prometheus.io/docs/prometheus/latest/querying/operators/#logical-set-binary-operators

like image 30
valyala Avatar answered Nov 19 '25 01:11

valyala