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:])
Answer from markalex on Stack Overflow
🌐
Prometheus
prometheus.io › docs › prometheus › latest › querying › functions
Query functions | Prometheus
min_over_time(range-vector): the minimum value of all float samples in the specified interval. max_over_time(range-vector): the maximum value of all float samples in the specified interval.
Discussions

[Question] Two different values for the same day when calculating max_over_time over two different time ranges
Try adding : and your scrape interval after your range i.e., [5d:15s] to evaluate every point. More on reddit.com
🌐 r/PrometheusMonitoring
1
2
August 25, 2023
kubernetes - Calculate Max over time on sum function in Prometheus - Stack Overflow
I am running prometheus in my kubernetes cluster. I have the following system in kubernetes: I have 4 nodes. I want to calculate free memory. I want to have the summation of those four nodes. Then I More on stackoverflow.com
🌐 stackoverflow.com
prometheus - How to use rate to handle max_over_time - Stack Overflow
Then I want to use rate to handle result of max_over_time, e.g. More on stackoverflow.com
🌐 stackoverflow.com
How to make a max_over_time([30d]) over a avg_over_time([1min])
You can use a subquery to do this: https://prometheus.io/blog/2019/01/28/subquery-support/ More on reddit.com
🌐 r/grafana
4
3
May 20, 2024
🌐
Grafana
community.grafana.com › prometheus
Max_over_time not showing actual maximum - Prometheus - Grafana Labs Community Forums
July 16, 2025 - I’m trying to get the max container memory usage as a percentage value over a time range, and I’m quite close, but my current query seems to fall short. As can be seen in the image below I’m getting two time series for memory usage by ntfy, and a single max value as a result.
🌐
Google Groups
groups.google.com › g › prometheus-users › c › gAMhzzp0Cb0
max_over_time not working as expected - want to get the 3 most recent values higher than a specific threshold
August 28, 2024 - If you see multiple values of 22, then they are for separate timeseries, and each will be identified by its unique sets of labels. That's what max_over_time does: it works on a range vector of timeseries, and gives you the *single* maximum for *each* timeseries.
🌐
Promlabs
promlabs.com › promql-cheat-sheet
PromLabs | PromQL Cheat Sheet
avg_over_time(go_goroutines[5m]) Open in PromLens · Get the maximum for each series over a one-day period: max_over_time(process_resident_memory_bytes[1d]) Open in PromLens · Count the number of samples for each series over a 5-minute period: count_over_time(process_resident_memory_bytes[5m]) Open in PromLens ·
🌐
Reddit
reddit.com › r/prometheusmonitoring › [question] two different values for the same day when calculating max_over_time over two different time ranges
r/PrometheusMonitoring on Reddit: [Question] Two different values for the same day when calculating max_over_time over two different time ranges
August 25, 2023 -

I am tracking the number of jobs in a queue at specific time intervals using a gauge metric. Prometheus scrapes this every minute.

However, when I attempt to determine the highest number of jobs in the queue on a given day using the max_over_time query, I receive two distinct values for the same day based on different time ranges.

I am using the query max_over_time(job_count_by_service{service="ServiceA", tenant="TenantA"}[1d]). When I run this query for a 1-day time range (from 2023-08-19 00:00:00 to 2023-08-19 23:59:59), the value I get is 38. However, when I run the same query for a 5-day time range (from 2023-08-18 00:00:00 to 2023-08-22 23:59:59), the result for Aug 19th is 35.

https://i.stack.imgur.com/RSxCO.png https://i.stack.imgur.com/gmW3m.png

In Grafana I have configured the Min Step as 1d and Type as Range. I'm not sure whether that could affect the values in any way.

I assumed that max_over_time would pick the max value among all the values that fall in the range vector specified time period. For example, if on Day 1 the values are [1,2,7,6,5] and on Day 2 the values are [8,1,2,3,1] then the query would return 7 & 8 respectively for each day.

