Reputation: 6578
I need to write a query that use any of the different jobs I define.
{job="traefik" OR job="cadvisor" OR job="prometheus"}
Is it possible to write logical binary operators?
Upvotes: 52
Views: 86567
Reputation: 115
Doing a regex label match like {job=~"traefik|cadvisor|prometheus”}
is correct, but there’s also another option that might offer a bit more flexibility for your end users.
Grafana lets you define dashboard variables that appear as drop downs at the top of your dashboards. Your users can then use these drop downs to specifiy which metric series instances they actually care about.
To define a new dashboard variable, navigate to Dashboard Settings -> Variables Tab -> New Variable. From here, you have a couple of options:
traefik,cadvisor,prometheus
.From here, make sure to also give it a name so you can reference it in your query in a second. Additionally, from your question, it sounds like you would also probably wish to enable the “Multi-value” and “Include All” options as well.
Next, you need to update your graph query to use the variable. Assuming that you called your variable job
, this would just be {job=~”$job”}
.
Finally, to set the default values of your variable, you just have to select them in the drop down and save the dashboard.
Upvotes: 0
Reputation: 34142
Prometheus has an or
logical binary operator, but what you're asking about here is vector selectors.
You can use a regex for this {job=~"traefik|cadvisor|prometheus"}
, however that you want to do this is a smell.
Upvotes: 102