Since version 2.7 (Jan 2019), Prometheus supports sub-queries:

max_over_time( sum(node_memory_MemFree_bytes{instance=~"foobar.*"})[1d:1h] )

(metric for the past 2 days, with a resolution of 1 hour.)

Read the documentation for more informations on using recording rules: https://prometheus.io/docs/prometheus/latest/querying/examples/#subquery

However, do note the blog recommendation:

Epilogue

Though subqueries are very convenient to use in place of recording rules, using them unnecessarily has performance implications. Heavy subqueries should eventually be converted to recording rules for efficiency.

It is also not recommended to have subqueries inside a recording rule. Rather create more recording rules if you do need to use subqueries in a recording rule.

The use of recording rules is explained in brian brazil article: https://www.robustperception.io/composing-range-vector-functions-in-promql/

Answer from Franklin Piat 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

prometheus - Promql difference between max and max_over_time - Stack Overflow
I am very new to promql. I want to know, what is the maximum cpu usage in last 7 days using promql for each instace. And figure out under utilized instance, by checking if its maximum cpu usage never More on stackoverflow.com
🌐 stackoverflow.com
Actual timestamp() for max_over_time (and other agg functions)
Proposal Use case. Why is this important? Knowing when a min or max happened in defined window of time is useful. Imagine monitoring a gauge like metric over a week, you want to know the max value ... More on github.com
🌐 github.com
13
December 15, 2018
[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
How to get maximum of a sum over a period of time
I can't use push gateway since I can't discover Prometheus from metric exporter component, so we use pull of the metric from it. I need to sum all the data for certain period of time. More on github.com
🌐 github.com
3
October 17, 2018
🌐
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 - However, the *values* returned will be the maximum value for each timeseries over that 24 hour period. And topk(3, max_over_time(foo[24h]) will then give you the three timeseries which have the highest value of that maximum. > third step would be to get the time of these top3 values calculated earlier. As far as I know, prometheus can't do that for you.
🌐
Last9
last9.io › blog › prometheus-functions
Prometheus Functions: How to Make the Most of Your Metrics | Last9
February 28, 2025 - In these cases, consider using max_over_time or quantile functions: # Alert on any 30-second window with high error rates in the last 5 minutes ... This checks if there was any 30-second window in the last 5 minutes where the error rate exceeded 5%. ... Not sure which Prometheus metric type to use?
🌐
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.

Find elsewhere
🌐
GitHub
github.com › prometheus › docs › issues › 1194
How to get maximum of a sum over a period of time · Issue #1194 · prometheus/docs
October 17, 2018 - E.g. if start=now()-1hour, end=now() and step=900 I would to get 4 values but no miss (e.g. in case the metric was reported in a different time than the step sampled) ... and I want to see the maximum value even if the metrics got reported only once, however the values I see depends on the step:
Author: prometheus
🌐
OneUptime
oneuptime.com › home › blog › how to create prometheus metrics for over time analysis
How to Create Prometheus Metrics for Over Time Analysis
December 17, 2025 - # Pre-compute daily aggregations ...uests_total[5m]))[24h:5m]) Over time analysis in Prometheus transforms point-in-time metrics into historical trends and baselines....
🌐
Promlabs
promlabs.com › promql-cheat-sheet
PromLabs | PromQL Cheat Sheet
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]) ) ) ... See all available xxx_over_time() aggregation functions.
🌐
Google Groups
groups.google.com › g › prometheus-users › c › Evum5I8ARDs
Calculate Max over time on Sum function
July 13, 2017 - So, What sum(max_over_time(node_memory_MemFree[2m])) will do is it will first find maximum from all the nodes. So, the answer will be the sum of all the maximum values of all the nodes, which I don't want. This will give me: ... PS: I have changed the value of node3, because it has maximum values for all the nodes. On Thursday, 13 July 2017 10:57:59 UTC-7, Ben Kochie wrote: You need to use the range vector function first. ... I am running prometheus in my kubernetes cluster.
🌐
Iximiuz
iximiuz.com › en › posts › prometheus-functions-agg-over-time
Prometheus Cheat Sheet - Moving Average, Max, Min, etc (Aggregation Over Time)
July 2, 2021 - Prometheus has a bunch of functions called <smth>_over_time(). They can be applied only to range vectors. It essentially makes them window aggregation functions.
🌐
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
🌐
Prometheus
discuss.prometheus.io › promql
Max_over_time with sum - PromQL - Prometheus Monitoring System
March 15, 2022 - I am using prometheus to manage multiple smart PDU’s with the snmp explorer, I need to track max power usage for different devices connected to these PDU’s. I have a list of PDU’s along with the outlets they are connected to. 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.
🌐
YouTube
youtube.com › watch
Prometheus Query: Calculate Max Over Time on Sum Function Explained - YouTube
In this video, we dive into the powerful capabilities of Prometheus, focusing on how to calculate the maximum value over time using the sum function. Whether...
Published: August 6, 2025
🌐
Reddit
reddit.com › r/prometheusmonitoring › min, max, avg, and stddev of values in between scrape interval
r/PrometheusMonitoring on Reddit: Min, max, avg, and stddev of values in between scrape interval
April 22, 2023 -

