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 - ... count(http_requests_total): This part of the query counts the number of occurrences of the http_requests_total metric across all instances. by (instance): This clause specifies that the counting should be grouped by the instance 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
prometheus - Count the labels value and use it in another query - PromQL - Stack Overflow
I'm making a Grafana dashboard to display the performance of the canary application. My problem is I need to find out which instance is the canary one (blue or green). Canary stack will always crea... More on stackoverflow.com
🌐 stackoverflow.com
No prometheus metric to find all unique label names, unique label counts or unique label value pairs
Proposal I was trying to create a high cardinality management dashboard as Grafana cloud has. See URL below: https://grafana.com/docs/grafana-cloud/billing-and-usage/control-prometheus-metrics-usag... More on github.com
🌐 github.com
6
November 15, 2022
Counting unique values in PromQL
regardless of what you want to achieve: this to me is a really weird metric to be using for this purpose as the value is neither a gauge, nor a counter. I'd expect the method to be also a label/value pair as it is a piece of metadata for a specific event and the value does not signify the outcome of the event or state of the system. More on reddit.com
🌐 r/PrometheusMonitoring
2
2
November 22, 2023
People also ask

How to use group by in PromQL?
Place the by clause after an aggregation function like sum(), avg(), or count(). For example: sum(http_requests_total) by (service, region) This aggregates the metric and groups results by service and region.
🌐
last9.io
last9.io › blog › prometheus-group-by-label
Prometheus Group By Label: Advanced Aggregation Techniques for ...
Why count unique label values?
Counting unique values helps measure cardinality, which is important for performance. Use queries like: count by (label_name) (metric_name) to see how many unique label values exist.
🌐
last9.io
last9.io › blog › prometheus-group-by-label
Prometheus Group By Label: Advanced Aggregation Techniques for ...
How can I group labels in a Prometheus query?
Use by (label1, label2) to retain specific labels or without (label) to exclude one or more. For example: sum(cpu_usage) by (region) sum(memory_usage) without (instance)
🌐
last9.io
last9.io › blog › prometheus-group-by-label
Prometheus Group By Label: Advanced Aggregation Techniques for ...
🌐
OneUptime
oneuptime.com › home › blog › how to count unique label values in prometheus
How to Count Unique Label Values in Prometheus
December 17, 2025 - However, understanding how many unique values exist for a given label is crucial for cardinality management and query optimization. This guide shows you how to count unique label values using PromQL. Use count(group by (label_name) (metric_name)) to ...
🌐
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))`.
🌐
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 - Functions like count() and count_values() may struggle with performance issues and become less efficient when analyzing high-cardinality metrics. Queries requiring sophisticated grouping and aggregation across various labels can become complex and less intuitive in PromQL. While Prometheus is excellent for time-series data collection and querying, SigNoz extends its capabilities by ...
🌐
Last9
last9.io › blog › prometheus-group-by-label
Prometheus Group By Label: Advanced Aggregation Techniques for Monitoring | Last9
June 12, 2026 - It gives you total usage or error counts by service without pulling in unnecessary detail. Here are a few practical queries that use sum by to answer operational questions: ... Each of these queries gives you high-level visibility. Without grouping, you’d have to manually look at or sum dozens of metrics. ... If you’re working with PromQL ...
🌐
Promlabs
promlabs.com › promql-cheat-sheet
PromLabs | PromQL Cheat Sheet
Go get our self-paced in-depth PromQL training! Select latest sample for series with a given metric name: ... Available aggregation operators: sum(), min(), max(), avg(), stddev(), stdvar(), count(), count_values(), group(), bottomk(), topk(), quantile() ... Only keep series from the left-hand side whose sample values are larger than their right-hand-side matches: ... histogram_quantile( 0.9, sum by(le, path, method) ( rate(demo_api_request_duration_seconds_bucket[5m]) ) )
Find elsewhere
🌐
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.
🌐
Chris's Wiki
utcc.utoronto.ca › ~cks › space › blog › sysadmin › PrometheusCountDistinctLabels
Counting the number of distinct labels in a Prometheus metric
November 30, 2019 - This gives us an instant vector that we can then process in the same way as we did with vpn_user_sessions when we generated our number of currently connected users; we aggregate it to get rid of all labels other than 'user', and then we count how many distinct elements we have. The resulting query is: count( sum( min_over_time( vpn_user_sessions[24h] ) ) by (user) )
🌐
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: > I would like to count how many time-series have 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"})
🌐
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)))

🌐
Robust Perception
robustperception.io › using-the-group-aggregator-in-promql
Using the group() aggregator in PromQL – Robust Perception | Prometheus Monitoring Experts
August 10, 2020 - count without(cpu) ( count without(mode) (node_cpu_seconds_total) ) That is first you aggregate away any other labels that don't matter with the inner aggregation (here just the mode label), and then count the resulting series with the outer aggregation.
🌐
Coralogix
coralogix.com › home › promql tutorial: 5 tricks to become a prometheus god
PromQL Tutorial: Basic Concepts & Examples - Coralogix
June 3, 2025 - What if you want to aggregate by a label just to get values for that label? Prometheus 2.0 introduced the group() operator for exactly this purpose. Using it makes queries easier to interpret and means you don’t need to use bodges. ... PromQL has two operators for counting up elements in a time series.
🌐
Prometheus
prometheus.io › docs › prometheus › latest › querying › operators
Operators | Prometheus
limit_ratio(r, v) (sample a pseudo-random ratio r of elements, experimental, must be enabled with --enable-feature=promql-experimental-functions) group(v) (all values in the resulting vector are 1) ... These operators can either be used to aggregate over all label dimensions or preserve distinct dimensions by including a without or by clause.
🌐
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.
🌐
OneUptime
oneuptime.com › home › blog › how to write prometheus queries that return label values
How to Write Prometheus Queries That Return Label Values
December 17, 2025 - groups: - name: label_materialization rules: # Create a metric that exposes label as value - record: namespace:pod_count:total expr: count(kube_pod_info) by (namespace) # Store label mappings - record: info:service_version:labels expr: | max( label_replace( service_info, "version_major", "$1", "version", "(\\d+)\\..*" ) ) by (service, version, version_major)
🌐
Prometheus
prometheus.io › docs › prometheus › latest › querying › examples
Query examples | Prometheus
topk(3, sum by (app, proc) (rate(instance_cpu_time_ns[5m]))) Assuming this metric contains one time series per running instance, you could count the number of running instances per application like this: ... If we are exploring some metrics for their labels, to e.g.
🌐
Stack Overflow
stackoverflow.com › questions › 72980697 › count-the-labels-value-and-use-it-in-another-query-promql
prometheus - Count the labels value and use it in another query - PromQL - Stack Overflow
I tried the below query and it ...n=${location}}) == 1)) 2022-07-15T10:19:29.703Z+00:00 ... Just add location label name into every on() modifier: on(location)....
🌐
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 - 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
🌐
SigNoz
signoz.io › guides › how to write prometheus queries to return label values
How to Write Prometheus Queries to Return Label Values | SigNoz
July 25, 2024 - PromQL is a powerful language designed specifically for time series data manipulation. To select metrics with specific labels, use this basic syntax: ... This query returns the total number of HTTP requests grouped by the method label.