【问题标题】:How @Counted works in spring boot?@Counted 如何在 Spring Boot 中工作?
【发布时间】:2021-05-21 01:42:48
【问题描述】:

@Counted 如何工作? 我在 Controller 中的方法上添加了 @Counted 注释,并希望看到有多少点击进入控制器。但我看不到添加到 url http://localhost:8080/actuator/prometheus 的指标。

 @Counted(value = "counted.success.test",description = "testCounter")

【问题讨论】:

  • 您能否提供您为 prometheus 所做的所有配置以将所有统计信息转移到执行器?你拿到执行器的钥匙了吗?
  • @Yogesh Prajapati 没有得到普罗米修斯的钥匙。

标签: spring-boot prometheus spring-boot-actuator health-monitoring spring-micrometer


【解决方案1】:

你需要添加一个CountedAspect作为bean,然后在调用方法时创建度量:

@Configuration
@EnableAspectJAutoProxy(proxyTargetClass = true)
public class Config {

    @Bean
    CountedAspect countedAspect(MeterRegistry registry) {
        return new CountedAspect(registry);
    }

(不记得我们为什么要添加@EnableAspectJAutoProxy(proxyTargetClass = true)

虽然这种仪器并不完美,但 classmethod 标签会在您重构代码后立即更改,并且您的 Grafana 仪表板可能不再工作。

【讨论】:

  • 添加了 CountedAspect 的 bean,它起作用了。 @Bean public CountedAspect countedAspect(MeterRegistry MeterRegistry) { return new CountedAspect(meterRegistry); }
猜你喜欢
  • 2018-10-03
  • 1970-01-01
  • 1970-01-01
  • 2020-03-04
  • 2017-07-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多