Difference between max
and max_over_time
max
returns maximum among time series returned by inner selector. Result is single time series.
max_over_time
returns maximum value of every time series over specified range. Result contains number of values equal to number of inner time series.
Consider this demo.
Same logic applies to all <aggregation>
vs. <aggregation>_over_time
functions.
Maximum CPU usage
I want to know, what is the maximum CPU usage in last 7 days using promql for each instance.
First of all I'm assuming here you are using node_exporter
's metrics, and the following message will be based on this assumption, though I don't know what service="x"
means in your selector. Hopefully it is just static label applied to target.
Regarding calculation of CPU utilization everything is not as simple as you tried.
I believe, simplest query to get CPU utilization of an instance is this:
100 - (avg by(instance) (rate(node_cpu_seconds_total{mode="idle"}[2m])) * 100)
Taken from this answer.
So, to get maximum value over last week you could use this:
max_over_time((100 - (avg by(instance) (rate(node_cpu_seconds_total{mode="idle"}[2m])) * 100))[7d:])