# Increment of a counter metrics in the last hour divided by 5 mins

**URL:** <https://discuss.prometheus.io/t/increment-of-a-counter-metrics-in-the-last-hour-divided-by-5-mins/2299>\
**Category:** PromQL\
**Created:** [June 12, 2024, 8:21am UTC](https://discuss.prometheus.io/t/increment-of-a-counter-metrics-in-the-last-hour-divided-by-5-mins/2299 "2024-06-12T08:21:10Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![enchandan](https://avatars.discourse-cdn.com/v4/letter/e/e47774/32.png) [@enchandan](https://discuss.prometheus.io/u/enchandan)\
**Post date:** [June 12, 2024, 8:21am UTC](https://discuss.prometheus.io/t/increment-of-a-counter-metrics-in-the-last-hour-divided-by-5-mins/2299/1 "2024-06-12T08:21:10Z")

</div>

Hello community,

I have a counter metrics say `api_msg_count` which keeps on increasing based on incoming no. of messages to the api.  
I want to show this increase of no. of messages on a graph. It should be for the last hour for each 5 mins interval. I am using the following promql, which also gives me separate timestamps for the last hour divided by 5 mins.

Example: [PromLens - The query builder, analyzer, and explainer for PromQL](https://demo.promlens.com/?l=QZG4uMv81Z7)

`increase(api\_msg\_count[5m])[1h:5m]

6397.894736842105 @ 1718175600  
7066.315789473684 @ 1718175900  
7184.210526315789 @ 1718176200  
6791.578947368421 @ 1718176500  
5882.105263157894 @ 1718176800  
4908.421052631578 @ 1718177100  
4245.263157894737 @ 1718177400  
4032.6315789473683 @ 1718177700  
3996.8421052631575 @ 1718178000  
4074.736842105263 @ 1718178300  
4558.9473684210525 @ 1718178600  
5416.8421052631575 @ 1718178900`

However, I see that some of the times, the very first msg count doesn’t apear in the results. Also, the results are always extrapolated, if there are total 10 msgs sent to the api, it shows 12.5 in the result for that timestamp.  
Is there a better way to do this?

I tried using `offset` and it gives the correct results. But now instead of one query to prometheus api, I have to make total (60 / 5 = 12) calls to prometheus api for every 5 mins of the past hour and implement a logic to calculate the increment.

api\_msg\_count offset 5m  
api\_msg\_count offset 10 m  
…  
api\_msg\_count offset 60
