我有一个简单的 springboot REST API,我想在其中检查不同操作所花费的时间。我正在使用 Springboot 3.2.2 和 Micrometer 提供的 @Timed 注释。当我执行休息端点时,我无法在 /actuator/metrics 端点或日志中看到计时器详细信息。
以下是我在 pom.xml 中的依赖项
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.2.2</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-aop</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-tracing-bridge-otel</artifactId>
</dependency>
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-core</artifactId>
<version>1.12.2</version>
</dependency>
</dependencies>
以下是控制器类
import io.micrometer.core.annotation.Timed;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class TestController {
@Timed(value = "first.timer", description = "Time taken by GET method")
@GetMapping("/apiEndpoint")
public String helloWorld() {
doBusiness();
return "Hello world called!";
}
@Timed(value = "second.timer", description = "Time taken by business method")
private void doBusiness()
{
//Does some long running task
}
}
下面是 application.yml 条目 -
management:
metrics:
distribution:
percentiles-histogram:
http:
server:
requests: true
endpoint:
metrics:
enabled: true
endpoints:
web:
exposure:
include: health,info,metrics
tracing:
sampling:
probability: 1.0
propagation:
type: w3c
logging:
level:
root: DEBUG
我需要设置任何特定参数才能启用此功能吗?如果您能在最新的 Spring Boot 3.2.2 文档中展示 Micrometer 注释的用法,我将不胜感激。
我浏览了 Spring 文档,但找不到任何具体内容。