count(count by (a) (hello_info))
First you want an aggregator with a result per value of a, and then you can count them.
count(count by (a) (hello_info))
First you want an aggregator with a result per value of a, and then you can count them.
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))
Query for Count of Metric A or B, but Unique Labels?
How to count metrics based to label values - Prometheus - Grafana Labs Community Forums
Implement "COUNT expr BY (labels)"
Count and group by day based on label value
I'm trying to set a counter in Grafana that will count our out of service dispensers. I have a metric for if the application, and another metric for if the dispenser is offline. However, a dispenser can be both with an application out of service AND offline, so I can't just add these two metrics together, or a single dispenser can be counted twice, inflating the number.
In my example, the label is the dispenser ID. This is the closest I have gotten, but it will double count if they're both out of service and offline. What's the best way to count both values, but check that the label is only counted once? (The regex resolves to something like XX-####.# for each dispenser.)
sum(count(dispenser_status_SRVREADY{dispenser=~"(customerA).+"} == 0)) + ((count(dispenser_status_OFFLINE{dispenser=~"(customerA).+"} == 1)))