Prometheus query to count unique label values

前端 未结 2 1533
小鲜肉
小鲜肉 2021-02-12 02:44

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\'

相关标签:
2条回答
  • 2021-02-12 03:38
    count(count by (a) (hello_info))
    

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

    0 讨论(0)
  • 2021-02-12 03:49

    Other example: If you want to count the number of apps deployed in a kubernetes cluster based on different values of a label( ex:app):

    count(count(kube_pod_labels{app=~".*"}) by (app))
    
    0 讨论(0)
提交回复
热议问题