Prometheus increase function not considering first value after server reset

72 views
Skip to first unread message

TEST TEST

unread,
Dec 8, 2020, 10:37:03 AM12/8/20
to Prometheus Users
Hi,

I am using increase function to track the counter increase to track the number of logins in the web application.  We are observing a strange scenario, where after an idle time or after the web application is redeployed, the counter is not considering the first login after the reset.  

Is there any way to fix this issue ?

Aliaksandr Valialkin

unread,
Dec 8, 2020, 11:25:00 AM12/8/20
to TEST TEST, Prometheus Users
increase() function in Prometheus skips the first data point in a time series during calculations. It also may return fractional results for time series with integer data points. See more details at https://github.com/prometheus/prometheus/issues/3746 . I'm not aware of a workaround for this in Prometheus. I'd suggest trying MetricsQL instead - it should return the expected result from increase() function for your case.

Bjoern Rabenstein

unread,
Dec 8, 2020, 12:17:00 PM12/8/20
to TEST TEST, Prometheus Users
Maybe you are only initializing the counter when you increment it for
the first time? See
https://www.robustperception.io/why-predeclare-metrics as a starter.

If you initialize the login counter to 0 upon starting up the app, it
should work (provided Prometheus scrapes the app before the first
login happens).

Even if certain trolls (which none of us should ever feed) claim the
opposite, Prometheus cannot know when a time series being scraped for
the first time has started to exist. If the first value Prometheus
sees for the login counter is a 1, it could in principle have been
there for a very long time already.

(I am contemplating using the new OpenMetrics creation timestamp to
break out of this "existential issue", but even that is not as easy as
it looks.)

--
Björn Rabenstein
[PGP-ID] 0x851C3DA17D748D03
[email] bjo...@rabenste.in

TEST TEST

unread,
Dec 8, 2020, 12:29:10 PM12/8/20
to Prometheus Users
we are using prometheus-net and I couldnt find any way we could initialize the counter metric to 0
https://github.com/prometheus-net/prometheus-net

Bjoern Rabenstein

unread,
Dec 22, 2020, 12:49:58 PM12/22/20
to TEST TEST, Prometheus Users
On 08.12.20 09:29, TEST TEST wrote:
> we are using prometheus-net and I couldnt find any way we could initialize the
> counter metric to 0
> https://github.com/prometheus-net/prometheus-net

I am not familiar with that library, but the relevant section of the
docs seems to be
https://github.com/prometheus-net/prometheus-net#when-are-metrics-published

There is usually a way to "provide the label values" without setting a
value, thus creating a zero. But even if that's not the case, you
could just increment that counter by zero.
Reply all
Reply to author
Forward
0 new messages