使用 spring boot 2.5.6 版本时缺少 jvm 配置项

2.5.6我正在使用带有版本和springfox-boot-starter版本的Spring Boot 项目3.0.0。我的项目还包括一个WebSecurityConfig扩展WebSecurityConfigurerAdapter 并实现WebMvcConfigurer 的类。但是,我面临的问题是指标在端点jvm_memory_usage_after_gc_percent中不可见/actuator/metrics

我们也不能删除"springfox-boot-starter",因为我们的应用程序中需要 swagger。

为了在 /actuator/metrics 端点中启用 jvm_memory_usage_after_gc_percent 指标,我尝试添加以下依赖项:

lang-java 复制代码
<dependency>             
    <groupId>io.micrometer</groupId>             
    <artifactId>micrometer-registry-prometheus</artifactId>         
</dependency>         
<dependency>            
    <groupId>io.micrometer</groupId>             
    <artifactId>micrometer-core</artifactId>         
</dependency>

我还将 application.yml 配置更新为:

lang-java 复制代码
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

尽管进行了这些更改,但jvm_memory_usage_after_gc_percent指标仍然不可见。

经过排查发现是jvm.memory.usage.after.gc其中的一部分JvmHeapPressureMetrics,在使用的 Spring Boot 版本中默认情况下未注册。

手动将其注册为一个 bean。

lang-java 复制代码
@Bean
public JvmHeapPressureMetrics jvmHeapPressureMetrics() {
  return new JvmHeapPressureMetrics();
}

此注册已在 Spring Boot 2.6.0 版本中添加。

相关推荐
LucianaiB5 分钟前
我用豆包工作 Seed-2.1-pro,复刻了 QQ 时代爆红的魔术图片
后端
码事漫谈10 分钟前
智谱 ZCode 静默上传 Git 历史:48 小时信任危机复盘
后端
掘金码甲哥31 分钟前
当对话模型遇上向量模型,vllm production stack 又该如何应对?
后端
传奇开心果编程1 小时前
【springboot基础语法学与练】第 1 课:从零开始
java·spring boot·后端·学习
IT_陈寒1 小时前
Java线程池用错参数,我的服务居然悄悄崩溃了
前端·人工智能·后端
光影少年1 小时前
Express 中间件原理
后端·node.js·express
aramae2 小时前
MySQL内置函数(7)
开发语言·笔记·后端·mysql·其他
徐小夕3 小时前
存量.doc 文档怎么办?JitWord 开源转换库打通旧文档到在线协同全链路
后端·架构·github
ee又momo3 小时前
一次 JWT Token 过期续期的踩坑记录
后端
二月龙3 小时前
App 瘦身实战:图片、so 库、资源压缩,安装包体积减小 40%
后端