简体   繁体   English

如何从Dropwizard指标正确切换到千分尺?

[英]How to switch correctly from Dropwizard metrics to Micrometer?

I have a piece of an old code which uses Codahale metrics. 我有一段使用Codahale指标的旧代码。 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. 我很乐意改变那些简单的,我有一些麻烦来重现一些Codahale特定的objets的功能。

And I am fine with switching the easy ones, I have some troubles to reproduce funtionality of some Codahale specific objets. 我很乐意改变那些简单的,我有一些麻烦来重现一些Codahale特定的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? 例如,这在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. 这里有3个问题。 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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM