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)
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With