🌐
Google Groups
groups.google.com › g › prometheus-users › c › Evum5I8ARDs
Calculate Max over time on Sum function
July 13, 2017 - I want to do the sum of all the nodes first at a particular time. So, Sum of time t1, Sum of time t2, Sum of time t3, Sum of time t3. And then, I want to find the maximum among them. So, What sum(max_over_time(node_memory_MemFree[2m])) will do is it will first find maximum from all the nodes.
Find elsewhere
🌐
Google Groups
groups.google.com › g › prometheus-users › c › 6cxqUGoxZ-Q
max_over_time - start of month
Another option is to use the @ modifier to specify the exact execution time of the query, giving the end of the month as the timestamp. This is now available by default in recent versions of prometheus (v.2.33.0+), but before that it was hidden behind a feature flag. max_over_time(rack_max_power_watts{job="Max power on path /racks/max-power"}[4w] @ 1667260800) # up to midnight on Nov 1st
🌐
Last9
last9.io › blog › prometheus-functions
Prometheus Functions: How to Make the Most of Your Metrics | Last9
February 28, 2025 - Range vectors become particularly ... Calculates the increase in the counter value · max_over_time(): Returns the maximum value over the specified time range...
🌐
Reddit
reddit.com › r/grafana › how to make a max_over_time([30d]) over a avg_over_time([1min])
r/grafana on Reddit: How to make a max_over_time([30d]) over a avg_over_time([1min])
May 20, 2024 -

Hello everyone I would like to get in a graph the maximum of a moving average, But simply nesting the two functions inside each other doesn't work.

max_over_time(avg_over_time(meter_amp{instance=~"$group_id-.*"}[1m])[30d])

Error Msg: : 1:89: parse error: ranges only allowed for vector selectors

Is there another solution for this?

🌐
GitHub
github.com › prometheus › prometheus › discussions › 10929
max_over_time(sum · prometheus/prometheus · Discussion #10929
max_over_time(sum(pdu_inlet_sensor_value{instance=~"10.241.137.132|10.241.137.134|10.241.137.135|10.241.137.137",sensorType="apparentPower"})[15d])
Author: prometheus
🌐
Prometheus
discuss.prometheus.io › promql
Max_over_time with sum - PromQL - Prometheus Monitoring System
March 15, 2022 - When I run my query i would like to sum/combine up the outlets used for a specific device then take the max power over a period of time. I can get the sum/combine working and the max_over_time on a entire pdu but when i try to use them together they fail. This is through h...
🌐
Cairry
cairry.github.io › docs › Prometheus › promql.html
PromQL 常用的内置函数 | WatchAlert
http_request_duration_seconds{instance="server1"} 1.2 (timestamp: 1626568200) http_request_duration_seconds{instance="server1"} 2.5 (timestamp: 1626568300) http_request_duration_seconds{instance="server1"} 0.8 (timestamp: 1626568400) http_request_duration_seconds{instance="server1"} 4.2 (timestamp: 1626568500) 计算过去5分钟内的最大响应时间 · max_over_time(http_request_duration_seconds{instance="server1"}[5m]) 使用场景 ·
🌐
Prometheus
prometheus.io › docs › prometheus › latest › querying › examples
Query examples | Prometheus
Using regular expressions, you could select time series only for jobs whose name match a certain pattern, in this case, all jobs that end with server: ... Return the 5-minute rate of the http_requests_total metric for the past 30 minutes, with a resolution of 1 minute. ... This is an example of a nested subquery. The subquery for the deriv function uses the default resolution. Note that using subqueries unnecessarily is unwise. max_over_time(deriv(rate(distance_covered_total[5s])[30s:5s])[10m:])
🌐
Grafana
community.grafana.com › prometheus
How do I get max_over_time to work without skipping data points? - Prometheus - Grafana Labs Community Forums
August 29, 2024 - I want to use max_over_time to find spikes in a gauge metric that measures cpu usage. However, when I execute the promQL query in my dashboard, some data is missing. I also have a graph displaying these spikes, but the main problem with this graph is, that it smoothes away the spikes I am looking ...
🌐
VictoriaMetrics
victoriametrics.com › blog › prometheus monitoring: functions, subqueries, operators, and modifiers
Prometheus Monitoring: Functions, Subqueries, Operators, and Modifiers
April 25, 2025 - Every 30 seconds, rate(http_re... ... Then every 1 minute, max_over_time(...) collects those rate values and finds the maximum value within the last 1-minute window....