count(count by (a) (hello_info))

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

Answer from brian-brazil on Stack Overflow
🌐
Better Stack
betterstack.com › community › questions › prometheus-to-count-unique-label-values
Prometheus Query to Count Unique Label Values | Better Stack Community
December 2, 2024 - To count unique label values in Prometheus, you can use the count function along with the by clause to aggregate metrics based on a specific label.
Discussions

Query for Count of Metric A or B, but Unique Labels?
Try queries but with the word "and" separating them maybe sum(foo) and sum(bar) There also exists the "or" keyword. I'm terms of data I can see some unusual patterns in your example. Ideally slicing and dicing should be done by labels rather than metric names... Eg I would have A "status" key for values like "srvready" or "offline"etc.. (KISS) Then you can query and ask "dispenser_status" for different things.. and more elegantly including the same key more than once eg: foo{ key1="waz", key2!="baz", key1="daz”, } More on reddit.com
🌐 r/PrometheusMonitoring
1
0
March 11, 2022
How to count metrics based to label values - Prometheus - Grafana Labs Community Forums
What Grafana version are you using? [v9.3.8 (7ab70dbce8)] What are you trying to achieve? I have the following data from a Prometheus metric azurerm_resource_info Is there a way in grafana to create a dashboard that will show I have x number of resource created 1 month ago, y number of resources ... More on community.grafana.com
🌐 community.grafana.com
0
April 14, 2023
Implement "COUNT expr BY (labels)"
Currently we have a count() function which takes a vector expression and returns the count of vector elements as a scalar. We might want to change the function so that: count returns a vector, with all labels being preserved that are com... More on github.com
🌐 github.com
1
April 22, 2013
Count and group by day based on label value
What Grafana version and what operating system are you using? Grafana v9.1.4 What are you trying to achieve? I’m collecting metrics about log files with filestat_exporter, and i would like to have graphic with the count of rotated logs per day based on values of the label path. ... More on community.grafana.com
🌐 community.grafana.com
2
0
March 30, 2023
🌐
SigNoz
signoz.io › guides › how to count unique label values with prometheus queries
How to Count Unique Label Values with Prometheus Queries | SigNoz
September 6, 2024 - Prometheus labels are key-value pairs attached to metrics that provide additional context and allow for more detailed data analysis. They play a crucial role in identifying and categorizing metrics, enabling you to slice and dice your data in ...
🌐
OpenObserve
openobserve.ai › home › blog › prometheus metrics count basics
Prometheus Metrics Count Basics
September 26, 2025 - Learn how Prometheus metrics counts unique label values using basic queries and methods like `count(count by (label) (metric))`.
🌐
OneUptime
oneuptime.com › home › blog › how to count unique label values in prometheus
How to Count Unique Label Values in Prometheus
December 17, 2025 - # Count unique instance-job combinations count(group by (instance, job) (up)) # Count unique service-version pairs count(group by (service, version) (http_requests_total)) High cardinality can cause performance problems. Monitor it proactively: # Total number of time series (requires Prometheus 2.x) prometheus_tsdb_head_series # Series created per second rate(prometheus_tsdb_head_series_created_total[5m]) # Count unique values per label across all series # (Run this for each label you want to analyze) count(group by (your_label) ({__name__=~".+"}))
🌐
Better Stack
betterstack.com › community › questions › how-do-i-write-prometheus-query-that-returns-value-of-label
How Do I Write a Prometheus Query That Returns the Value of a Label? | Better Stack Community
August 5, 2025 - To count unique label values in Prometheus, you can use the count function along with the by clause to aggregate metrics based on a specific label.
🌐
Reddit
reddit.com › r/prometheusmonitoring › query for count of metric a or b, but unique labels?
r/PrometheusMonitoring on Reddit: Query for Count of Metric A or B, but Unique Labels?
March 11, 2022 -

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

