Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

multiple values from grafana variable in prometheus query

We have a situation where we need to select the multiple values (instances/servers) from grafana variable field, and multiple values needs to passed to the Prometheus query using some regex, so that i can see selected hosts metrics in single graph. but i am not able to make it work. Can someone please help me with this.

lets take an example , if i select multiples values host1,host2,host3 and then the query should be looks something like this node_load1(instance="host1", instance="host2" , instance="host3").

Hope i made it clear my question.

Thanks in well advance.

like image 210
Anil Kumar Avatar asked Dec 03 '19 13:12

Anil Kumar


People also ask

How do I use Grafana variables in query?

To create a new variable, go to your Grafana dashboard settings, navigate to the Variable option in the side-menu, and then click the Add variable button. In this case, we use the Query type, where our variable will be defined as the result of an SQL query.

How do you add multiple queries in Grafana?

Go to the tab Transform , select Add field from calculation , and chose Mode : Binary operation . Then you can select your two query results, choose + as operator, give an alias and choose to hide the inital fields if you want.

What is $_ interval in Grafana?

$interval is a built in automatic variable in grafana , and is automatically set based on time range.


1 Answers

Grafana generates a regex for you when you use the variable in queries.

I assume you have a variable $host defined by collecting the label values. Ex:

label_values(node_load1, instance)

Then simply use the request:

node_load1{instance=~"$host"}
like image 60
Michael Doubez Avatar answered Sep 24 '22 20:09

Michael Doubez