I need to add gauges from a scheduler to MeterRegistry. I register new gauges and they appear in Prometheus output, but the value functions aren’t being called. It leads to NaN values on the added metrics in prometheus.
I tried to add those gauges with MeterBinder and it works fine, but I need to do it at runtime due to the nature of these metrics.
In brief, my flow looks like following:
- Each N minutes retrieve all existing entities from the db
- Remove metrics for removed entities
- Add gauges for new entities
- In the value function of the gauge go to redis, fetch the state and return the value
Thus, I can’t just add them at startup.