🌐
Prometheus
prometheus.io › docs › prometheus › latest › querying › examples
Query examples | Prometheus
If we have two different metrics with the same dimensional labels, we can apply binary operators to them and elements on both sides with the same label set will get matched and propagated to the output. For example, this expression returns the unused memory in MiB for every instance (on a fictional cluster scheduler exposing these metrics about the instances it runs): (instance_memory_limit_bytes - instance_memory_usage_bytes) / 1024 / 1024 · The same expression, but summed by application, could be written like this:
Discussions

prometheus - PromQL sum by label over time - Stack Overflow
I am trying to sum up a counter metric over time and grouped by the label applied. I've tried this sum by (searchTerm) (bot_guides_failed_total) but I want to have out in a table form like this: More on stackoverflow.com
🌐 stackoverflow.com
Prometheus query to only include sum of labels with other metric value over some value - Stack Overflow
If I use this query sum by (host_name) ... / sum by (host_name) (vmware_host_memory_max) it looks like I have way over provisioned because there are quite a few VMs that are off but are still included in the total of vmware_vm_memory_max for a given ESXi host. I'd like to have Prometheus ignore any ... More on stackoverflow.com
🌐 stackoverflow.com
openshift - Prometheus sum while filtering by label - Stack Overflow
In Prometheus I can provide a sum of pod cpu usage that is filtered by namespace: sum(node_namespace_pod_container:container_cpu_usage_seconds_total:sum_irate{namespace='my-namespace'}) by (pod) I... More on stackoverflow.com
🌐 stackoverflow.com
relabel and aggregate metrics
For future travelers here is what I found after looking around.Prometheus cant do what I'm asking for directly since running the sum (aggergation) query requires the data to be in the tsdb , which deafets the purpose of doing the aggregation on scrap. There are other ways to do this. writing your own exporter; basically hack a python script and expose /metrics that scrap rabbitmq and do the aggregation on demand without having a state. having another prometheus instance with a recording rule federated to the main instance, this will be the most compatible but will cause delays of queries since recording rules gets evaluated after the scrap getting stored using victoriametrics aggregation via a cheap single instance server with the lowest retention possible then using the /federate endpoint as a scrap endpoint for my main prometheus give up and just dont collect those metrics I choose the 3rd option since it is the most sane one. Although I dont like having this victoriametrics instance just to aggregate, and I dont want to maintain or solve the problems related to metrics aggregation with my own hacky python script, I have no other choice but to use this. If anyone else have a better solution let me know edit: note with victoriametrics, the only shared metrics with the federate endpoint are the aggregated ones, so you might need to scrap twice, once for prometheus with dropping the labels you want to aggregate, and second for victoriametrics with the labels you want to aggregate More on reddit.com
🌐 r/PrometheusMonitoring
4
2
July 21, 2023
People also ask

