18

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?

checketts
  • 14,167
  • 10
  • 53
  • 82

3 Answers3

23

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

checketts
  • 14,167
  • 10
  • 53
  • 82
8

label_values works just fine using variables. For ex:

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

enter image description here

Firdousi Farozan
  • 762
  • 1
  • 6
  • 14
-1

****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