Eamonn
Eamonn

Reputation: 53

Using Coda Hale Meter in Spring Boot application

The documentation says that

Users can create Coda Hale metrics by prefixing their metric names with the appropriate type (e.g. histogram., meter.).

I am taking this to mean that I can use either a Counter or Guage with a metric name of the form "meter.*" and this will work as a meter. I have tried

counterService.increment("meter.si.invoice.processing");

but when I visit /manage/metrics I just see the count and not the metered rate. What is the correct way to use a Coda Hale Meter in Spring Boot. The documentation is not very clear on how the integration works.

Upvotes: 2

Views: 1744

Answers (2)

ben schwartz
ben schwartz

Reputation: 2589

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/

Upvotes: 1

Dave Syer
Dave Syer

Reputation: 58124

The metrics endpoint is not aware of Codahale stuff. Once you send your metrics there you need to use Codahale tools to extract them (a meter for example doesn't map directly onto Spring Boot metric types, so there's no obvious way to expose them in the way you tried).

Upvotes: 2

Related Questions