checketts
checketts

Reputation: 14963

How can I make a Grafana template with a variable reference another variable using Prometheus as a datasource?

I have a Grafana dashboard with template variables for services and instances. When I select a service how can I make it filter the second template variable list based on the first?

Upvotes: 18

Views: 44968

Answers (3)

RezviyBelorus
RezviyBelorus

Reputation: 21

****Variable 1 (get labels from metrics, ends with below):**

name: instance

label: instance

type: Query

Query: label_values({name=~".*jvm_JvmMetrics_MemNonHeapUsedM"}, instance)

****Variable 2 (depends on variable 1)**:

name: task_name

label: task_name

type: Query

Query: label_values({name=~".*jvm_JvmMetrics_MemNonHeapUsedM",instance=~"$instance"},task_name)

Symbol "~" for multiple values

Upvotes: -1

Firdousi Farozan
Firdousi Farozan

Reputation: 882

label_values works just fine using variables. For ex:

label_values(cassandra_keyspace_readlatency_count{product="$product"}, keyspace)

enter image description here

Upvotes: 8

checketts
checketts

Reputation: 14963

You can reference the first variable in the second variables query. I'm not certain if there is a way using the label_values helper though.

First variable
query: up
regex: /.*app="([^"]*).*/

Second variable:
query: up{app="$app"}
regex: /.*instance="([^"]*).*/

enter image description here

Upvotes: 24

Related Questions