🌐
Last9
last9.io › blog › prometheus-group-by-label
Prometheus Group By Label: Advanced Aggregation Techniques for Monitoring | Last9
June 12, 2026 - The by clause in Prometheus comes right after an aggregation function. It tells Prometheus which labels to keep in the result, allowing you to group related time series, like by service, region, or environment.
🌐
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.
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 ...
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 ...
🌐
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 example, if you want to sum total requests but ignore the instance label, you can write: ... This aggregates the total requests across all instances. You can also combine groupings using on and ignoring. For example, if you want to group by method but ignore the instance label:
🌐
Coralogix
coralogix.com › home › promql tutorial: 5 tricks to become a prometheus god
PromQL Tutorial: Basic Concepts & Examples - Coralogix
June 3, 2025 - PromQL has twelve built in aggregation operators that allow you to perform statistics and data manipulation. ... 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 ...
🌐
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 - It allows you to summarize or categorize metrics based on their labels. There are two types of grouping: Without Grouping (without()): Removes certain labels from the aggregation. By Grouping (by()): Aggregates data based on specified labels.
🌐
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.
🌐
GitHub
github.com › prometheus › prometheus › discussions › 12205
Promql group by label for absent or absent_over_time · prometheus/prometheus · Discussion #12205
So the way I'm filling value with 0 is by doing · sum without() (up{service="service1"}) or (0 * absent(up{service="service1"})) This works if I specify service label, but I have many services, I want to have 0 filled for all of them, but absent or absent_over_time does not support group by label, which means (sum without() (up) or (0 * absent(up))) just doesn't work.
Author: prometheus
Find elsewhere
🌐
Robust Perception
robustperception.io › using-the-group-aggregator-in-promql
Using the group() aggregator in PromQL – Robust Perception | Prometheus Monitoring Experts
August 10, 2020 - It could be sum, max, or even stddev, because it's not the numeric result of the aggregation that we care about but instead the labels on the resultant time series. This is where group comes in. group always produces 1 as a the value of the aggregation group, but more importantly signifies for anyone reading the PromQL expression that it is the aggregation's label handling that is what's important rather than the numeric result:
🌐
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.
🌐
Middleware
middleware.io › blog › prometheus-labels
Prometheus Labels: Understanding and Best Practices
Moreover, Prometheus labels are used for PromQL aggregations like grouping and filtering.
🌐
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 ... you how to count unique label values using PromQL. Use count(group by (label_name) (metric_name)) to count unique label values...
🌐
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]) ) )
🌐
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 - The group() function returns 1 for each unique label combination, effectively listing all label values: # Get all unique namespace values (returns 1 for each) group(kube_pod_info) by (namespace) # Get all unique job/instance combinations group(up) ...
🌐
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.
🌐
Grafana
grafana.com › blog › 2021 › 08 › 04 › how-to-use-promql-joins-for-more-effective-queries-of-prometheus-metrics-at-scale
How to use PromQL joins for more effective queries of Prometheus metrics at scale | Grafana Labs
August 5, 2021 - groups: - name: slo_metric expr: count by (reference_label) ((api_response_latency * on (labelone,labeltwo) group_left(reference_label) sli_info > 100)
🌐
Google Groups
groups.google.com › g › prometheus-users › c › qlHK7r1hQVs
Joining two metrics in promtheus and having all labels from both
March 6, 2023 - Unless im forming my PromQL wrong? ... Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message ... To pick up labels from the other side, you need to list them as part of your group_right.
🌐
Yannick Pereira-Reis
ypereirareis.github.io › blog › 2020 › 02 › 21 › how-to-join-prometheus-metrics-by-label-with-promql
How to join Prometheus metrics by label with PromQL – Yannick Pereira-Reis
There is a label in common between the two metrics “node_meta” and “node_disk_bytes_read”: instance. ... How to query prometheus to have sum of “disk bytes read” by instance/node/server name ? The result we want is something like that : node2 => 22082332072448 node4 => 8439202548224 node5 => 28203612148224 node6 => 56887513977344 node3 => 30887053824 node1 => 36352176166912 · sum(node_disk_bytes_read * on(instance) group_left(node_name) node_meta{}) by (node_name)
🌐
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?