Thanks for you help I think I figured it out now with your help! [image] Do please follow up if this could be further improved! Answer from anon56958872 on community.grafana.com
🌐
Grafana
community.grafana.com › t › how-to-plot-the-rate-of-change-or-the-incline-of-a-line-plot › 14334
How to plot the rate of change or the incline of a line plot? - Grafana Labs Community Forums
February 11, 2019 - I’m plotting AWS/Billing Estimated charges in Grafana, but I am having a hard time determining if the slope if increasing or not. Basically I want to plot the graph in such a way, that I am aware of the rates of change. I.e. if spending goes up, I can notice that increase.
🌐
Reddit
reddit.com › r/grafana › is it possible to create a graph to calculate the change rate over a certain time frame?
r/grafana on Reddit: Is it possible to create a graph to calculate the change rate over a certain time frame?
January 6, 2023 -

I have multiple graphs for all the log sources, I want to know when one changes drastically. The option to set thresholds for each log source does not support the current version, so I need to work around it. I want to create a graph for which would calculate the change rate over a certain time-frame. The idea is to create a graph in place which shows the change rate (in %) and alarm me if it’s too high.

Any idea on how to do this?

The grafana version is 7.5.15

Top answer
1 of 2
2
Not natively but with SQL code you can. Or just set up an alert.... Those can calculate based on a timeframe.
2 of 2
1
There are a few ways do to this, one is hacky and one is the "right" way. They both ultimately rely on what your data source is. 1) The Hack: long time ranges and derivatives in Grafana This is what I am doing now. I don't like it, but I haven't gotten around to implementing #2 below. The concept is you take the derivative of the same data you're already graphing, which gives you the rate of change. Then, you can alert if that graph gets too high or too low. The reason I say this is a hack is you are required to set your time span in grafana to a long enough range that it can aggregate change over time. If you normally have grafana set to 6 hours but want it to aggregate the prior 10 hours, this won't work. I've successfully used this method with InfluxQL and Prometheus queries. 2) The right way: Storing the data in your Data Source This method will depend on the data source having the specific feature I'm about to describe. InfluxDB calls them "continuous queries", Prometheus calls them "recording rules", but they're functionally similar. In both cases, what you're doing is writing a new query that takes the same query from option 1, but writes it back to InfluxDB directly. This happens completely outside of Grafana. Then, you can graph this new value natively as a normal value, and the best part is it doesn't rely on any grafana funny stuff. So you'll have a metric for my_value and another, separate metric for my_value_change_rate or something. Another benefit of this technique is you are storing this data permanently, so you can use it later if needed for other things. The last benefit I can think of is you're reducing the load on your InfluxDB server when you load your dashboard, because there are no complex long-running queries being calculated. This is especially pronounced as you increase the length of time.
How can I understand rate() ? Nov 21, 2021
r/grafana
4y ago
Custom state timeline graph Oct 20, 2022
r/grafana
3y ago
Time series x axis scale Sep 14, 2021
r/grafana
4y ago
Grafana custom metrics Dec 3, 2021
r/sysadmin
4y ago
More results from reddit.com
Discussions

