本文介绍了Prometheus查询以计算唯一标签值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想计算唯一标签值的数量.有点像

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

select count (distinct a) from hello_info

例如,如果我的指标"hello_info"具有标签a和b.我想计算唯一的a的数量.在这里,对于a ="1","2","3",计数将为3.

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")

推荐答案

count(count by (a) (hello_info))

首先,您需要一个聚合器,其结果的每个值为a,然后可以对其进行计数.

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

这篇关于Prometheus查询以计算唯一标签值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-17 00:22