Use the following PromQL:

count_values("status", probe_http_status_code)

More info in Prometheus documentation here.

Answer from Marcelo Ávila de Oliveira on Stack Overflow
🌐
Prometheus
prometheus.io › docs › prometheus › latest › querying › examples
Query examples | Prometheus
...we could get the top 3 CPU users grouped by application (app) and process type (proc) like this: 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 ...
🌐
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 ...
People also ask

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 ...
How do I use the "group by" function with labels in Prometheus queries?
Apply by (label) after an aggregation function. For example: avg(cpu_usage_seconds_total) by (service) This gives the average CPU usage grouped by service.
🌐
last9.io
last9.io › blog › prometheus-group-by-label
Prometheus Group By Label: Advanced Aggregation Techniques for ...
How do I use the "group by" function to aggregate metrics by label in Prometheus?
Combine aggregation and grouping like this: sum(rate(http_requests_total[5m])) by (service) This gives the request rate per service by summing over time.
🌐
last9.io
last9.io › blog › prometheus-group-by-label
Prometheus Group By Label: Advanced Aggregation Techniques for ...
🌐
OpenObserve
openobserve.ai › home › blog › prometheus metrics count basics
Prometheus Metrics Count Basics
September 26, 2025 - This architecture is why Prometheus ...sts_total)) This query works in two steps. First, count by (status_code) (http_requests_total) groups all HTTP requests by their status code (like 200, 404, 500)....
🌐
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 ...
🌐
Robust Perception
robustperception.io › using-the-group-aggregator-in-promql
Using the group() aggregator in PromQL – Robust Perception | Prometheus Monitoring Experts
August 10, 2020 - group always produces 1 as a the ... aggregation's label handling that is what's important rather than the numeric result: count without(cpu) ( group without(mode) (node_cpu_seconds_total) )...
🌐
Promlabs
promlabs.com › promql-cheat-sheet
PromLabs | PromQL Cheat Sheet
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]) ) )
🌐
Promlabs
promlabs.com › blog › 2020 › 12 › 17 › promql-queries-for-exploring-your-metrics
PromLabs | Blog - PromQL Queries for Exploring Your Metrics
December 17, 2020 - count(group by(le, job) (demo_api_request_duration_seconds_bucket)) This way, you are able to get a good idea about the cost split-up of your metrics. For understanding the semantic meaning of your metrics, their documentation string and metric type information (counter, gauge, histogram, summary) are very useful. This information is not directly accessible via PromQL, but the Prometheus server keeps it in memory for each target and it can be queried via another metadata API endpoint.
Find elsewhere
🌐
Coralogix
coralogix.com › home › promql tutorial: 5 tricks to become a prometheus god
PromQL Tutorial: 5 Tricks to Become a Prometheus God
June 3, 2025 - If you’re familiar with SQL, you’ll remember that GROUP BY allows you to group results by a field (e.g country or city) and apply an aggregate function, such as AVG() or COUNT(), to values of another field.
🌐
Better Stack
betterstack.com › community › questions › how-can-group-labels-in-prometheus-query
How Can I Group Labels in a Prometheus Query? | Better Stack Community
August 5, 2025 - If you want to count the total number of requests grouped by the method label (e.g., GET, POST), you can use: ... This query sums the total requests and groups the result by the method label, giving you the total number of requests for each HTTP method.
🌐
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 ...
🌐
Grafana
community.grafana.com › prometheus
Group by option in query for prometheus - Prometheus - Grafana Labs Community Forums
June 15, 2017 - Is there a way to do a group by query on Prometheus database like there’s for Graphite databases?
🌐
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 - Data Explosion: Grouping by numerous labels might result in an explosion of time series. Be mindful of this to avoid overwhelming your Prometheus server. Misleading Aggregations: Ensure your by() clauses make logical sense to avoid misleading aggregations. Double-check that the labels used align with your intended analysis. The count_values() function offers an alternative approach to counting unique label values:
🌐
Medium
medium.com › @suchitasharma1106 › a-comprehensive-guide-to-grouping-and-functions-in-promql-cc3c438be320
A Comprehensive Guide to Grouping and Functions in PromQL | by Suchita Sharma | Medium
October 7, 2024 - PromQL (Prometheus Query Language) is a powerful query language used to extract and analyze metrics from time-series data stored in Prometheus. It’s designed for use in monitoring and alerting systems, allowing users to query and aggregate metrics effectively. In this blog, we’ll cover grouping in PromQL, explore the core functions, and look at various ways to combine them to build insightful queries.
🌐
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.
🌐
Chris's Wiki
utcc.utoronto.ca › ~cks › space › blog › sysadmin › PrometheusCountDistinctLabels
Counting the number of distinct labels in a Prometheus metric
November 30, 2019 - For our purposes we can use any of the straightforward operators such as sum, min, or max; I'll use sum. Using 'sum(...) by (user)' will produce a series like this: ... Having generated this new vector, we simply count how many elements are in it with count().
🌐
Google Groups
groups.google.com › g › prometheus-users › c › es9KAsTY-Jc
PromQL query to count how many series have {label=XYZ}
March 24, 2021 - > > 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" group.
🌐
SigNoz
signoz.io › guides › how to group labels in prometheus queries - a practical guide
How to Group Labels in Prometheus Queries - A Practical Guide | SigNoz
July 24, 2024 - Prometheus Query Language (PromQL) offers powerful tools for label grouping. The primary method involves using the group() operator along with the by clause.
🌐
Prometheus
prometheus.io › docs › prometheus › latest › querying › operators
Operators | Prometheus
In case the threshold value is not aligned to one of the bucket boundaries of the histogram, either linear (for NHCB and zero buckets of exponential histogram) or exponential (for non zero bucket of exponential histogram) interpolation is applied to compute the estimated count of observations that remain in the bucket containing the threshold. In case when some observations get trimmed, the new sum of observation values is recomputed (approximately) based on the remaining observations. The following binary comparison operators exist in Prometheus: ... Comparison operators are defined between scalar/scalar, vector/scalar, and vector/vector value pairs. By default they filter.