What are the limitations of Prometheus labels?
Labels with high cardinality, like user_id or request_id—can generate too many time series, slowing down queries and increasing memory usage. Labels must follow specific naming rules, can't start with __, and are case-sensitive.
🌐
last9.io
last9.io › blog › prometheus-group-by-label
Prometheus Group By Label: Advanced Aggregation Techniques for ...
What is the job label in Prometheus?
The job label identifies the target being scraped. It’s automatically assigned by Prometheus and helps group metrics by application, service, or source as defined in the scrape configuration.
🌐
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 ...
🌐
Last9
last9.io › blog › prometheus-group-by-label
Prometheus Group By Label: Advanced Aggregation Techniques for Monitoring | Last9
June 12, 2026 - In Prometheus, group by is an operator ... how data should be grouped. On the other hand, sum by (...) combines the sum() aggregation function with group by....
🌐
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 ... 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....
🌐
Prometheus
prometheus.io › docs › prometheus › latest › querying › functions
Query functions | Prometheus
histogram_quantile(0.9, sum by (job) (rate(http_request_duration_seconds[10m]))) To aggregate all classic histograms, specify only the le label:
🌐
Prometheus
prometheus.io › docs › prometheus › latest › querying › operators
Operators | Prometheus
without removes the listed labels ... their label values are identical between all elements of the vector. sum(v) sums up sample values in v in the same way as the + binary operator does between two values....
🌐
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 - The by and without clauses enable ... tells the query to include labels: the query sum by(instance) (node_filesystem_size_bytes) returns the total node_filesystem_size_bytes for each instance....
Find elsewhere
🌐
Fiberplane
fiberplane.com › blog › why-are-prometheus-queries-hard
Why are Prometheus queries hard? | Fiberplane Blog
July 4, 2023 - When querying our data, we often care about some of those label dimensions and not others. In PromQL, sum by (label1, label2,…) groups the time series by the labels you specify and uses the sum function to merge series together (similar to ...
🌐
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 - Here are some common functions and how they can be applied: Aggregation functions are used to aggregate data across multiple time-series, typically with by() or without(). sum(): Adds up the values of all selected time series.
🌐
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()
🌐
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
sum(node_disk_bytes_read * on(instance) group_left(node_name) node_meta{}) by (node_name) on(instance) => this is how to JOIN on label instance. group_left(node_name) node_meta{} => means, keep the label node_name from metric node_meta in the result.
🌐
Robust Perception
robustperception.io › using-the-group-aggregator-in-promql
Using the group() aggregator in PromQL – Robust Perception | Prometheus Monitoring Experts
August 10, 2020 - 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. The thing is though that the inner aggregation doesn't have to be count. 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.
🌐
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 - Proper label grouping significantly improves query performance and data visualization. group() drops specified labels without modifying values, while sum() aggregates values across the grouped labels.
🌐
Reddit
reddit.com › r/prometheusmonitoring › relabel and aggregate metrics
r/PrometheusMonitoring on Reddit: relabel and aggregate metrics
July 21, 2023 -

Hi,

I have rabbitmq metrics which contains the `channel` label. Since this label has high cardinality I decided I want to drop it, but faced an issue.

When prometheus drops it, there will be duplicates, and prometheus just take one of them, the exact situation here https://grafana.com/blog/2022/10/20/how-to-manage-high-cardinality-metrics-in-prometheus-and-kubernetes/#3-begin-optimizing-metrics in the `Reduce labels` section.

From what I can see, I need recording rule that would sum these metrics but im not sure about the order of operations.

If I have a metric_relabeling_rule in the scrapping config and a recording rule, which one will be applied first?

Is there a sensible way of recalculating all of the metrics that contains the `channel` label and take the sum of them such that no data is being dropped?

Or do I have to create a new metric name with the channel summed?

Edit:
In this response they say "maybe you need to aggregate over the duplicate series", but i dont know if they mean recording rules or what

Top answer
1 of 1
1
For future travelers here is what I found after looking around.Prometheus cant do what I'm asking for directly since running the sum (aggergation) query requires the data to be in the tsdb , which deafets the purpose of doing the aggregation on scrap. There are other ways to do this. writing your own exporter; basically hack a python script and expose /metrics that scrap rabbitmq and do the aggregation on demand without having a state. having another prometheus instance with a recording rule federated to the main instance, this will be the most compatible but will cause delays of queries since recording rules gets evaluated after the scrap getting stored using victoriametrics aggregation via a cheap single instance server with the lowest retention possible then using the /federate endpoint as a scrap endpoint for my main prometheus give up and just dont collect those metrics I choose the 3rd option since it is the most sane one. Although I dont like having this victoriametrics instance just to aggregate, and I dont want to maintain or solve the problems related to metrics aggregation with my own hacky python script, I have no other choice but to use this. If anyone else have a better solution let me know edit: note with victoriametrics, the only shared metrics with the federate endpoint are the aggregated ones, so you might need to scrap twice, once for prometheus with dropping the labels you want to aggregate, and second for victoriametrics with the labels you want to aggregate
🌐
Middleware
middleware.io › blog › prometheus-labels
Prometheus Labels: Understanding and Best Practices
sum by (status, endpoint) (rate(http_requests_total[5m])) The above will first group all the HTTP request rates in the last 5 minutes by the value of the labels Prometheus provides, specifically status and endpoint.
🌐
Grafana
community.grafana.com › prometheus
Grafana table with sum of two prometheus labels, first label as row and second as column - Prometheus - Grafana Labs Community Forums
August 24, 2022 - I have the following Prometheus query with a gauge metric: sum by (service, status) (service_results_total) The metric is more granular and has other labels, that’s why aggregation is needed. I’d like to generate a table where the service label is the row and the status label is the column ...
🌐
GitHub
github.com › prometheus › prometheus › issues › 12934
promql: numerical comparison of label values · Issue #12934 · prometheus/prometheus
October 4, 2023 - And it won't even end there because one might argue we should then also be able to do aggregation based on the numerical label value (do a sum by (le) where all numerically equal le labels end up in one resulting entry). Prometheus 1.x normalized the values of the le and quantile labels of (classic) histograms and summaries, respectively, i.e.
Author: prometheus