Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 869
checketts Avatar asked Jan 20 '17 22:01

checketts


People also ask

How do you reference a variable in Grafana dashboard?

To create a new variable, go to your Grafana dashboard settings, navigate to the 'Variable' option in the side-menu, and then click the 'Add variable' button. In this case, we use the 'Query' type, where your variable is defined as the results of SQL query.

How does Prometheus and Grafana integrate with each other?

Prometheus is a monitoring solution for storing time series data like metrics. Grafana allows to visualize the data stored in Prometheus (and other sources). This sample demonstrates how to capture NServiceBus metrics, storing these in Prometheus and visualizing these metrics using Grafana.

How do I use mixed data source in Grafana?

You can enable this by selecting the built in -- Mixed -- data source. When selected this will allow you to specify data source on a per query basis. This will, for example, allow you to plot metrics from different Graphite servers on the same Graph or plot data from Elasticsearch alongside data from Prometheus.


2 Answers

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

like image 109
checketts Avatar answered Sep 16 '22 11:09

checketts


label_values works just fine using variables. For ex:

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

enter image description here

like image 36
Firdousi Farozan Avatar answered Sep 19 '22 11:09

Firdousi Farozan