I have a piece of an old code which uses Codahale metrics. I would like to change it to Micrometer. And I am fine with switching the easy ones, I have some troubles to reproduce funtionality of some Codahale specific objets.
And I am fine with switching the easy ones, I have some troubles to reproduce funtionality of some Codahale specific objets. I did not find any satisfying comparison in the area. I was basing on documentation and articles, but still no luck. I don't know if what I want to do is even possible.
For example, how would this look in Micrometer?
final CachedGauge<T> g = new CachedGauge<T>(refreshPeriod, TimeUnit.SECONDS) {
@Override
protected T loadValue() {
try {
return provider.call();
} catch (Exception ex) {
throw new RuntimeException("Failed to get cached value for [" + name + "]", ex);
}
}
};
metricRegistry.register("gauge." + fullName, g);
or just a simple String Gauge?:
Gauge<String> gauge;
or a ratio gauge?
RatioGauge ratioGauge = new AttendanceRatioGauge(15, 20);
when I want to compare two long values for example?
There are 3 questions here. All with vastly different answers.
There is no equivalent for a cached gauge in Micrometer. I recommend opening an issue requesting it. It would be a good addition. I would advocate for it. (I even need something like it myself)
All metrics that micrometer produces are numeric. So for cases where you want to expose a string add it as a tag.
meterRegistry.gauge("app.version",Tags.of("version",myVersion), this, () -> 1.0)
A ratio gauge would just be a typical gauge, doing the division yourself. Alternatively, you could expose the ratios sources as their own meters and do the division on the metrics platform side. For example Prometheus supports that easily:
class_attendance/class_size