首页 > 解决方案 > How to count number of requests in spring boot app?

问题描述

I have a spring boot application whose metrics I want to later send to gcp. But for now I just need to find a way to count the total number of requests my application is handling either with actuator or with micrometer. Does anybody know how I could do something like this? Thanks In advance

标签: javaspring-bootmetricsactuator

解决方案


一个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获取数据

官方文档中查看更多信息


推荐阅读