It's even easier
sum by (group) (my_metric)
Answer from uamanager on Stack Overflow 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.
Last9
last9.io › blog › prometheus-group-by-label
Prometheus Group By Label: Advanced Aggregation Techniques for Monitoring | Last9
June 12, 2026 - Every label you add to a grouping increases the number of time series Prometheus has to store and process. For example: ... Start with just service, then add dimensions like region or environment only when you need that additional context. For a reliable, low-noise overview of how your services are performing, this pattern works well: ... It gives you total usage or error counts by service without pulling in unnecessary detail.
What are Prometheus labels?
Prometheus labels are key-value pairs that add context to metrics and help in filtering and aggregating your metrics for enhanced observability.
middleware.io
middleware.io › blog › prometheus-labels
Prometheus Labels: Understanding and Best Practices
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 ...
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 ...
Prometheus
prometheus.io › docs › prometheus › latest › querying › examples
Query examples | Prometheus
Assuming that the http_requests_total time series all have the labels job (fanout by job name) and instance (fanout by instance of the job), we might want to sum over the rate of all instances, so we get fewer output time series, but still preserve the job dimension:
Iximiuz
iximiuz.com › en › posts › prometheus-vector-matching
Prometheus Cheat Sheet - How to Join Multiple Metrics (Vector Matching)
November 30, 2021 - If during a query execution Prometheus finds a collision (label-wise) on the "one" side, the query will fail with the following error: found duplicate series for the match group <keys/values> on the <left|right> hand-side of the operation: <op>; many-to-many matching not allowed: matching labels must be unique on one side · Interesting, that even if the "one" side doesn't have collisions and group_left or group_right is specified, a query can still fail with: multiple matches for labels: grouping labels must ensure unique matches
Stack Overflow
stackoverflow.com › questions › 74106857 › multiple-group-left-join-to-get-owner-labels
prometheus - Multiple group_left join to get owner labels - Stack Overflow
October 18, 2022 - sum by(namespace, pod, owner_kind) (max by(namespace, pod) (kube_pod_status_phase{job="kube-state-metrics",namespace="itops",phase=~"Pending|Unknown|Failed"}) * on(namespace, pod) group_left(owner_kind) topk by(namespace, pod) (1, max by(namespace, pod, owner_kind) (kube_pod_owner{owner_kind='ReplicaSet'})))
Google Groups
groups.google.com › g › prometheus-users › c › qlHK7r1hQVs
Joining two metrics in promtheus and having all labels from both
March 6, 2023 - To view this discussion on the ... member email addresses permission to view the original message ... But yes, you'll have to treat it as a many-to-one in order to pick up the extra labels....
Prometheus
prometheus.io › docs › prometheus › latest › querying › operators
Operators | Prometheus
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.
Google Groups
groups.google.com › g › prometheus-users › c › or-U4nMHBA0
How to deal with multivalue labels
February 14, 2018 - And I'd like to get average cpu utilization (load/core count) grouped by team and datacenter. A machine can belong to multiple teams, so the same instance might have to be included in multiple averages. It seems you cannot group left twice to annotate other metrics with labels from two other metrics.
Robust Perception
robustperception.io › using-the-group-aggregator-in-promql
Using the group() aggregator in PromQL – Robust Perception | Prometheus Monitoring Experts
August 10, 2020 - 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. This is where group comes in.
Google Groups
groups.google.com › g › prometheus-users › c › VmYTkQhO5Kg
PromQL: multiple queries with dependent values
October 13, 2022 - The shared label value would be something like, group="cluster-a" and should not evaluate metrics where group="cluster-b" Thanks in advance! ... Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message ... Yes, but it depends on exactly what you mean. The details are here: https://prometheus.io/docs/prometheus/latest/querying/operators/
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 - This can be useful in Prometheus ... a series by appending labels from another info metric. For more information on the join operator, see the documentation for Prometheus Querying Operators and check out these blog posts: ... You can repurpose the tooling that generates the 18,000 rule groups to instead ...
about:farcaller
farcaller.net › posts › this is how you merge labels from several prometheus metrics
This is how you merge labels from several prometheus metrics | about:farcaller
May 31, 2024 - we take the values of node_hwmon_temp_celsius (1), and group it (4) with the additional label of label from node_hwmon_sensor_label (5) using the job, chip, and sensor (3) as the labels to group on. As you can only do vector matching on bin-ops, we also divide (2) the value of temp over the value of sensor label. In this case the latter is always 1, so it’s safe to divide by it (I actually picked / and not * just in case it’s not 1.