Prometheus seems to hide metrics that happen between the scrape interval, and I can't find anyone who looked into this. Statsd has a type called "Timing" which is like a gauge, but also stores min, max, avg, and stddev of all values submitted to it, aggregated by time interval. This is useful when you want to measure latency of some process that happens faster than the scrape interval. They also get computed correctly when you plot them on graphs and zoom out, showing fewer points.

This also brings up the question about existing metrics like CPU and Memory usage. If the scrape interval is 30 seconds, is the CPU usage metric (say from k8s node exporter) the value sampled at that time only (so last), is it the average of CPU usage from the last scrape window, or something else? (I know that in this example the metric `node_cpu_seconds_total` is a counter, and from the start has no statistical data attached to it)

For some metrics, like CPU usage, looking at an average can be very misleading, as the data tends to be very spiky. This already happens when zooming out in Grafana. For these metrics when aggregating time intervals you almost always want to use max all the time. `max_over_time()` is incompatible with `rate()`.

The result is that zooming out in Grafana shows basically lies, as showing averages make it seem like everything is fine.

Top answer
1 of 2
5
I think you may be misunderstanding of how Prometheus is designed. It doesn't "hide" values between the scrape interval. It never records them in the first place. The node_cpu_seconds_total metric is a counter. It records the amount of "busy" time for the CPU since the counter last reset, which happens when the node_exporter restarts or if the counter rolls over at the maximum possible value. You can use that metric with rate() or irate() to approximate a "percentage" CPU usage across the scrape interval. Here's an old blog post about it . If an average across 30 seconds isn't sufficient for your use case then you can decrease the scrape interval (possibly only for CPU metrics, by creating a separate job definition) or consider some different tooling. Information on using Prometheus to monitor basic system metrics is quite abundant at this point so I'd highly recommend looking around for some guides or documentation. Googling for "node_cpu_seconds_total" will have turned up both that blog post and the official documentation, which includes a note about how to use that metric .
2 of 2
3
For these metrics when aggregating time intervals you almost always want to use max all the time. max_over_time() is incompatible with rate(). No, you don't always want max_over_time(), this is just misleading in a different way. What I typically do for this is have a recording rule to generate the rate() data. Then I will have a Grafana graph with multiple queries. avg_over_time(instance:node_cpu_utilization:ratio{instance="$instance"}[$__interval]) min_over_time(instance:node_cpu_utilization:ratio{instance="$instance"}[$__interval]) max_over_time(instance:node_cpu_utilization:ratio{instance="$instance"}[$__interval]) This way you can see the spread of utilization within this window. As you zoom in, the lines converge since you're close to the raw data. As you zoom out, you get a good idea on where the min/max are. This is possible to do without the recording rules, using subquery syntax , but is of course more expensive to compute on the fly.
🌐
Medium
medium.com › @suchitasharma1106 › a-comprehensive-guide-to-grouping-and-functions-in-promql-cc3c438be320
A Comprehensive Guide to Grouping and Functions in PromQL | by Suchita Sharma | Medium
October 7, 2024 - This query returns the maximum CPU usage in the last 10 minutes. quantile_over_time(): Calculates a specific quantile (e.g., 95th percentile) over the window.
🌐
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 ...