使用弹簧引导将系统指标发送到石墨 [英] Sending System Metrics to Graphite with Spring-Boot

查看:82
本文介绍了使用弹簧引导将系统指标发送到石墨的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Spring-Boot执行器在/metrics处公开了许多有用的指标,例如正常运行时间,内存使用情况,GC计数.

Spring-Boot actuator exposes many useful metrics at /metrics such as uptime, memory usage, GC count.

使用Dropwizard Metrics集成时,仅其中一部分会发送到Graphite.具体来说,只有计数器和量规

Only a subset of these are sent to Graphite when using the Dropwizard Metrics integration. In specific, only the counters and gauges

是否有其他方法可以将这些其他指标发布到石墨上?

Is there any way to get these other metrics to be published to graphite?

文档建议应该这样做:

Dropwizard指标"库的用户会发现Spring Boot指标会自动发布到com.codahale.metrics.MetricRegistry

Users of the Dropwizard ‘Metrics’ library will find that Spring Boot metrics are automatically published to com.codahale.metrics.MetricRegistry

推荐答案

Spring Boot创建的系统度量标准不会自动报告,因为MetricsRegistry对这些度量标准一无所知.

System Metrics created by Spring boot are not reported automatically because MetricsRegistry does not know anything about those Metrics.

在应用程序启动时,您应该手动注册这些指标.

You should register those metrics manually when your application boots up.

@Autowired
private SystemPublicMetrics systemPublicMetrics;

private void registerSystemMetrics(MetricRegistry metricRegistry) {
    systemPublicMetrics.metrics().forEach(m -> {
        Gauge<Long> metricGauge = () -> m.getValue().longValue();
        metricRegistry.register(m.getName(), metricGauge);   
    });
}

我已经定义了Gauge,并非所有系统指标都应添加为量规.例如计数器应用于捕获计数值.

I have defined Gauge, not all the system metrics should be added as gauge. e.g. the Counter should be used to capture count values.

如果您不想使用Spring Boot.可以直接使用metrics-jvm来捕获JVM级别的指标.

If you don't want to use Spring boot. Use can include metrics-jvm out of the box to capture JVM level metrics.

这篇关于使用弹簧引导将系统指标发送到石墨的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