2

This is probably simple and I am missing some piece.

I have a grafana dashboard backed by prometheus. Prometheus is running in two different kubernetes cluster.

What I want is the first dropdown to be the cluster - say A and B. And based on what I select in the first dropdown, I want the values populated in the second dropdown. The second dropdown in my case is label_values.

The first dropdown is defined by variable datasource and is type datasource and type for datasource options is prometheus.

For the second dropdown, I have variable service, type=Query.

In the query options, I define the query as label_values(rt) but that gives the values of all labels irrespective of the cluster I chose in the first dropdown.

Any help is appreciated.

user2237511
  • 1,089
  • 2
  • 13
  • 20

1 Answers1

2

You need to use the value of the first template variable in the query for the second. I.e. assuming your metric labels for cluster and service are actually cluster and respectively service then you should define your template variable queries as:

cluster: label_values(up, cluster)
service: label_values(up{cluster="$cluster"}, service)

This will automagically populate the second dropdown whenever you change selection in the first.

Alin Sînpălean
  • 8,774
  • 1
  • 25
  • 29
  • I have a variable datasource: type = Datasource, label= Cluster, Data source options.type = Prometheus. The variable I want dynamically filled is service. So following your suggestion I did Name: service, type: query Query options: Data source = $datasource Query = label_values(up{datasource="$datasource"}, service) But, it isn't working. Btw, what is up? – user2237511 Jun 28 '18 at 15:41
  • A datasource template variable allows you to select between multiple datasources (i.e. multiple Prometheus instances). You definitely don't need that AFAICT. What you need are two query variables, set up as above: one will give you the cluster drop-down, the other the service. – Alin Sînpălean Jun 28 '18 at 20:46
  • I in-fact have multiple prometheus instances, one in each cluster and none of the metrics I have, have the label cluster. I am basically using the names of the datasources for the cluster names. – user2237511 Jun 28 '18 at 22:52
  • In that case, keep the datasource variable, but don't use it as a label selector, since I imagine your metrics don't actually have a `datasource` or `cluster` label. Just make sure your `service` template variable and all your panels use `$datasource` as their datasource. – Alin Sînpălean Jun 29 '18 at 04:46