When I was checking the Prometheus github issues, I stumbles upon this line of code that basically resets the gauge.
YOUR_GAUGE._metrics.clear()
Answer from RonZhang724 on Stack OverflowWhen I was checking the Prometheus github issues, I stumbles upon this line of code that basically resets the gauge.
YOUR_GAUGE._metrics.clear()
https://github.com/prometheus/client_java/blob/master/simpleclient/src/main/java/io/prometheus/client/SimpleCollector.java
Confirmed that we can initialize Gauge with
YOUR_GAUSE.clear()
I put it to catch block to handle exception :) Note that, it clears all metrics instead setting 0.
Is there a way to avoid reading zero values? This is my problem:
-
Lets say that I have a prometheus
gaugethat I update every few minutes with some numbern. -
Now let's say that I restart my software. Right after restarting, the value of the
gaugewill take a default value0becausenhasn't been set yet. -
Before
nis set, prometheus reads thegaugevalue, which is0 -
Is there way to make prometheus wait until the
gagugevalue is set?
I could also just filter out 0 values, but 0 can be also a valid value.
I’m having a wierd issue. I’m running a local app configured with a prometheus CounterVec that’s scraped by a local prometheus instance.
After running both a while I can query prometheus for the counter and all is good.
Then I restart the app and do the same query and the data is lost. The counter is reset.
What am I Missing here? Do I need some persistant id for the app? I would expect prometheus to show me all data across app restarts.