2

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?

KompiKompi
  • 400
  • 4
  • 22

1 Answers1

3

There are 3 questions here. All with vastly different answers.

Cached gauge

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)

String gauge

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)

Ratio gauge

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
checketts
  • 14,167
  • 10
  • 53
  • 82
  • You confirmed my concerns about this. I need to figure out the way to do this, is Gauge even doable? – KompiKompi Feb 12 '19 at 18:53
  • By `Gauge` would it be a gauge on a specific pojo that returns a `double` that references a property on the POJO? That is supported. But if you are instead trying to write out all POJO fields, it won't work. – checketts Feb 14 '19 at 18:18