I'm trying to programmatically read the Meters as follows:
Get registry:
MeterRegistry registry = Metrics.globalRegistry.getRegistries().iterator().next();
Read measurement:
double systemCpuUsage = registry.get("system.cpu.usage").gauge().measure().iterator().next().getValue();
The problem is that sometimes I get NaN
.
I read about this in the docs: Why is my Gauge reporting NaN or disappearing?
but I'm not sure what I shall do. Also, I'm reading the "built-in" gauge of Spring Boot actuator (which is exposed by management.metrics.enable.process.cpu.usage=true
) so I cannot change it's construction.