使用 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 版本中添加。

相关推荐
biubiubiu070618 小时前
SpringBoot 3.5.4 整合Quartz 定时任务
java·spring boot·spring
copyer_xyf18 小时前
Python 内存分析:从栈和堆理解对象引用
前端·后端·python
可乐ea19 小时前
【知识获取与分享社区项目 | 项目日记第 19 天】基于 Elasticsearch 实现关键词检索与业务权重排序
java·大数据·spring boot·mysql·elasticsearch·搜索引擎·全文检索
金銀銅鐵19 小时前
用 Tkinter 实现一个简单的罗马数字转化工具
后端·python
RemainderTime19 小时前
Spring Boot脚手架集成 Spring Security实现生产级RBAC鉴权
spring boot·后端·spring
宸津-代码粉碎机20 小时前
Spring AI企业级Agent实战|多工具自动规划+并行调度落地,彻底解决复杂业务AI任务编排问题
java·大数据·人工智能·spring boot·python·spring
biubiubiu070620 小时前
自定义starter 可以导入SpringBoot直接使用
java·spring boot·spring
用户23307130747920 小时前
对象的一生(上)
后端
爱勇宝20 小时前
如何评估 AI 大模型的商业价值?
前端·后端·程序员
小刘|20 小时前
SpringBoot整合LangChain4j实现流式AI对话
java·spring boot·langchain