我正在尝试设置metrics-spring以在Spring Boot应用程序中工作。为此,我添加了以下依赖项:
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'
为指标创建了配置:
@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)
}
}
并添加了@Timed注释:
@POST
@Path('auth')
@Timed(absolute = true, name = 'api.auth.createAuthToken')
Response auth(Credentials credentials) {
}
但我没有收到指标: 15/06/17 18:06:10 ======================================== ======================
另一方面,如果我手动创建一个Timer并为它提供时间,它可以正常工作。
我认为它不起作用,因为metrics-spring不会为带注释的方法创建AOP代理,但我不确定原因。
你知道我应该怎么做才能启用它吗?