Sammi
Sammi

Reputation: 41

Grafana/Prometheus Multi-value selection with avg() function

I'm trying to create a Grafana dashboard with Multi-select and ALL option to be enabled from variable.

Query exmple: avg(metric{label1="$label1",label2=~"$label2",label3=~"$label3"})

Multi-select and ALL options looks fine in variable dropdown, but seems like prometheus query is doing the sum of label1 and label 2 and returning a single avg value, but I'm looking for multiple values based on the variable selection.

Example: host1 - host4 10% host2 - host5 15% host3 - host6 20%

but instead of that it's returning value like below: (host1,host2,host3) - (host4,host5,host6) - 20%

Any suggestion? or we can do it with avg() function?

Thanks!

Upvotes: 0

Views: 837

Answers (1)

Sammi
Sammi

Reputation: 41

This issue is resolved by adding "by (label1,label2)" in the end

avg(metric{label1="$label1",label2=~"$label2",label3=~"$label3"}) by (label1,label2)

Upvotes: 0

Related Questions