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.
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.
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.
$interval is a built in automatic variable in grafana , and is automatically set based on time range.
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"}
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