It's even easier
sum by (group) (my_metric)
Answer from uamanager on Stack OverflowIt's even easier
sum by (group) (my_metric)
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 - PromQL sum by label over time - Stack Overflow
Prometheus query to only include sum of labels with other metric value over some value - Stack Overflow
openshift - Prometheus sum while filtering by label - Stack Overflow
relabel and aggregate metrics
What are the limitations of Prometheus labels?
What is the job label in Prometheus?
How can I group labels in a Prometheus query?
The following PromQL query should return the increase of bot_guides_failed_total time series over the last hour (see 1h in square brackets) grouped by searchTerm label:
sum(increase(bot_guides_failed_total[1h])) by (searchTerm)
If this query is used for building a graph in Grafana, then every point on the graph will contain the increase of the bot_guides_failed_total metric over the one hour interval ending at this point.
Note that the increase() function in Prometheus may return unexpected results when applied to slow-changing counters. This is because of extrapolation - see this issue for details. If you need the expected results from the increase() function, then try VictoriaMetrics instead - this is Prometheus-like monitoring system I work on.
You need to use a function to extract the number of searches in a specific time window. E.g:
sum by (increase(searchTerm[5m])) (bot_guides_failed_total)
This will give you the number of searchTerm grouped by bot_guides_failed_total in a 5 minutes time window.
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