How to select multiple time series in a Prometheus line graph

18 views Asked by At

the problem I'm having is the following: I send some memory values to my Prometheus instance, each including the host of the generating metric. Something like the following example:

Java_HeapMemoryUsage_max{host="host_1"} 4108320768 1710496990682
Java_HeapMemoryUsage_max{host="host_2"} 446218158 1710496990682
Java_HeapMemoryUsage_used{host="host_1"} 116086264 1710496990682
Java_HeapMemoryUsage_used{host="host_2"} 8786264 1710496990682

With these, I need to create a graph like the following one, displaying the data previously sent: enter image description here

What I want to do is to be able to select all the metrics for a given host:this means that, for example, I click on the "Used host_1" metric label, also the "Max host_1" label will be selected. Is it possible to do it?

1

There are 1 answers

0
markalex On

No, you cannot do this in vanilla version of Grafana. Maybe something like this might be implemented through plugins, but I would argue that this is incorrect way of approaching situation.

You can create a variable host and use it in your query to limit shown metrics. For example, if your current query looks like Java_HeapMemoryUsage_max you can modify it to Java_HeapMemoryUsage_max{host="$host"}.

And if you want to still be able to see all or multiple hosts on your graphs - you can add options Include All option (with custom value .+) or Multi-value respectively, and replacing = with =~ in your selector (as in Java_HeapMemoryUsage_max{host=~"$host"})