Dashboard filter for Graph

Hi all,

I want to use filtering on my monitoring dashboard by ip address of the machines where my services are hosted on. For example, i have two services Apache Storm and Zookeeper, that each are hosted on 192.168.0.1 and 192.168.0.2. I would like to show jvm_memory_bytes_used metric that i received via jmx from these services. But as i am receving it using jmx, i have instance label of this metric like 192.168.0.1:9120 (storm), 192.168.0.1:9125 (zookeeper), 192.168.0.2:9120 (storm), 192.168.0.2:9125 (zookeeper)
To make these labels more human-readable i show metrics in the following query:

label_replace(jvm_memory_bytes_used{area=~“heap”}, “instance”, “$1”, “instance”, “(.*):.*”)
and Legend format as: {{job}} {{instance}}

That perfectly works, metrics are showed like zookepeer 192.168.0.2, zookepeer 192.168.0.1, etc

But i want to filter my Graph by ip address, to choose only 192.168.0.2 server and only this server’s metrics for service will be showed: zookepeer 192.168.0.2, storm 192.168.0.2 in my example.
So i add $instance variable on my dashboard template as:
label_values(jvm_memory_bytes_used, instance)
and regex:
/([0-9.]+):+/
These operations add variable to my dashboard and i could choose servers as 192.168.0.1, 192.168.0.2
But choosing filters does not affect my Graph at all, memory_used metrics don’t choosing for corresponding server.

Please provide me with an answer, what am i doing wrong or maybe another solution for my case…
Thanks

In your metric in graph you’ll need to filter by the template variable you’ve created, something like

metric{... instance=~"^$instance.*"}

See example https://play.grafana.org/d/000000063/prometheus-templating?orgId=1