@Counted 是如何工作的? 我在控制器(Controller)的方法上添加了 @Counted 注释,并期望看到有多少次请求来到控制器(Controller)。但我无法看到指标(metrics)添加到URL http://localhost:8080/actuator/prometheus 上。
@Counted(value = "counted.success.test",description = "testCounter")
@Counted 是如何工作的? 我在控制器(Controller)的方法上添加了 @Counted 注释,并期望看到有多少次请求来到控制器(Controller)。但我无法看到指标(metrics)添加到URL http://localhost:8080/actuator/prometheus 上。
@Counted(value = "counted.success.test",description = "testCounter")
CountedAspect
作为一个 bean 添加进来,这样在调用方法时指标就会被创建:@Configuration
@EnableAspectJAutoProxy(proxyTargetClass = true)
public class Config {
@Bean
CountedAspect countedAspect(MeterRegistry registry) {
return new CountedAspect(registry);
}
(记不清为什么我们添加了@EnableAspectJAutoProxy(proxyTargetClass = true)
)
尽管这种工具不是完美的,但标签class
和method
会随着代码重构而改变,你的Grafana仪表板可能不再起作用。