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 OverflowPrometheus
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 ...
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 ...
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.
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 ...
Top answer 1 of 3
74
It's even easier
sum by (group) (my_metric)
2 of 3
57
Yes, you can you use label replace to group all the misc together:
sum by (new_group) (
label_replace(
label_replace(my_metric, "new_group", "$1", "group", ".+"),
"new_group", "misc", "group", "misc group.+"
)
)
The inner label_replace copies all values from group into new_group, the outer overwrites those which match "misc group.+" with "misc", and we then sum by the "new_group" label. The reason for using a new label is the series would no longer be unique if we just overwrote the "group" label, and the sum wouldn't work.
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.
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.