简体   繁体   English

Springboot:千分尺指标未显示

[英]Springboot: micrometer metrics not showing up

I am writing my first spring boot (2.6.3) application.我正在编写我的第一个 spring 启动 (2.6.3) 应用程序。

Here the relevant dependencies I am using:这里是我正在使用的相关依赖项:

<dependencyManagement>
    <dependencies>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-dependencies</artifactId>
            <version>2.6.3</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>

    </dependencies>
</dependencyManagement>

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
        <exclusions>
            <exclusion>
                <groupId>org.apache.logging.log4j</groupId>
                <artifactId>log4j-api</artifactId>
            </exclusion>
            <exclusion>
                <groupId>org.apache.logging.log4j</groupId>
                <artifactId>log4j-to-slf4j</artifactId>
            </exclusion>
        </exclusions>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-validation</artifactId>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-actuator</artifactId>
    </dependency>

    <dependency>
        <groupId>io.micrometer</groupId>
        <artifactId>micrometer-registry-prometheus</artifactId>
        <scope>runtime</scope>
    </dependency>
</dependencies>        

I exposed by actuator all the features:我通过执行器暴露了所有功能:

management:
  endpoint:
    health:
      show-details: always
  endpoints:
    web:
      exposure:
        include: '*'
  info:
    env:
      enabled: true

So I can see all the endpoints listed by the url /actuator .所以我可以看到 url /actuator列出的所有端点。

Now, I added some annotations like @Counted and @Timed to some methods, I invoked them, but they don't show up into /actuator/metrics .现在,我在一些方法中添加了一些注释,如@Counted@Timed ,我调用了它们,但它们没有出现在/actuator/metrics中。

How could I solved that issue?我怎么能解决这个问题?

Thank you so much in advance!非常感谢您!

Are you aware that @Timed annotations are supported on @Controller classes and @RequestMapping methods only?您是否知道@Timed注释仅在@Controller类和@RequestMapping方法上受支持?

https://docs.spring.io/spring-boot/docs/current/reference/html/actuator.html#actuator.metrics.supported.spring-mvc https://docs.spring.io/spring-boot/docs/current/reference/html/actuator.html#actuator.metrics.supported.ZC5611D5C8C9F9E896756BF480C0E7

I am not sure @Counted is supported by default.我不确定默认情况下是否支持@Counted

EDIT: The @Counted annotation doesn't work by default.编辑: @Counted注释默认不起作用。 To make it work, you'll need to add an CountedAspect to your context.要使其工作,您需要将CountedAspect添加到您的上下文中。

See: https://github.com/micrometer-metrics/micrometer/blob/main/micrometer-core/src/main/java/io/micrometer/core/aop/CountedAspect.java参见: https://github.com/micrometer-metrics/micrometer/blob/main/micrometer-core/src/main/java/io/micrometer/core/aop/CountedAspect.java

Also, there's an open issue for @Counter auto-configuration: https://github.com/spring-projects/spring-boot/issues/17260此外,@Counter 自动配置还有一个未解决的问题: @Counter ://github.com/spring-projects/spring-boot/issues/17260

Solved by adding the following:通过添加以下内容解决:

@Bean
CountedAspect countedAspect(MeterRegistry registry) {
    return new CountedAspect(registry);
}
<dependency>
    <groupId>org.aspectj</groupId>
    <artifactId>aspectjweaver</artifactId>
    <version>1.8.13</version>
</dependency>

It works with OpenAPI delegates too.它也适用于 OpenAPI 委托。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM