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
🌐
Last9
last9.io › blog › how-sum_over_time-works-in-prometheus
sum_over_time in Prometheus: Syntax and Pitfalls | Last9
July 25, 2025 - The more unique label combinations you query over, the harder Prometheus has to work. ... Stick to group by labels with fewer unique values (like service, region, or env) when possible. Avoid using user identifiers, IPs, or request-level labels unless absolutely necessary. ... Prometheus doesn’t stream values—it loads the entire time range into memory before computing sum_over_time().
Discussions

Help with PromQL query (sum over time)
For a stat panel, you want to use increase() to compute the value. sum by (ifName) ( increase( ifHCInOctets{ instance="192.168.200.10", job="snmp_exporter", ifName=~".*(1001).*" }[$__range] ) ) * 8 Make sure to click the query options and change it from "Range" to "Instant". This will provde an efficient single computation of the value for the panel. Although you won't get the spark line. (but really, if you want a spark line, use a graph) For the graph query, I also recommend against using irate(). It leads to misleading results. Use this query instead: sum by (ifName) ( increase( rate{ instance="192.168.200.10", job="snmp_exporter", ifName=~".*(1001).*" }[$__rate_interval] ) ) * 8 This will give you accurate graphs as you in and zoom out over time. Make sure you set the query option "min step" to match your scrape interval (1m). More on reddit.com
🌐 r/PrometheusMonitoring
9
1
July 17, 2024
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 "count the value above x and make sum over time"?
Hi, I’m using Grafana with Prometheus to monitor some smart outlets (like the microwave or TV) with watt consumption, but I also want to monitor the time that they are ON. But they’re “on” also when they are in standby, because they drain few watts but for the metrics, 0 off, 1 on. More on community.grafana.com
🌐 community.grafana.com
2
0
November 24, 2022
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
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
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
🌐
Prometheus
prometheus.io › docs › prometheus › latest › querying › functions
Query functions | Prometheus
The following example expression returns the per-second rate of HTTP requests looking up to 5 minutes back for the two most recent data points, per time series in the range vector: ... irate should only be used when graphing volatile, fast-moving counters. Use rate for alerts and slow-moving counters, as brief changes in the rate can reset the FOR clause and graphs consisting entirely of rare spikes are hard to read. Note that when combining irate() with an aggregation operator (e.g. sum()) or a function aggregating over time (any function ending in _over_time), always take an irate() first, then aggregate.
🌐
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

🌐
Prometheus
prometheus.io › docs › prometheus › latest › querying › examples
Query examples | Prometheus
topk(3, sum by (app, proc) (rate(instance_cpu_time_ns[5m]))) Assuming this metric contains one time series per running instance, you could count the number of running instances per application like this: ... If we are exploring some metrics for their labels, to e.g. be able to aggregate over ...
🌐
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. ...
Find elsewhere
🌐
Promlabs
promlabs.com › promql-cheat-sheet
PromLabs | PromQL Cheat Sheet
Per-second rate of increase, calculated ...i_request_duration_seconds_count[1h]) Open in PromLens · Sum over all series: sum(node_filesystem_size_bytes) Open in PromLens ·...
🌐
GitHub
github.com › prometheus › prometheus › blob › main › docs › querying › examples.md
prometheus/docs/querying/examples.md at main · prometheus/prometheus
topk(3, sum by (app, proc) (rate(instance_cpu_time_ns[5m]))) Assuming this metric contains one time series per running instance, you could count the number of running instances per application like this: ... If we are exploring some metrics ...
Author: prometheus
🌐
Chris's Wiki
utcc.utoronto.ca › ~cks › space › blog › sysadmin › PrometheusCountUsageOverTime
Calculating usage over time in Prometheus (and Grafana)
December 2, 2019 - sum_over_time( (sum(vpn_user_sessions) by (user) > bool 0)[$__range:1m] ) / ($__range_s / 60)
🌐
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

🌐
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 ... 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. Every such function takes in a range vector and produces an instant vector with elements being per-series aggregations. For people like me who normally grasp code faster than text, here is some pseudocode of the aggregation logic: # Input vector example.
🌐
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]))....
🌐
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:
🌐
Grafana
community.grafana.com › dashboards
How to "count the value above x and make sum over time"? - Dashboards - Grafana Labs Community Forums
November 24, 2022 - Hi, I’m using Grafana with Prometheus to monitor some smart outlets (like the microwave or TV) with watt consumption, but I also want to monitor the time that they are ON. But they’re “on” also when they are in standby, because they drain few watts but for the metrics, 0 off, 1 on.
🌐
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 ...
🌐
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 foo with the sample values [5, 10, 15, 20, 25] at 30-second intervals. Running the PromQL query sum_over_time(foo[30s]) with a step of 60 seconds (i.e., every 60 seconds, sum up the sample values in the last ...
🌐
Google Groups
groups.google.com › g › prometheus-users › c › 8m7tkdB_8sk
Sum over time without instance
The same number is coming from different pods in the cluster. Prometheus nicely shows that separately but I can't "without" it. Somehow I have to collapse the two different metrics into one. So now there are two rows: | time | id | endpoint | instance | pod | service | metric | value |
🌐
SigNoz
signoz.io › guides › how to query data by time period - a step-by-step guide
How to Query Data by Time Period - A Step-by-Step Guide | SigNoz
November 20, 2024 - Here's an example of a Prometheus query in Grafana that visualizes HTTP request trends on an API server over time: ... Time Range Filter: [5m] — Limits data to the last five minutes, creating a moving window for real-time trends.