Dashboard variable that let me choose between values of query

  • What Grafana version and what operating system are you using?
    OS Debian 12
    Grafana Version 9.5.20 (commit: 1ba5cd985398b8b7d399cbcf11aaa03234d1fa42, branch: HEAD)
    mysql Ver 8.4.4 for Linux on x86_64 (MySQL Community Server - GPL)

  • What are you trying to achieve?
    I am trying to make a variable which is getting the results of a query ( up{} ) and let me choose between the results of the query (which in this case will be 1 and 0 ) and all

I created a dashboard with query: up{category=~"$category"}. Category is a label in my prometheus config that is collecting multiple jobs in a category. The dashboard is set to be Stat with solid background, so when something goes offline the whole line will turn from green to red.
I created a variable in the dashboard called category which is set to Query type: Label Values > Label*: category with selection options Multi-value and Include All option.
This will allow me to choose a category and see status of all host in that cattegory.

Now i would like to have a variable which will have option to show: all, only online, only offline hosts.

  • How are you trying to achieve it?
    Creating variable in the dashboard with Query Type: Query result > Query: up == 1

  • What happened?
    it shows no data.

  • What did you expect to happen?
    To filter all hosts depending on choise ( online onlu, offline only, all )

Create new dashboard variable, e.g. upstatuscondition:

and then use it in the panel query, e.g.:

up{category=~"$category"}${upstatuscondition:raw}

This is not copy&paste solution - just a hint, so fix any syntax/functional issues, which you may have.

1 Like