2

Currently, I'm looping through all the labels and setting their values to 0 manually. I was wondering whether there is less error-prone way.

Context: I'm using a Prometheus Gauge to monitor the maximum number of duplicates found in my data. The data duplication check itself is triggered once on every 4 hours. When the latter happens, all labels' values are reset to 0, then every time I detect duplicates the Gauge's value for the corresponding labels is set to max(previousValue, newValue).

2 Answers2

4

When I was checking the Prometheus github issues, I stumbles upon this line of code that basically resets the gauge.

YOUR_GAUGE._metrics.clear()
RonZhang724
  • 535
  • 8
  • 17
2

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.

  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Mar 11 '22 at 08:34