0

I am trying to setup metrics-spring to work in a Spring Boot application. To do this I added following dependencies:

compile group: 'io.dropwizard.metrics', name: 'metrics-core', version: '3.2.2'
compile group: 'io.dropwizard.metrics', name: 'metrics-annotation', version: '3.2.2'
compile group: 'com.ryantenney.metrics', name: 'metrics-spring', version: '3.1.3'

compile group: 'org.aspectj', name: 'aspectjweaver', version: '1.8.10'
compile group: 'cglib', name: 'cglib-nodep', version: '3.2.5'
compile group: 'org.springframework', name: 'spring-aop'

Created a configuration for metrics:

@EnableMetrics(proxyTargetClass = true)
@Configuration
@Slf4j
@CompileStatic
class SpringConfig extends MetricsConfigurerAdapter {
    @Override
    void configureReporters(MetricRegistry metricRegistry) {
        // registerReporter allows the MetricsConfigurerAdapter to
        // shut down the reporter when the Spring context is closed
        registerReporter(ConsoleReporter
                .forRegistry(metricRegistry)
                .build())
                .start(20, TimeUnit.SECONDS)
    }
}

And added a @Timed annotation:

@POST
@Path('auth')
@Timed(absolute = true, name = 'api.auth.createAuthToken')
Response auth(Credentials credentials) {
}

But I receive no metrics: 15/06/17 18:06:10 ==============================================================

On the other hand if I manually create a Timer and provide time to it it works fine.

I assume that it does not work because metrics-spring does not create AOP proxies for annotated methods, but I am not sure why.

Do you know what should I do to enable it?

Ivan Mushketyk
  • 8,107
  • 7
  • 50
  • 67
  • You shouldn't need anything but the dependencies. Spring Boot auto configures the drop wizard metrics when available. – M. Deinum Jun 15 '17 at 17:20
  • I tried it but I had two issues: 1. It ignored Timed annotation but instead was recording gauges and counters 2. Instead of using metric name from Timed annotation it was using different metric names. Not sure how to fix these issues – Ivan Mushketyk Jun 15 '17 at 17:29

0 Answers0