Trying to integrate Coda Hale Metrics in spring boot, not seing the metrics in /metrics

北城以北 提交于 2019-12-10 22:39:31

问题


I have followed the indication that adding the coda hale metrics library into the classpath would automatically autoconfigure the metrics.

That works, I get the injected metricRegistry bean.

However, how to I expose these new metrics in the /metrics endpoint?

Thanks!


回答1:


That's not the way it's supposed to work. Codahale has some metric types that do not map to Spring Boot ones, so you are supposed to use the Codahale native APIs for reporting once you start collecting metrics that way. Boot is only providing the service abstraction for Gauge and Counter at that point.

UPDATE: Spring Boot also adds Codahale metrics to the /metrics endpoint since 1.2.0 (see MetricRegistryMetricReader).




回答2:


There's some integration magic accomplished by http://www.ryantenney.com/metrics-spring/ that wires codahale metrics into the actuator /health endpoint.

With this dependency included,

compile 'com.ryantenney.metrics:metrics-spring:3.0.0-RC2'

you can "enableMetrics" in your application configuration

@EnableMetrics
public class ApplicationConfiguration {
    ...

This allows you to time each request with the @timed annotation:

@Timed
@RequestMapping(method=RequestMethod.GET)
public @ResponseBody
Foo foo() {
    ...

and to have your other interactions with MetricRegistry aggregate into the actuator /health endpoint.

I've put together an example application which implements this integration:

https://github.com/benschw/consul-cluster-puppet/tree/master/demo

and written a more in depth tutorial here: http://txt.fliglio.com/2014/10/spring-boot-actuator/




回答3:


I update a metrics histogram using spring-boot like this:

        gauge.submit("histogram." + name + ".millis", durationMillis);


来源:https://stackoverflow.com/questions/24571282/trying-to-integrate-coda-hale-metrics-in-spring-boot-not-seing-the-metrics-in

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!