Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Grafana query to get unique tag values

I want to get unique values for specific tag of some metric. For example if I have metric 'metric_name' has tags 'tag_name1' and 'tag_name2':

metric_name{tag_name1='a',tag_name2='b'}
metric_name{tag_name1='c',tag_name2='d'}
metric_name{tag_name1='e',tag_name2='f'}

I want to get unique values of 'tag_name1' tag: a,c,e

Kind of like:

select distinct tag_name1 from metric_name
like image 968
grolegor Avatar asked Nov 28 '18 10:11

grolegor


People also ask

How do I use Query variables in Grafana?

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 our variable will be defined as the result of an SQL query. Under the General section, we name our variable route .

Does Grafana support PromQL?

In Grafana, you can configure New Relic as a Prometheus data source. Not only that, within Grafana you can query metrics stored in New Relic using the PromQL query language.

How do you add multiple queries in Grafana?

Go to the tab Transform , select Add field from calculation , and chose Mode : Binary operation . Then you can select your two query results, choose + as operator, give an alias and choose to hide the inital fields if you want.


1 Answers

TLDR;

Template with query label_values(tag_name1) would do the job.

More details:

By the prometheus tag I guess you are working with this db.

You can use the Grafana templating to get the unique values for specific tag of some metric.

Query is the most common type of Template variable. Use the Query template type to generate a dynamic list of variables, simply by allowing Grafana to explore your Data Source metric namespace when the Dashboard loads.

For example a query like prod.servers.* will fill the variable with all possible values that exists in that wildcard position (in the case of the Graphite Data Source).

So you can add template and query using label_values for Prometheus query in Grafana.

like image 191
Gal S Avatar answered Oct 17 '22 18:10

Gal S