Reputation: 109
this seems like a pretty easy thing to do. Yet I cannot wrap my head around it.
I make some calculations depending on the average CPU Utilization for the last 15s and get a value based of that calculation. No I want a graph in Grafana which shows the cumulative result. E.g.
Time passed | Current result | Cumulative result |
---|---|---|
15s | 5 | 5 |
30s | 7 | 12 |
45s | 6 | 18 |
At the moment my query looks something like:
sum (((1 - (avg by (cpu, instance) (rate(node_cpu_seconds_total{mode="idle"}[15s])))) * 2 + 4
This results in a graph plotting the current results. But I want a query plotting the cumulative results. When I try to wrap the whole query with a sum_over_time, I get the following exception: "expected type matrix in call to function "sum_over_time", got vector"
Thank you for your help
Upvotes: 3
Views: 762
Reputation: 2504
The problem is that sum_over_time returns a single value which is the total sum of all data points in the interval, whereas what you want is - for each timestamp - the sum up to that timestamp. That is unfortunately not possible in Prometheus alone.
But Grafana has support for that using an "Add field from calculation" transformation using "Cumulative functions" as mode . See https://stackoverflow.com/a/79453819/574351
Upvotes: 0
Reputation: 18094
PromQL in Prometheus doesn't support functions for cumulative calculations. If you need cumulative calculations, then try VictoriaMetrics instead - its query language - MetricsQL - provides running_sum() function.
P.s.: I'm the author of VictoriaMetrics.
Upvotes: 1