Reputation: 4627
I've a prometheus query looking like this:
api_latency
And it gives me all kinds of cool stuff, all I want to know. To mention, it is a custom metric.
And I can make it fetch data with some condition, like this:
api_latency{uri="/ping"}
api_latency{uri="/pong"}
I can even join them like this:
api_latency{uri=~"/ping|/pong"}
But what I want is, from the grafana dashboard, I will pickup a variable, and based on that I will execute this query. This dowpdown in grafana is a multi-select dropdown.
How can I do so?
Upvotes: 1
Views: 1637
Reputation: 13414
You can do it bu introducing dashboard variable with Multi-value option
Dashboard settings > Variables > + New variable
label_values(api_latency, uri)
Now you'll see preview of values above the button Apply. And when you save changes and come back to panel, you'll see drop-down with variable in the left upper corner of dashboard.
Now you can simple use this variable in your queries, like this:
api_latency{uri=~"$uri"}
$uri
will be automatically substituted by Grafana with /ping|/pong
if you select those two as variables. Note that this substitution depends on data source, and it could be substituted with other format value for other data sources, more about it here.
Upvotes: 1