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
🌐
Google Groups
groups.google.com › g › prometheus-developers › c › pul4HF4OS0E
Is it possible to sum a metric by day?
day_of_month label to your metric. You can use the same approach to add ... sum_over_time(your_recorded_rule[1y]) to get separate sums over each day (although you probably want to record an
🌐
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

Discussions

prometheus - Get Total requests in a period of time - Stack Overflow
I need to show, in Grafana, a panel with the number of requests in the period of time selected in the upper right corner. For this I need to solve 2 issues here, I will ask the prometheus question... More on stackoverflow.com
🌐 stackoverflow.com
Possible to sum counter increase within range of hours, every day? - PromQL - Prometheus Monitoring System
Been around the internets, tried a thousand things, suspect it isn’t possible (or I’m out of my depth here), so last ditch is to seek out guidance on the forum… Basically we have a counter that tracks successful job runs. What I am trying to do is sum(increase(... within a 4h window every ... More on discuss.prometheus.io
🌐 discuss.prometheus.io
0
April 13, 2023
promql - Which prometheus querying function must be used to get values per day from total? - Stack Overflow
We have several different metrics which show bytes total (which is a counter) for all sorts of "cars" and their "types". For example bytes_total_incoming{"car_name": &... More on stackoverflow.com
🌐 stackoverflow.com
Sum of a Prometheus metric over the current day - Stack Overflow
I want to have a metric that shows the total incoming bytes on an interface for the day so far. The closest I can get is having to specify the date in the query, but I was hoping to have something ... More on stackoverflow.com
🌐 stackoverflow.com
🌐
Promlabs
promlabs.com › promql-cheat-sheet
PromLabs | PromQL Cheat Sheet
Go get our self-paced in-depth PromQL training! Select latest sample for series with a given metric name: ... 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]) ) )
🌐
Prometheus
prometheus.io › docs › prometheus › latest › querying › functions
Query functions | Prometheus
It is syntactic sugar for rate(v) multiplied by the number of seconds under the specified time range window, and should be used primarily for human readability. Use rate in recording rules so that increases are tracked consistently on a per-second basis. The info function is an experiment to improve UX around including labels from info metrics . The behavior of this function may change in future versions of Prometheus, including its removal from PromQL.
🌐
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 - Use the increase() function in PromQL to calculate the total requests over a specific time range: ... This query returns the number of requests in the last hour. The increase() function calculates the increase in the counter's value over the ...
🌐
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 - In PromQL, you can use functions like avg_over_time and sum_over_time for this purpose. sum_over_time(): Returns the total value over a specified interval, which is useful for aggregating metrics like total bytes ...
🌐
Sysrant
sysrant.com › posts › monthly-reports-with-grafana-and-prometheus
Monthly reports with Grafana and Prometheus | Sysrant
July 16, 2021 - 1up{job="prometheus"} + ignoring(year, month, day) group_right 2 count_values without() ("year", year(timestamp( 3 count_values without() ("month", month(timestamp( 4 count_values without() ("day", day_of_month(timestamp( 5 up{job="prometheus"} 6 ))) 7 ))) 8 ))) * 0 · Also there is a really good blogpost (https://www.robustperception.io/monthly-reporting-with-prometheus-and-python), and I'll quote them right now: While PromQL has some calendar functions, it's designed more for doing math over arbitrary fixed time periods rather than time periods that vary over time due to business logic.
Find elsewhere
🌐
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 - In VictoriaMetrics you can use the following MetricsQL query for bulilding summary increase graph over multiple time series of counter type, which starts from zero on the left side: ... Note that you don't need specifying lookbehind window in square brackets at increase(...), since VictoriaMetrics automatically sets it to the interval between points shown on the graph (aka step query arg automatically passed by Grafana to /api/v1/query_range - see https://prometheus.io/docs/prometheus/latest/querying/api/#range-queries ).
🌐
Prometheus
discuss.prometheus.io › promql
Possible to sum counter increase within range of hours, every day? - PromQL - Prometheus Monitoring System
April 13, 2023 - Been around the internets, tried a thousand things, suspect it isn’t possible (or I’m out of my depth here), so last ditch is to seek out guidance on the forum… Basically we have a counter that tracks successful job runs. What I am trying to do is sum(increase(... within a 4h window every day over say, a 30d period.
Top answer
1 of 1
4

You need to use increase() function for calculating bytes usage over the last 24 hours:

increase(bytes_total_incoming[24h])

This query is executed independently per each point on the graph and per each matching time series. So every point on the graph shows bytes usage for the last 24 hours ending at that point. If you need showing per-day bytes usage on the graph, then the following options exist:

  • To set min interval in Grafana graph panel settings to 24h. See these docs. In this case Grafana would query only a single point per day per each matching time series. Every point will show bytes usage over the previous day ending at the point.
  • To use subquery feature in Prometheus in order to limit increase() calculations to per-day boundaries:
last_over_time(
  increase(bytes_total_incoming[1d])[2d:1d]
)

This query returns a graph with per-day steps showing bytes usage over the previois day.

If you need grouping the results by a paricular label such as car_name or type, then just wrap the query into sum(...) by (car_name) or sum(...) by (type). For example, the following query returns per-day bytes usage grouped by type:

sum(
  increase(bytes_total_incoming[24h])
) by (type)

Tye sum() is an aggregate function, which sums series values individually per each point and groups the reaulting sums by label values specified in the optional by (...) modifier.

P.s. the above queries return per-day bytes usage shifted by one day in the future. For example, they return bytes usage for August 10 at August 11. This shift can be removed with negative offset modifier:

sum(
  increase(bytes_total_incoming[24h] offset -24h)
)

P.p.s. increase() function in Prometheus may return fractional results when applied to integer counters. This is because of extrapolation - see this issue. If you want obtaining the exact increase over integer counter, then try the project I work on - VictoriaMetrics. It implements increase() function in the expected way without using extrapolation. See this article for details.

Top answer
1 of 2
1

Prometheus doesn't provide the ability to query counter increase for the current day (e.g. since 00:00 of the current day). Prometheus provides the ability to query counter increase over the fixed lookbehind window (aka sliding window) though. For example, the following query returns the counter increase over the last 24 hours:

increase(ifen02[24h])

If you need counter increase since the beginning of the current day, then the following MetricsQL query can be used:

running_sum(
  increase(ifen02)
  if (
    time()+timezone_offset("Europe/Kiev")
    > (now() - now() % (24*3600))
  )
)

It is expected that this query is used for building a graph on a time range covering the current day.

This query works in the following way:

  1. It calculates the increase() for ifen02 between adjacent points on the graph. VictoriaMetrics automatically converts increase(ifen02) into the equivalent of increase(ifen02[$__interval])). See increase docs and implicit query conversion docs.

  2. Then it calculates time()+timezone_offset("Europe/Kiev") > (now() - now() % (24*3600)) . This query returns unix timestamps in Europe/Kiev time zone for the current day. It drops all the timestamp for the previous days. See docs for the used functions: now(), timezone_offset() and time().

  3. Then the if operator leaves the calculated increase() values only for the current day starting at 00:00 Europe/Kiev timezone, while dropping all the values for previous days. See docs about if operator here.

  4. Then the remaining increase() values are summed over the current day with running_sum function. Sometimes it is possible to use range_sum instead of running_sum.

2 of 2
0

Why don't you simply use this?

sum(increase(ifen02[2h]))

And from the visualization tools (i.e. Grafana or Prometheus graph) select last 1 day or last 24 hr, it will show the data of last 1 day relative to current time.

🌐
Last9
last9.io › blog › promql-cheat-sheet
PromQL Cheat Sheet: Queries, Functions, and Labels | Last9
September 12, 2024 - PromQL offers several specialized aggregation functions to help you analyze and summarize your time series data efficiently.
🌐
Prometheus
discuss.prometheus.io › promql
PromQL sum from beginning of month - i.e traffic consumer during billing period - PromQL - Prometheus Monitoring System
January 23, 2022 - Hello! I’ve set up a free vps, and have prometheus + node exporter on it, so I can have panel that shows node_network_transmit_bytes_total What I want is to be able to check that server hasn’t consumed more than 5Tb of traffic during any particular month.
🌐
OneUptime
oneuptime.com › home › blog › how to calculate cumulative increase in prometheus
How to Calculate Cumulative Increase in Prometheus
December 17, 2025 - # Total requests in the last 24 hours sum(increase(http_requests_total[24h])) # Requests per day for each service sum by (service) (increase(http_requests_total[24h]))
🌐
Last9
last9.io › blog › how-sum_over_time-works-in-prometheus
sum_over_time in Prometheus: Syntax and Pitfalls | Last9
July 25, 2025 - 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().
🌐
VictoriaMetrics
docs.victoriametrics.com › metricsql
VictoriaMetrics: MetricsQL
This function is supported by PromQL. See also stddev_over_time . sum_eq_over_time(series_selector[d], eq) is a rollup function , which calculates the sum of raw sample values equal to eq on the given lookbehind window d per each time series returned from the given series_selector .
🌐
Chronosphere
chronosphere.io › home › top 3 queries to add to your promql cheat sheet
Top 3 queries to add to your PromQL cheat sheet
April 2, 2025 - If you have 1000 counter series with the metric name “api_requests_total” that partition your API requests by various label dimensions, you will now get 1000 output rates — one for each input series. The label dimensions that partition the metric name into many time series can be aspects like: ... This level of dimensional insight in Prometheus is great, but you will often want to show an overall request rate for your service, with some dimensions aggregated away. This is where the sum() aggregator comes in: It sums the values of many time series into fewer series, but still preserves the dimensions that you want to see in the result.
🌐
Iximiuz
iximiuz.com › en › posts › prometheus-functions-agg-over-time
Prometheus Cheat Sheet - Moving Average, Max, Min, etc (Aggregation Over Time)
July 2, 2021 - What only matters for PromQL is an expression type. I.e., it wouldn't allow you to call a function that expects an instant vector with a range vector argument. However, a range vector of gauges is physically indistinguishable from a range vector of counters. And here we go... functions min_over_time(), max_over_time(), avg_over_time(), sum_over_time(), stddev_over_time(), and stdvar_over_time() makes sense to use only with gauge metrics.