我正在尝试设置 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 ================================== ==============================
另一方面,如果我手动创建一个计时器并为其提供时间,它工作正常。
我认为它不起作用,因为 metrics-spring 不会为带注释的方法创建 AOP 代理,但我不知道为什么。
你知道我应该怎么做才能启用它吗?