Spring Boot 2.5.6中jvm_memory_usage_after_gc_percent指标缺失排查
问题:Spring Boot 2.5.6中
jvm_memory_usage_after_gc_percent指标未在Actuator端点显示 环境信息
- Spring Boot版本:
2.5.6 - 集成Swagger依赖:
springfox-boot-starter:3.0.0 - 安全配置类:
WebSecurityConfig(继承WebSecurityConfigurerAdapter、实现WebMvcConfigurer) - 已添加的Micrometer依赖:
<dependency> <groupId>io.micrometer</groupId> <artifactId>micrometer-registry-prometheus</artifactId> </dependency> <dependency> <groupId>io.micrometer</groupId> <artifactId>micrometer-core</artifactId> </dependency> - 已配置的
application.yml(存在语法错误):management: metrics: enable: jvm: true all: true export: prometheus: enabled: true endpoints: web: exposure: include: "*" cors: allowed-methods: GET,POST allowed-origins: ${ALLOWED_ORIGINS:https://abc-xyz.rst.net endpoint: shutdown: enabled: true metrics: enabled: true springfox: documentation: swagger-ui: enabled: true security: enabled: true
解决步骤
修复application.yml语法错误
你的配置里allowed-origins末尾少了闭合双引号,这会导致配置加载失败,直接影响所有Actuator相关配置生效。修正后:allowed-origins: ${ALLOWED_ORIGINS:https://abc-xyz.rst.net}确保WebSecurityConfig放行Actuator端点
因为你的WebSecurityConfig继承了WebSecurityConfigurerAdapter,如果没有明确放行Actuator端点,请求会被拦截,导致无法获取完整指标。在configure(HttpSecurity http)方法中添加:@Override protected void configure(HttpSecurity http) throws Exception { // 保留原有配置,新增以下放行规则 http.authorizeRequests() .antMatchers("/actuator/**").permitAll() .anyRequest().authenticated(); // 如果开启了CSRF,需要忽略Actuator端点 http.csrf().ignoringAntMatchers("/actuator/**"); }显式启用JVM GC相关指标
Spring Boot 2.5.x中,jvm.memory.usage.after.gc.percent属于GC细分指标,仅配置jvm: true可能无法覆盖。在application.yml中补充:management: metrics: enable: jvm.gc: true统一Micrometer依赖版本
Spring Boot 2.5.6默认适配Micrometer 1.7.x,你单独指定依赖版本可能导致冲突。建议移除micrometer-core依赖(会被自动引入),并去掉版本号,让Spring Boot管理版本:<dependency> <groupId>io.micrometer</groupId> <artifactId>micrometer-registry-prometheus</artifactId> </dependency>验证指标的正确访问路径
注意Micrometer的指标名称是点分隔而非下划线,正确的访问路径是/actuator/metrics/jvm.memory.usage.after.gc.percent,而不是你写的下划线格式。也可以通过/actuator/prometheus端点查看所有Prometheus格式的指标,确认该指标是否存在。
内容的提问来源于stack exchange,提问作者Tanu
相关产品推荐
相关产品推荐

