My question is this how rate will get calculated(my understanding is correct)?

Theoretically, it is correct (except in your example you have 6 datapoints, not 5). But the "magic" starts happening when you add start and end params to your query. In most cases, these two params will not exactly match t1 and t5 from your example, and Prometheus won't be able to capture one or more data points of yours:

In the example above, time window isn't perfectly aligned with real values. In this case, value of v1 will be missed, which would affect the result since increase will be calculated between v5 and v2. Knowing the avg interval between received values, Prometheus could assume that it didn't capture some of the values. So it will try to extrapolate the result by simply multiplying it by coefficient.

I'd recommend reading this great thread https://github.com/prometheus/prometheus/issues/3746.

I'd also recommend reading how alternative rate could work here https://medium.com/@romanhavronenko/victoriametrics-promql-compliance-d4318203f51e in "Better rate" section. Disclosure, I am one of the developers at VictoriaMetrics, so take it with a grain of salt.

Answer from hagen1778 on Stack Overflow
🌐
Prometheus
prometheus.io › docs › prometheus › latest › querying › functions
Query functions | Prometheus
Breaks in monotonicity (such as counter resets due to target restarts) are automatically adjusted for. The increase is extrapolated to cover the full time range as specified in the range vector selector, so that it is possible to get a non-integer result even if a counter increases only by ...
Discussions

