prometheus / client_java

Prometheus instrumentation library for JVM applications

Home Page:http://prometheus.github.io/client_java/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Add "increment to" to counters

Hoffs opened this issue · comments

Similar to #554 I feel like it is pretty common and legitimate use-case when trying to expose external system metrics using prometheus. For example, there is a autoanalyze_count FROM pg_stat_user_tables stat which is pretty closely mapped to prometheus counter (name gives it away). The problem is that there is no easy safe way to accomplish correct increment. The "obvious" solution is to retrieve current counter value and increment the difference. But this has obvious race condition issues, where anything can happen between value is read and increment is added, where the end result becomes out of sync. In such case, what really is needed is "increment to" method.
prometheus-net library provides exactly that: https://github.com/prometheus-net/prometheus-net/blob/master/Prometheus/Counter.cs#L55