Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Prometheus query to count unique label values

I want to count number of unique label values. Kind of like

select count (distinct a) from hello_info 

For example if my metric 'hello_info' has labels a and b. I want to count number of unique a's. Here the count would be 3 for a = "1", "2", "3".

hello_info(a="1", b="ddd") hello_info(a="2", b="eee") hello_info(a="1", b="fff") hello_info(a="3", b="ggg") 
like image 593
emperorspride188 Avatar asked Aug 16 '18 17:08

emperorspride188


People also ask

What is TOPK Prometheus?

The topk() function in Prometheus and Loki returns the topk per interval. This means that at time T1, the topk series returned is a different set as that on T2. As a result of this, the graph in Grafana may contain more series in total than what you would expect. As of Grafana 5.3.


1 Answers

count(count by (a) (hello_info)) 

First you want an aggregator with a result per value of a, and then you can count them.

like image 119
brian-brazil Avatar answered Sep 20 '22 14:09

brian-brazil