Prometheus counter reset

149 views
Skip to first unread message

Yogita Bhardwaj

unread,
May 25, 2023, 1:56:18 AM5/25/23
to Prometheus Users
I am using Prometheus counters in my project but the value of counter reset when service restart. how can I prevent counter reset while fetching data from Prometheus using http api.

Stuart Clark

unread,
May 25, 2023, 10:22:06 AM5/25/23
to Yogita Bhardwaj, Prometheus Users
On 25/05/2023 06:56, Yogita Bhardwaj wrote:
> I am using Prometheus counters in my project but the value of counter
> reset when service restart. how can I prevent counter reset while
> fetching data from Prometheus using http api. --

It is expected that counters will reset when a service restarts, so you
don't need to do anything. Prometheus handles counter resets
automatically when you are using functions like rate().

--
Stuart Clark

Yogita Bhardwaj

unread,
May 25, 2023, 10:59:51 AM5/25/23
to Stuart Clark, Prometheus Users
How can i apply rate or increase while using http api.

Stuart Clark

unread,
May 25, 2023, 11:11:44 AM5/25/23
to Yogita Bhardwaj, Prometheus Users
On 25/05/2023 15:59, Yogita Bhardwaj wrote:
> How can i apply rate or increase while using http api.
You just need to include it in the query you are sending the Prometheus API.

--
Stuart Clark

Yogita Bhardwaj

unread,
May 25, 2023, 11:22:58 AM5/25/23
to Stuart Clark, Prometheus Users

Brian Candler

unread,
May 26, 2023, 3:58:44 AM5/26/23
to Prometheus Users
By sending a PromQL query that uses rate, e.g.  rate(up[2m])
... with suitable URL escaping.

In fact, if you go to Prometheus' built-in web interface, turn on your browser's developer console, and enter that expression into the PromQL browser, you'll see that behind the scenes the web UI sends this to the API:

/api/v1/query?query=rate%28up%5B2m%5D%29&time=1685087742.644
Reply all
Reply to author
Forward
0 new messages