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

Luis Muñiz picture Luis Muñiz · Jul 4, 2014 · Viewed 7.9k times · Source

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!

Answer

ben schwartz picture ben schwartz · Oct 23, 2014

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/