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.
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.
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 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 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 ...
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:
Prometheus
prometheus.io › docs › prometheus › latest › querying › functions
Query functions | Prometheus
Please note that sort_by_label only affects the results of instant queries, as range query results always have a fixed output ordering. ... This function has to be enabled via the feature flag --enable-feature=promql-experimental-functions.
Robust Perception
robustperception.io › using-the-group-aggregator-in-promql
Using the group() aggregator in PromQL – Robust Perception | Prometheus Monitoring Experts
August 10, 2020 - 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:
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]) ) )
Promlabs
promlabs.com › blog › 2020 › 12 › 17 › promql-queries-for-exploring-your-metrics
PromLabs | Blog - PromQL Queries for Exploring Your Metrics
December 17, 2020 - If your UI does not already show you this list in one way or another (it really should!), you can query for it by first selecting all series, then grouping by the special metric name label __name__: ... Note: A more efficient, non-PromQL way to get the same information is to use Prometheus's label values metadata endpoint to get all values for the __name__ label, e.g.: https://demo.promlabs.com/api/v1/label/name/values.
Google
docs.cloud.google.com › cloud monitoring › promql for cloud monitoring
PromQL for Cloud Monitoring | Google Cloud Documentation
You can use PromQL to create alerting policies for any metric in Cloud Monitoring. Alerting policies can also filter and group time series by metric and resource labels.
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.
Puziol
devsecops.puziol.com.br › prometheus › promql
PromQL - Query Language | DevSecOps and Platform Engineering Knowledgement
Prometheus provides a functional query language called PromQL (Prometheus Query Language) that allows users to select and aggregate time series data in real time. The result of an expression can be shown as a graph, viewed as tabular data in the Prometheus expression browser, or consumed by external systems via the HTTP API.
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
Chris's Wiki
utcc.utoronto.ca › ~cks › space › blog › sysadmin › PrometheusGroupLeftAndRightNotes
Prometheus's group_left() and group_right() operators
December 17, 2023 - The value comes from the left side metric, but by default all the labels will come from the right side metric and you'll have to explicitly pull in all of the left side labels you may care about for generating alert messages. (If you're using group_*() in order to pull in extra labels from the right hand side of a one to one match, this is why you want to use group_left() instead of group_right(); it automatically preserves all of the labels of your left side metric.)
Microsoft Community Hub
techcommunity.microsoft.com › microsoft community hub › communities › products › azure › azure observability blog
Announcing public preview of query-based metric alerts in Azure Monitor | Microsoft Community Hub
November 23, 2025 - Alerting at scale: Query-based ... resource group, using a single rule. Managed Identity Support: Securely authorize queries using Azure Managed Identity, ensuring compliance and reducing credential management overhead. Customizable Notifications: Add dynamic custom properties and custom email subjects for faster triage and context-rich alerting. Reuse community alerts: Easily import and re-use PromQL alert queries ...