Last9
last9.io › blog › prometheus-group-by-label
Prometheus Group By Label: Advanced Aggregation Techniques for Monitoring | Last9
June 12, 2026 - How to use group by in PromQL? Place the by clause after an aggregation function like sum(), avg(), or count(). For example:
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 ...
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 ...
Promlabs
promlabs.com › promql-cheat-sheet
PromLabs | PromQL Cheat Sheet
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 ...
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:
Medium
valyala.medium.com › promql-tutorial-for-beginners-9ab455142085
PromQL tutorial for beginners and humans | by Aliaksandr Valialkin | Medium
September 15, 2023 - SELECT ts.metric_name_plus_tags, r.timestamps, r.values FROM ( (SELECT time_series_id, array_agg(timestamp ORDER BY timestamp) AS timestamps, array_agg(value ORDER BY timestamp) AS values FROM metrics WHERE time_series_id IN ( SELECT id FROM time_series WHERE metric_name = 'node_network_receive_bytes_total' ) GROUP BY time_series_id ) ) AS r JOIN time_series AS ts ON (r.time_series_id = ts.id) Easy, isn’t it? :) The SQL must be even more complex in order to be on par with the one-word PromQL query above, since it doesn’t take into account time ranges and down-sampling, which are automatically handled by /query_range API for PromQL with start, end and step args.
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 - For instance, if you want to count the total requests grouped by both method and status, you can do: ... This query returns the total number of requests for each combination of HTTP method and status. If you want to aggregate metrics while ignoring certain labels, you can use the without keyword. For example, if you want to sum total requests but ignore the instance label, you can write:
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.
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) ( group without(mode) (node_cpu_seconds_total) ) Finally, as the value is 1 you could also use sum for the outer aggregation similarly to how you could for info metrics. Have PromQL questions?
Logz.io
logz.io › home › blog › how to › an intro to promql: basic concepts & examples
An Intro to PromQL: Basic Concepts & Examples | Logz.io
September 2, 2023 - Similarly, PromQL lets you group multiple labels together, then sorting according to those groupings. If you want a more thorough intro to installation and configuration, check out our recent Prometheus tutorial for system and Docker metrics. To be clear, there are two kinds of “types” in Prometheus. There are the metric types of metrics and the data types of PromQL expressions.
DevOps.dev
blog.devops.dev › advanced-promql-understanding-optimizing-and-logical-grouping-of-queries-11220e80ba0d
Advanced PromQL: Understanding, Optimizing, and Logical Grouping of Queries | by Ashutosh Singh | DevOps.dev
July 20, 2023 - This query calculates the average rate of POST HTTP requests over the last 5 minutes, grouped by the job label. PromQL queries can become resource-intensive, particularly when dealing with a high cardinality dataset or long time ranges.
DoHost
dohost.us › home › 2025 › september › 27 › advanced querying: using labels and grouping in promql
Advanced Querying: Using Labels and Grouping in PromQL - DoHost
September 27, 2025 - Think of `by` as “group keeping only these labels” and `without` as “group ignoring these labels”. Use `rate` for steadily increasing counters and `irate` for more volatile counters that might reset frequently. `irate` can give you more accurate results in such scenarios because it only looks at the last two data points. Yes, you can use multiple aggregation operators in a single PromQL query.
Prometheus
prometheus.io › docs › prometheus › latest › querying › basics
Querying basics | Prometheus
Other programs can fetch the result of a PromQL expression via the HTTP API. This document is a Prometheus basic language reference. For learning, it may be easier to start with a couple of examples. The value of a sample at a given timestamp returned by PromQL may be a float or a native histogram.