What you need is the increase() function, that will calculate the difference between the counter values at the start and at the end of the specified time interval. It also correctly handles counter resets during that time period (if any).

increase(http_requests_total[24h])

If you have multiple counters http_requests_total (e.g. from multiple instances) and you need to get the cumulative count of requests, use the sum() operator:

sum(increase(http_requests_total[24h]))

See also my answer to that part of the question about using Grafana's time range selection in queries.

Answer from Yoory N. on Stack Overflow
🌐
Prometheus
prometheus.io › docs › prometheus › latest › querying › functions
Query functions | Prometheus
max_over_time(range-vector): the maximum value of all float samples in the specified interval. sum_over_time(range-vector): the sum of all float or histogram samples in the specified interval (see details below).
🌐
Last9
last9.io › blog › how-sum_over_time-works-in-prometheus
sum_over_time in Prometheus: Syntax and Pitfalls | Last9
July 25, 2025 - How sum_over_time() aggregates samples over a range in PromQL, how it differs from increase, avg_over_time, and count_over_time, and how gaps skew results.
Discussions

prometheus - Get Total requests in a period of time - Stack Overflow
But sum(increase(http_requests_total[100y])) will get you the total value over the whole lifetime of the counter and not just the selected time interval 2020-04-17T10:29:13.067Z+00:00 ... Save this answer. ... Show activity on this post. SO won't let me comment on Yoory's answer so I have to make a new one... In Grafana 5.3, they introduced $__range for Prometheus ... More on stackoverflow.com
🌐 stackoverflow.com
PromQL sum_over_time with only positiv values
You can use a subquery (that's the keyword to google for) first to filter out the values (fronius_site_power_grid > 0)[24h:15s] So your query would be: sum_over_time((fronius_site_power_grid > 0)[24h:15s]) More on reddit.com
🌐 r/PrometheusMonitoring
2
2
November 12, 2024
prometheus - PromQL Sum over time - Stack Overflow
If that's the case, then you got values over different dimensions at the same point in time. And from this, you don't know what those values are over 3h period, which you'd like to sum over. If you now do sum(METRIC), you'll get 9. You can punch METRIC[3h] into Prometheus to get those exact ... More on stackoverflow.com
🌐 stackoverflow.com
How to get maximum of a sum over a period of time
| Prometheus | ----> discovers and pulls -----> | metric exporter | <--- REST register metric value, timestamp and a coupe of labels · 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 ... More on github.com
🌐 github.com
3
October 17, 2018
People also ask

What is the difference between sum_over_time() and sum()?
sum() aggregates across different time series at a single point in time. sum_over_time() aggregates across multiple time points for the same time series.
🌐
last9.io
last9.io › blog › how-sum_over_time-works-in-prometheus
sum_over_time in Prometheus: Syntax and Pitfalls | Last9
How does sum_over_time() handle missing data points?
Missing data points are ignored. Prometheus treats data as stale when there is a gap longer than 5x the scrape interval, and those stale points are excluded from the sum.
🌐
last9.io
last9.io › blog › how-sum_over_time-works-in-prometheus
sum_over_time in Prometheus: Syntax and Pitfalls | Last9
When should I use recording rules with sum_over_time()?
Use them when the same heavy sum_over_time() query runs in dashboards or alerts. Recording rules precompute the result and cut response time.
🌐
last9.io
last9.io › blog › how-sum_over_time-works-in-prometheus
sum_over_time in Prometheus: Syntax and Pitfalls | Last9
🌐
Reddit
reddit.com › r/prometheusmonitoring › help with promql query (sum over time)
r/PrometheusMonitoring on Reddit: Help with PromQL query (sum over time)
July 17, 2024 -

Hello,

I have this graph monitoring the bandwidth of a VLAN on a switch every 1m using SNMP Exporter, but I also what to get the total/sum data over time, so if I select the last hour it will show x amount inbound and x amount outbound.

sum by(ifName) (irate(ifHCInOctets{instance=~"192.168.200.10", job="snmp_exporter", ifName=~".*(1001).*"}[1m])) * 8

My current graph:

I'd like to duplicate and create a stat panel show how much data in total has passed over what period I choose that's all.

For the metric I'm not sure whether to use bytes(SI) or bytes(IEC), but are similar if I change to either.

Not sure how to calculate this, but I have this created for the past 1 hour.

by copying the PromQL in Grafana and changing to a stat panel and then editing to use this:

Not sure if this is ok as I'm not sure how to calculate it all, maths was never my best subject.

Any help would be great.

I think something like is close: with sum_over_time

sum by(ifName) (sum_over_time(ifHCInOctets{instance=~"192.168.200.10", job="snmp_exporter", ifName=~".*(1001).*"}[1m])) * 8

but it comes back as 85.8 Pib when it should be 85.8 TB with my calculations.

EDIT

Observium:

What Grafana shows

🌐
OneUptime
oneuptime.com › home › blog › how to calculate cumulative increase in prometheus
How to Calculate Cumulative Increase in Prometheus
December 17, 2025 - # Shows a rolling cumulative increase over time in a graph sum_over_time( sum(increase(http_requests_total[1m]))[1h:1m] ) increase() automatically handles counter resets by detecting when a value drops and assuming it reset from zero. ...
🌐
Promlabs
promlabs.com › promql-cheat-sheet
PromLabs | PromQL Cheat Sheet
Per-second rate of increase, calculated over last two samples in a 1-minute time window: irate(demo_api_request_duration_seconds_count[1m]) Open in PromLens · Absolute increase over last hour: increase(demo_api_request_duration_seconds_count[1h]) Open in PromLens · Sum over all series: sum(node_filesystem_size_bytes) Open in PromLens ·
🌐
Prometheus
prometheus.io › docs › prometheus › latest › querying › examples
Query examples | Prometheus
Return the per-second rate for all time series with the http_requests_total metric name, as measured over the last 5 minutes: ... Assuming that the http_requests_total time series all have the labels job (fanout by job name) and instance (fanout by instance of the job), we might want to sum over the rate of all instances, so we get fewer output time series, but still preserve the job dimension:
Find elsewhere
🌐
Reddit
reddit.com › r/prometheusmonitoring › promql sum_over_time with only positiv values
r/PrometheusMonitoring on Reddit: PromQL sum_over_time with only positiv values
November 12, 2024 -

Hi there, I am using the fronius-exporter to scrape metrics from my PV inverter. One of the interesting metrics is

fronius_site_power_grid, this describes the power in Watt that is consumed or supplied to the grid.

Example:

  • fronius_site_power_grid = 4242W --> buying energy from the grid

  • fronius_site_power_grid = -2424W --> selling energy from the grid

Now I want to sum-up all the energy that was bought or sold in one day. The following PromQL came into my mind:

sum_over_time(fronius_site_power_grid[24h]) *15 / 3600

This should give me the Energy in Wh that was transferred to/from grid.

How can I get a summed-up value for consumed or supplied that is not combined?
With PromQL is tried the following code that was failing:

sum_over_time(clamp_max(last_over_time(fronius_site_power_grid[15s]), 0)[24h]) *15 / 3600

Hint: 15s is my scrape interval

🌐
SigNoz
signoz.io › guides › how to measure total requests with prometheus - a time-based guide
How to Measure Total Requests with Prometheus - A Time-Based Guide | SigNoz
July 25, 2024 - This query returns the number of requests in the last hour. The increase() function calculates the increase in the counter's value over the specified time range. To get the total requests across all instances, use the sum() function:
🌐
Google Groups
groups.google.com › g › prometheus-users › c › V7IbFb-w4ag
Simple increase - sum of the metrics in time range with dynamic metric count
September 22, 2023 - Speaking generally though, given ... the whole window period. This may give a non-integer result). You should then be able to sum() over that: sum(increase(foo[time]))....
🌐
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: curl -kv "http://localhost:9090/api/v1/query_range?query=sum(cell_value) by (pdbID)&start=1539527216&end=$NOW&step=3000" ....
Author: prometheus
🌐
Google Groups
groups.google.com › g › prometheus-developers › c › pul4HF4OS0E
Is it possible to sum a metric by day?
sum_over_time(your_recorded_rule[1y]) to get separate sums over each day (although you probably want to record an · increase(your_series) for that to be of any use). Probably not worth it, though. :o) ... -- You received this message because you are subscribed to a topic in the Google Groups ...
🌐
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 - Prometheus offers several functions that aggregate values across a time range: flowchart LR subgraph "Input: Range Vector" S1[Sample 1: 10] S2[Sample 2: 15] S3[Sample 3: 12] S4[Sample 4: 18] S5[Sample 5: 14] end subgraph "Over Time Functions" AVG["avg_over_time() = 13.8"] MAX["max_over_time() = 18"] MIN["min_over_time() = 10"] SUM["sum_over_time() = 69"] end S1 --> AVG S2 --> AVG S3 --> AVG S4 --> AVG S5 --> AVG
🌐
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 › 8m7tkdB_8sk
Sum over time without instance
to Prometheus Users · First understand what your metric does, and what change in that metric you're looking for. Decide whether it is a counter (it increments for each server restart, resetting to zero only when some collector restarts) or is a gauge (e.g. the number of restarts in a 5 minute period). If it's a counter, sum_over_time() is not what you're looking for.
🌐
Grafana
grafana.com › blog › 2021 › 08 › 19 › how-we-fixed-a-double-counting-prometheus-bug-while-working-on-a-grafana-cloud-project
How we fixed a double-counting Prometheus bug while working on a Grafana Cloud project | Grafana Labs
February 28, 2022 - ... Creating a time series named ... sum_over_time(foo[30s]) with a step of 60 seconds (i.e., every 60 seconds, sum up the sample values in the last 30 seconds)....
🌐
Last9
last9.io › blog › prometheus-functions
Prometheus Functions: How to Make the Most of Your Metrics | Last9
February 28, 2025 - sum_over_time(): Returns the sum of every sample in the range — see how sum_over_time() works for where it differs from increase() Instead of triggering alerts based on a single point-in-time measurement, range vectors let you create alerts ...
🌐
Prometheus
prometheus.io › docs › practices › histograms
Histograms and summaries | Prometheus
In the case of a summary or a classic histogram, you have separate time series for the sum and count of observations, marked by the magic suffixes _sum and _count, respectively. Thus, a summary or classic histogram called http_request_duration_seconds will result in the series http_request_duration_seconds_sum and http_request_duration_seconds_count, and the expression to calculate the average request duration over the last 5m will look like this:
🌐
Better Stack
betterstack.com › community › questions › get-total-requests-in-time-period
Get Total Requests in a Period of Time | Better Stack Community
February 26, 2025 - To calculate the total number of requests over a specified period of time using Prometheus, you can utilize the increase function. This function is ideal for summing up the total count of a counter metric over a given time interval.