🌐
Promlabs
promlabs.com › blog › 2020 › 12 › 17 › promql-queries-for-exploring-your-metrics
PromLabs | Blog - PromQL Queries for Exploring Your Metrics
December 17, 2020 - If your UI does not already show you this list in one way or another (it really should!), you can query for it by first selecting all series, then grouping by the special metric name label __name__: ... Note: A more efficient, non-PromQL way to get the same information is to use Prometheus's label values metadata endpoint to get all values for the __name__ label, e.g.: https://demo.promlabs.com/api/v1/label/name/values.
Find elsewhere
🌐
Grafana
community.grafana.com › prometheus
How to count metrics based to label values - Prometheus - Grafana Labs Community Forums
April 14, 2023 - What Grafana version are you using? [v9.3.8 (7ab70dbce8)] What are you trying to achieve? I have the following data from a Prometheus metric azurerm_resource_info Is there a way in grafana to create a dashboard that will show I have x number of resource created 1 month ago, y number of resources ...
🌐
Prometheus
prometheus.io › docs › prometheus › latest › querying › examples
Query examples | Prometheus
count by (app) (instance_cpu_time_ns) If we are exploring some metrics for their labels, to e.g.
🌐
Last9
last9.io › blog › prometheus-group-by-label
Prometheus Group By Label: Advanced Aggregation Techniques for Monitoring | Last9
June 12, 2026 - It tells Prometheus which labels to keep in the result, allowing you to group related time series, like by service, region, or environment. This lets you move from individual metrics to more useful summaries that still carry enough context to ...
🌐
client_java
prometheus.github.io › client_java › getting-started › labels
Labels | client_java
Counter counter = Counter.builder() .name("payments_total") .help("total number of payments") .constLabels(Labels.of("env", "dev")) .labelNames("type", "status") .register(); However, most use cases for constLabels() are better covered by target labels set by the scraping Prometheus server, or by one specific metric (e.g.
🌐
Chris's Wiki
utcc.utoronto.ca › ~cks › space › blog › sysadmin › PrometheusCountDistinctLabels
Counting the number of distinct labels in a Prometheus metric
November 30, 2019 - Having generated this new vector, we simply count how many elements are in it with count(). The final expression is: ... This will give us the number of different users that are connected right now. Next, suppose that we want to know how many different users have used our VPNs over some span of time, such as the past day. To do this in the most straightforward way, we'll start by basically aggregating our time spam down to something that has an element (with a full set of labels) if the user was connected to a particular VPN server at some point in the time span.
🌐
GitHub
github.com › prometheus › prometheus › issues › 172
Implement "COUNT expr BY (labels)" · Issue #172 · prometheus/prometheus
April 22, 2013 - count returns a vector, with all labels being preserved that are common among the counted elements · count becomes an operator of the form COUNT expr BY (labels)
Author: prometheus
🌐
Google Groups
groups.google.com › g › prometheus-users › c › es9KAsTY-Jc
PromQL query to count how many series have {label=XYZ}
March 24, 2021 - On 24 Mar 19:15, John Dexter wrote: ... a given label value for a > given metric. > > I am looking at something like: > group by (job) (my_updates_total{job="Job123"}) count by (job) (my_updates_total{job="Job123"}) > > It seems to work but feels a bit odd, is it right? > > -- > You received this message because you are subscribed to the Google Groups "Prometheus Users" ...
🌐
Prometheus
prometheus.io › docs › practices › naming
Metric and label naming | Prometheus
...SHOULD use base units (e.g. seconds, bytes, meters - not milliseconds, megabytes, kilometers). See below for a list of base units. ...SHOULD have a suffix describing the unit, in plural form. Note that an accumulating count has total as a suffix, in addition to the unit if applicable.
🌐
Grafana
community.grafana.com › prometheus
Count and group by day based on label value - Prometheus - Grafana Labs Community Forums
March 30, 2023 - What Grafana version and what operating system are you using? Grafana v9.1.4 What are you trying to achieve? I’m collecting metrics about log files with filestat_exporter, and i would like to have graphic with the count of rotated logs per day based on values of the label path. file_stat_size_bytes{fqdn=~“$fqdn”,path=~“/var/log/mylog-[0-9].*.log”} so the path label has values like this: /var/log/mylog-2023-03-18.0.log /var/log/mylog-2023-03-18.1.log /var/log/mylog-2023-03-18.2.log ...
🌐
The Mail Archive
mail-archive.com › prometheus-users@googlegroups.com › msg05819.html
[prometheus-users] Prometheus query to count unique label values
November 11, 2020 - How can I do that? Example: apple=1, orange=1 (count(count by (alertname)(customer_alerts[24h]))) Please note I am using grafana to create the dashboard. Thanks, Shilpa -- You received this message because you are subscribed to the Google Groups "Prometheus Users" group.
🌐
GitHub
github.com › prometheus › prometheus › issues › 11584
No prometheus metric to find all unique label names, unique label counts or unique label value pairs · Issue #11584 · prometheus/prometheus
November 15, 2022 - See URL below: https://grafana.com/docs/grafana-cloud/billing-and-usage/control-prometheus-metrics-usage/cardinality-management/ But I have found that there is no metric which can give me unique label names or count of unique labels or unique values for each label.
Author: prometheus
🌐
Robust Perception
robustperception.io › using-the-group-aggregator-in-promql
Using the group() aggregator in PromQL – Robust Perception | Prometheus Monitoring Experts
August 10, 2020 - This is where group comes in. group ... aggregation's label handling that is what's important rather than the numeric result: count without(cpu) ( group without(mode) (node_cpu_seconds_total) )...