title: PromQL: What is rate() function meant for?
body: <p>I have a question regarding PromQL and its query functions rate() and how to use it properly. In my application, I have a thread running, and I use Micrometer's Timer to monitor the thread's runtime. Using Timer gives you a counter with suffix _count and another counter with the sum of the seconds spent with suffix _sum. E.g. my_metric_sum and my_metric_count.</p>
  <p>My raw data looks like this (scrape interval 30 s, range vector 5m):</p>
  <p><a href="https://i.stack.imgur.com/Ptk2t.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Ptk2t.png" alt="enter image description here" /></a></p>
  <p>Now according to the docs, <a href="https://prometheus.io/docs/prometheus/latest/querying/functions/#rate" rel="nofollow noreferrer">https://prometheus.io/docs/prometheus/latest/querying/functions/#rate</a> <em>calculates the per-second average rate of increase of the time series in the range vector</em> (which is 5m here).</p>
  <p>Now my question is: why would I want that? The relative change of my execution runtime seems pretty useless to me. In fact, just using sum/count looks more useful as it gives me the avg absolute duration for each moment in time. At the same time, and this is what confused me, in the docs I find</p>
  <p>To calculate the average request duration during the last 5 minutes from a histogram or summary called http_request_duration_seconds, use the following expression:</p>
  <p>rate(http_request_duration_seconds_sum[5m]) / rate(http_request_duration_seconds_count[5m])</p>
  <p>Source: <a href="https://prometheus.io/docs/practices/histograms/" rel="nofollow noreferrer">https://prometheus.io/docs/practices/histograms/</a></p>
  <p>But as I understand the docs, it looks like this expression would calculate the per-second average rate of increase of the request duration, ie not how long a request takes on average, but instead how much the request duration has changed on average in the last 5 minutes.</p>