Prometheus Counters - and how to deal with them
Very nice article. As you can see above, the result Prometheus returns is more exact than the one that we came up with, but it’s still not the right value (we know because of the controlled environment we set up). One thing I'd like to point out is the Prometheus extrapolation is more accurate overall, especially when aggregating things that move at a high rate. The trick is, if you're using sum() to add up rate()/increase() for several endpoints, you need the interpolated values to produce the most accurate total. Say you have these samples from a job of 3 targets with a scrape interval of 15 seconds. foo{i="A"} 0 @0.1 foo{i="B"} 0 @5.6 foo{i="C"} 0 @12.8 foo{i="A"} 5 @15.1 foo{i="B"} 2 @20.6 foo{i="C"} 14 @27.8 If you query at T=30 with an sum(increase(foo[30s])), interpolation is needed to align all the timestamps and values. It's important because Prometheus tracks data with float64 values, timestamps in milliseconds. The millisecond you submit a query is actually important as part of the calculation if you're using the default /graph interface. If you're using Grafana, they snap the timestamps based on the graph window range and the step interval configured. This is how Grafana avoids graph jitter when refreshing. Everything is aligned to 15 seconds. This would be more easily visualized with a picture, probably something useful to add to your article. EDIT: Another fun fact, you can change the ordering of by/without. It makes it nice when you want to break up a long query shorten the line length. For example: sum by (country) ( increase(orders_created_total[5m]) ) More on reddit.com
🌐 r/PrometheusMonitoring
2
7
May 20, 2019
grafana - Rate and increase extrapolation in prometheus when service is redeploying - Stack Overflow
I have counter for successful orders. But when my service is redeploying, the rate drops for some period, while the increase does not change the trend. Please, Help me figure out why this might be More on stackoverflow.com
🌐 stackoverflow.com
increase() in Prometheus sometimes doubles values: how to avoid? - Stack Overflow
That's an increase of 1 over 2 minutes, which extrapolated over 4 minutes is an increase of 2 - which is as expected. Any metrics-based monitoring system will have similar artifacts, if you want 100% accuracy you need logs. ... Sign up to request clarification or add additional context in comments. ... This statement "Any metrics-based monitoring system will have similar artifacts, if you want 100% accuracy you need logs." Is factually incorrect, not only is this unique to Prometheus ... More on stackoverflow.com
🌐 stackoverflow.com
PromQL(histograms): Prevent extrapolation below zero
tl;dr: We should prevent extrapolation below zero in rate and increase calculations, in a similar way as for simple float counters. TODOs are in the code and in the spec. By not doing it, we someti... More on github.com
🌐 github.com
11
February 5, 2025
🌐
GitHub
github.com › prometheus › prometheus › issues › 3746
rate()/increase() extrapolation considered harmful · Issue #3746 · prometheus/prometheus
January 26, 2018 - Second, there is another workaround that only works for increase(foo[10s]), namely using foo - foo offset 10s. But there are a couple of problems with this approach: it doesn't handle counter resets and it's twice as slow because now Prometheus looks up foo twice.
Author: prometheus
🌐
DoiT
doit.com › home › blog › making peace with prometheus rate()
Making peace with Prometheus rate() | DoiT
February 17, 2023 - So basically Prometheus understands that the actual range in each bucket is one scrape less, i.e. 45 seconds instead of 60 in our case, so when it sees metric changed by 1 in a bucket, it’s actually “by 1 in 45 seconds”, not “by 1 in 60 seconds”, so it extrapolates the result as 1 / 45 * 60 = 1.33 and this is how we end up with increase() values being larger than the actual change.
🌐
Google Groups
groups.google.com › g › prometheus-users › c › qmutsg1c55g
Increase without extrapolation
We were able to prove this by manipulating the data to make sure the time range boundary was far enough away from the first and last sample to prevent the extrapolation code from running. So we are considering options to export the data from Prometheus and replicate the increase function but without the extrapolation.
🌐
Reddit
reddit.com › r/prometheusmonitoring › prometheus counters - and how to deal with them
r/PrometheusMonitoring on Reddit: Prometheus Counters - and how to deal with them
May 20, 2019 - If you query at T=30 with an sum(increase(foo[30s])), interpolation is needed to align all the timestamps and values. It's important because Prometheus tracks data with float64 values, timestamps in milliseconds.
🌐
Promlabs
promlabs.com › blog › 2021 › 01 › 29 › how-exactly-does-promql-calculate-rates
PromLabs | Blog - How Exactly Does PromQL Calculate Rates?
January 29, 2021 - Thus increase() (and also rate()) extrapolate the slope between those first and last data points under the window to the window boundaries, to arrive at a value that will on average be closer to the expected increase over the entire window (had there actually been samples precisely at the window boundaries).
🌐
MetricFire
metricfire.com › blog › understanding-the-prometheus-rate-function
How the Prometheus rate() function works | MetricFire
March 12, 2026 - In such a case, rate() calculates the rate with the data it has and then, if any information is missing, extrapolates the beginning or the end of the selected window using either the first or the last two data points.
Find elsewhere
🌐
Google Groups
groups.google.com › g › prometheus-users › c › _aK7im7elUs
Why does increase() return fractional results for integer-valued metrics?
Prometheus extrapolates `increase()` results - see https://github.com/prometheus/prometheus/issues/3746 for more details.
🌐
Stack Overflow
stackoverflow.com › questions › 79352883 › rate-and-increase-extrapolation-in-prometheus-when-service-is-redeploying
grafana - Rate and increase extrapolation in prometheus when service is redeploying - Stack Overflow
I have counter for successful orders. But when my service is redeploying, the rate drops for some period, while the increase does not change the trend. Please, Help me figure out why this might be
Top answer
1 of 3
44

This is known as aliasing and is a fundamental problem in signal processing. You can improve this a bit by increasing your sample rate, a 4m range is a bit short with a 2m range. Try a 10m range.

Here for example the query executed at 1515722220 only sees the [email protected] and [email protected] samples. That's an increase of 1 over 2 minutes, which extrapolated over 4 minutes is an increase of 2 - which is as expected.

Any metrics-based monitoring system will have similar artifacts, if you want 100% accuracy you need logs.

2 of 3
21

increase() will always (approximately) double the actual increase with your setup.

The reason is that (as currently implemented):

  1. increase() is (as you observed) syntactic sugar for rate() i.e. it is the value that would be returned by rate() multiplied by the number of seconds in the range you specified. In your case, it is rate() * 240.
  2. rate() uses extrapolation in its computation. In the vast majority of cases a 4 minute range will return exactly 2 data points, almost exactly 2 minutes apart. The rate is then computed as the difference between last and first (i.e. the 2 points in your case) divided by the time difference of the 2 points (around 120 seconds in 99.99% of cases) multiplied by the range you requested (exactly 240 seconds). So if the increase between the 2 points is zero, the rate is zero. If the increase between the 2 points is 1.0, the computed rate() will be close to 2.0 / 240 and, as a result, the increase() will be 2.0.

