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?
Asked
Active
Viewed 4.4k times
18

checketts
- 14,167
- 10
- 53
- 82
3 Answers
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="([^"]*).*/

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)

Firdousi Farozan
- 762
- 1
- 6
- 14
-
2This looks like a cleaner option. Thanks @Firdousi Farozan – Sebin May 13 '20 at 06:21
-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

RezviyBelorus
- 11
- 1