Applying a rate function to positive and negative changes
I’ve set up a new graph in Grafana showing the change of a metric using the rate() function. However, it seems to work in inverse (showing a positive value when the gauge drops) and does not show any change when the gauge increases. I’ve plotted the original gauge (yellow, right axis) along ... More on community.grafana.com
🌐 community.grafana.com
1
1
June 22, 2018
grafana - Finding the rate of decrease but ignoring increases over time with PromQL - Stack Overflow
Therefore, I would like to calculate a some-what accurate rate of %-loss over time for different time periods, for example 3, 10, 30, & 60 days, so I can see if the rate is changing on my Grafana dashboard and then create some relevant alerts. More on stackoverflow.com
🌐 stackoverflow.com
Do I understand Prometheus's rate vs increase functions correctly? - Stack Overflow
I have read the Prometheus documentation carefully, but its still a bit unclear to me, so I am here to get confirmation about my understanding. (Please note that for the sake of the simplest examples More on stackoverflow.com
🌐 stackoverflow.com
prometheus - Why does Rate is grafana seem to be looking at an interval that is a minute larger than requested? - Stack Overflow
Bring the best of human thought and AI automation together at your work. Explore Stack Internal ... Save this question. Show activity on this post. I am trying to follow up on this question that has a great explanation about counter/rate/increase work in prometheus/grafana ... More on stackoverflow.com
🌐 stackoverflow.com
🌐
Last9
last9.io › blog › grafana-rate-function
Why Grafana's Rate Function Is Your Dashboard's Best Kept Secret | Last9
April 25, 2025 - The rate function in Grafana calculates how quickly a counter metric increases over time. Think of it like your car’s speedometer - instead of just showing total miles driven (the counter), it shows how fast you’re currently going (the rate).
🌐
Grafana
grafana.com › docs › grafana › latest › visualizations › panels-visualizations › query-transform-data › calculation-types
Calculation types | Grafana documentation
Documentation Grafana documentation Visualize data Panels and visualizations Query and transform data Calculation types ... The following table contains a list of calculations you can perform in Grafana.
🌐
MetricFire
metricfire.com › blog › understanding-the-prometheus-rate-function
How the Prometheus rate() function works | MetricFire
March 12, 2026 - As you can see, instant vectors only define the recently scraped value. rate() and its cousins take an argument of the range type since to calculate any change, you need at least two points of data. They do not return any results if less than two samples are available. PromQL indicates range vectors by writing a time range in square brackets next to a selector that says how much time it should go into the past. Selecting the right time range for the rate() function is crucial for obtaining meaningful insights: Customizable Managed Grafana Dashboards
🌐
Grafana
community.grafana.com › t › applying-a-rate-function-to-positive-and-negative-changes › 8243
Applying a rate function to positive and negative changes - Grafana - Grafana Labs Community Forums
June 22, 2018 - I’ve set up a new graph in Grafana showing the change of a metric using the rate() function. However, it seems to work in inverse (showing a positive value when the gauge drops) and does not show any change when the gauge increases. I’ve plotted the original gauge (yellow, right axis) along with the rate function (green, left axis) to demonstrate this behavior: The following Prometheus queries were used to create them: Rate of change - min(rate(metric_name{cluster=“$cluster”, cluster_type=...
🌐
Medium
medium.com › @bhupender.rawat4 › demystifying-prometheus-a-deep-dive-into-rate-and-irate-ce02745231fc
Demystifying Prometheus: A Deep Dive into rate() and irate() | by Bhupender Singh Rawat | Medium
May 7, 2025 - Check the Grafana dashboard for visual representation. ... Once you add the datasource. Import the dashboard using dashboard.json content present in the repository. You will see three visualization panel as shown below. Below is the representation of following panels. total http request count [testpath_requests_total] ... both rate() and irate() are essential functions for analyzing counter metrics in Prometheus, but they serve different purposes.
🌐
Grafana
grafana.com › docs › grafana › latest › visualizations › panels-visualizations › visualizations › stat
Stat | Grafana documentation
Adjust the sizes of the stat text. Title - Enter a numeric value for the stat title size. Value - Enter a numeric value for the stat value size. Percent change - Enter a numeric value for the percent change size when Show percent change is enabled.
Find elsewhere
Top answer
1 of 3
273

In an ideal world (where your samples' timestamps are exactly on the second and your rule evaluation happens exactly on the second) rate(counter[1s]) would return exactly your ICH value and rate(counter[5s]) would return the average of that ICH and the previous 4. Except the ICH at second 1 is 0, not 1, because no one knows when your counter was zero: maybe it incremented right there, maybe it got incremented yesterday, and stayed at 1 since then. (This is the reason why you won't see an increase the first time a counter appears with a value of 1 -- because your code just created and incremented it.)

increase(counter[5s]) is exactly rate(counter[5s]) * 5 (and increase(counter[2s]) is exactly rate(counter[2s]) * 2).

Now what happens in the real world is that your samples are not collected exactly every second on the second and rule evaluation doesn't happen exactly on the second either. So if you have a bunch of samples that are (more or less) 1 second apart and you use Prometheus' rate(counter[1s]), you'll get no output. That's because what Prometheus does is it takes all the samples in the 1 second range [now() - 1s, now()] (which would be a single sample in the vast majority of cases), tries to compute a rate and fails.

If you query rate(counter[5s]) OTOH, Prometheus will pick all the samples in the range [now() - 5s, now] (5 samples, covering approximately 4 seconds on average, say [t1, v1], [t2, v2], [t3, v3], [t4, v4], [t5, v5]) and (assuming your counter doesn't reset within the interval) will return (v5 - v1) / (t5 - t1). I.e. it actually computes the rate of increase over ~4s rather than 5s.

increase(counter[5s]) will return (v5 - v1) / (t5 - t1) * 5, so the rate of increase over ~4 seconds, extrapolated to 5 seconds.

Due to the samples not being exactly spaced, both rate and increase will often return floating point values for integer counters (which makes obvious sense for rate, but not so much for increase).

2 of 3
50

Prometheus calculates rate(counter[d]) at timestamp t in the following way:

  1. It selects raw samples for the counter time series on the time range (t-d ... t]. Note that the t-d timestamp isn't included in the time range, while t timestamp is included in the time range. If the selected time range contains less than two raw samples, then Prometheus returns an empty value (a gap) at the timestamp t.
  2. Then it calculates the increase of the selected raw samples. Usually it is calculated as the difference between the last selected sample and the first selected sample. Calculations become slightly complicated if the counter was reset to zero during the selected time range. Let's skip this for the sake of clarity.
  3. Then the resulting increase can be extrapolated if timestamps for the first and/or the last raw samples are located too far from the bounds of the selected time range.
  4. Then the rate is calculated by dividing the extrapolated increase by d.

Prometheus calculates increase(counter[d]) in the same way except the last step.

Let's look at a few examples applied to the original data:

second   counter_value    increase calculated by hand(call it ICH from now)
1             1                    1
2             3                    2
3             6                    3
4             7                    1
5            10                    3
6            14                    4
7            17                    3
8            21                    4
9            25                    4
10           30                    5
  • The rate(counter[1s]) will return nothing at any timestamp t, since any time range (t-1s ... t] contains only a single raw sample, while Prometheus requires at least two samples for calculating both rate() and increase().

  • The rate(counter[2s]) and increase(counter[2]) would return the following values per each timestamp t when extrapolation isn't applied:

t       counter_value    rate(counter[2s])        increase(counter[2s])
1             1                    -                       -
2             3               (3-1)/2=1.0                3-1=2
3             6               (6-3)/2=1.5                6-3=3
4             7               (7-6)/2=0.5                7-6=1
5            10              (10-7)/2=1.5               10-7=3
6            14             (14-10)/2=2                14-10=4
7            17             (17-14)/2=1.5              17-14=3
8            21             (21-17)/2=2                21-17=4
9            25             (25-21)/2=2                25-21=4
10           30             (30-25)/2=2.5              30-25=5

In reality Prometheus results for rate(counter[2s]) and increase(counter[2s]) may be slightly bigger because of extrapolation, since the first sample on the selected time range is located comparatively far from the start of the time range.

Such calculations have the following issues:

  • Prometheus can return fractional results from increase() over time series, which contains only integer values. This is because of extrapolation. For example, Prometheus may return fractional results from increase(http_requests_total[5m]).

  • Prometheus returns empty results (aka gaps) from increase(counter[d]) and rate(counter[d]) when the lookbehind window d doesn't cover at least two samples - see rate(counter[1s]) and increase(counter[1s]) example above.

  • Prometheus completely misses the increase between the raw sample just before the (t-d ... t] interval and the first raw sample on this interval. This may result in inaccurate calculations. For example, increase(counter[1h]) doesn't equal to sum_over_time(increase(counter[1m])[1h:1m]).

Prometheus developers are aware of these issues - see this link. These issues are addressed in the system I work on - VictoriaMetrics - more specifically, in MetricsQL query language - see this comment and this article for technical details.

🌐
Grafana
grafana.com › docs › grafana › latest › panels-visualizations › query-transform-data › transform-data
Transform data | Grafana documentation
Use transformations to rename fields, join time series/SQL-like data, apply mathematical operations, and more
🌐
DoiT
doit.com › home › blog › making peace with prometheus rate()
Making peace with Prometheus rate() | DoiT
February 17, 2023 - You see, depending on how stars align if our 1-minute range buckets land just on metric change boundaries, there is no change in the metric within that bucket at all and this is exactly why rate(), together with its sister increase(), returns zeroes. Why does it reproduce so often and so consistently? Two factors: If you have a thing in your code that reports change around a whole minute(s) (think cronjobs), then it’s likely that the change will be attributed to the whole-minute boundary when scraping. As of two years ago, Grafana makes sure (and rightfully so) to align the start of the chart range to be a multiple of step, hence if your step in Grafana is one minute, the bucket boundaries will always fall on a whole-minute boundary, e.g.
🌐
Datadog
docs.datadoghq.com › dashboards › functions › rate
Rate
August 6, 2026 - Calculate rates, derivatives, and time differences to analyze metric changes per second, minute, or hour.
🌐
Wavefront
docs.wavefront.com › ts_rate.html
rate Function | VMware Aria Operations for Applications Documentation
For example, if my.metric reports ... in a new or restarted time series. rate() can then use the number of seconds in the specified interval to calculate the per-second rate of change from the inferred 0 value to the actual data value....
🌐
Promlabs
promlabs.com › blog › 2021 › 01 › 29 › how-exactly-does-promql-calculate-rates
PromLabs | Blog - How Exactly Does PromQL Calculate Rates?
January 29, 2021 - Example: irate(http_requests_total[5m]) looks at the two last samples under the provided 5-minute window and calculates the per-second rate of increase between them. This function can be helpful if you want to make a zoomed-in graph show very quick responses to changes in a rate, but the output will be much more spiky than for rate().
🌐
GitHub
github.com › prometheus › prometheus › issues › 2364
Simple Grafana graphs change significantly in between refreshes · Issue #2364 · prometheus/prometheus
January 24, 2017 - But the overall difference between 40% usage over most of 24 hours and 80% seems to huge a discrepancy to be expected rounding error. It throws into question how reliable any graph is if the value is so sensitive to what time range is selected (i.e. few seconds difference changes whole graph substantially). I've tried difference resolution and step settings in Grafana and they don't seem to make a difference to the fact that refreshes substantially change the graph content (obviously they affect the graph in expected ways).
Author: prometheus
🌐
IT Jobs Watch
itjobswatch.co.uk › contracts › uk › grafana.do
Grafana Contract Job Trends, Contractor Rates & Related Skills | IT Jobs Watch
Hourly rate distribution of jobs citing Grafana over the 6 months to 22 December 2025. The table below looks at the demand and provides a guide to the median contractor rates quoted in IT jobs citing Grafana within the UK over the 6 months to 22 December 2025. The 'Rank Change' column provides an indication of the change in demand within each location based on the same 6 month period last year.