This approach works mostly fine with counters that increase smoothly (e.g. if you have a more or less fixed number of signups every 2 minutes). But with a counter that rarely increases (as does your signups counter) or a spiky counter (like CPU usage) you get weird overestimates (like the increase of 2 you are seeing).

You can essentially reverse engineer Prometheus' implementation and get (something very close to) the actual increase by multiplying with (requested_range - scrape interval) and dividing by requested_range, essentially walking back the extrapolation that Prometheus does.

In your case, this would mean

increase(signups_count[4m]) * (240 - 120) / 240

or, more succinctly,

increase(signups_count[4m]) / 2

It requires you to be aware both of the length of the range and the scrape interval, but it will give you what you want: "ones for ones, and twos for twos, most of the time". Sometimes you'll get 1.01 instead of 1.0 because the scrapes were 119 seconds, not 120 seconds apart and sometimes, if your evaluation is closely aligned with the scrape some points right on the boundary might be included or not in a data point calculation, but it's still a better answer than 2.0.

🌐
GitHub
github.com › prometheus › prometheus › pull › 1254 › files
Rate extrapolation mode "median/half". by beorn7 · Pull Request #1254 · prometheus/prometheus
@brian-brazil @fabxc Not to merge right now, just for you to experiment. This combines both ideas, i.e. using median (not average) and extrapolate to half the median at the assumed start/end of a series.
Author: prometheus
🌐
Consol Labs
labs.consol.de › monitoring › 2016 › 08 › 13 › counting-errors-with-prometheus.html
Counting Errors with Prometheus - ConSol Labs
August 13, 2016 - Prometheus interprets this data as follows: Within 30 seconds (between 15s and 45s), the value increased by one (from three to four). Prometheus extrapolates that within the 60s interval, the value increased by 2 in average.
🌐
Blog
asserts.ai › home › the benefits of prometheus counters
The Benefits of Prometheus Counters - Asserts
April 18, 2026 - Prometheus’s rate() function automatically handles it by extrapolation.
🌐
Tigera
tigera.io › home › prometheus monitoring › prometheus metrics
Prometheus Metrics: A Practical Guide | Tigera – Creator of Calico
July 30, 2021 - The functions in Prometheus are similar to typical programming functions, except they are restricted to a predefined set. Most Prometheus functions are approximate—the results are extrapolated, so what should be an integer calculation may ...
🌐
GitHub
github.com › prometheus › prometheus › issues › 15976
PromQL(histograms): Prevent extrapolation below zero · Issue #15976 · prometheus/prometheus
February 5, 2025 - tl;dr: We should prevent extrapolation below zero in rate and increase calculations, in a similar way as for simple float counters. TODOs are in the code and in the spec. By not doing it, we sometimes get different results from a NH vs. ...
Author: prometheus
🌐
Last9
last9.io › blog › prometheus-rate-function
Prometheus Rate Function: A Practical Guide to Using It | Last9
June 15, 2026 - Master Prometheus remote write optimization. Learn queue tuning, cardinality management, and relabeling strategies to scale your monitoring infrastructure efficiently. ... An important but often overlooked aspect of rate() is how it handles extrapolation. The function doesn’t simply divide the total increase by the time range.
🌐
Robust Perception
robustperception.io › existential-issues-with-metrics
Existential issues with metrics – Robust Perception | Prometheus Monitoring Experts
Prometheus is a metric-based time series monitoring system. A key aspect of this style of monitoring is that time series have a continuous existence over a period of time, and that scrapes are a snapshot of what those time series look like at regular intervals.
🌐
INNOQ
innoq.com › en › blog › 2019 › 05 › prometheus-counters
Prometheus Counters and how to deal with them – INNOQ
May 20, 2019 - Because of that, if we calculate the increase within this range vector, the result is 58 (76 - 18). Now, that’s not what Prometheus returns. The reason is (again according to the documentation) that the increase function tries to extrapolate missing values and estimate the values at the borders of the range.