【发布时间】:2020-05-12 06:13:09
【问题描述】:
我有一个 Spring Boot 应用程序,我想稍后将其指标发送到 gcp。但是现在我只需要找到一种方法来计算我的应用程序使用actuator 或micrometer 处理的请求总数。有人知道我怎么能做这样的事情吗?提前致谢
【问题讨论】:
标签: java spring-boot metrics actuator
我有一个 Spring Boot 应用程序,我想稍后将其指标发送到 gcp。但是现在我只需要找到一种方法来计算我的应用程序使用actuator 或micrometer 处理的请求总数。有人知道我怎么能做这样的事情吗?提前致谢
【问题讨论】:
标签: java spring-boot metrics actuator
spring-actuator 示例:
//add pom
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
使用执行器
@Bean
public SecurityWebFilterChain securityWebFilterChain(
ServerHttpSecurity http) {
return http.authorizeExchange()
.pathMatchers("/actuator/**").permitAll()
.anyExchange().authenticated()
.and().build();
}
然后就可以从http://localhost:8080/metrics获取数据了
从official documentation查看更多信息
【讨论】:
看看Spring Boot Actuator - HttpTrace
默认情况下,它在最新版本中未启用,但您可以通过实现 HttpTraceRepository 来启用。
在此存储库中,您可以使用计数器来测量请求的数量,然后将其添加到 MetricRegistry。另一种选择是使用过滤器,然后在那里使用计数器。
【讨论】: