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

相关推荐
CQU_JIAKE6 小时前
11.7[高体】
java·后端·spring
Csvn6 小时前
认识 Nginx
后端·nginx
红尘散仙7 小时前
谁说终端只能敲键盘?我用 Rust 给小说阅读器加上了鼠标
前端·后端·rust
特立独行的猫A7 小时前
我给女儿写了个打字练习:一边敲键盘,一边把小学英语单词记牢
java·后端·python
陈随易8 小时前
C++26 草案被否,二十八年来头一回
前端·后端·程序员
金銀銅鐵9 小时前
同一个 Hello World,Kotlin 和 Java 在字节码层面差在哪
jvm·后端·kotlin
IT_陈寒11 小时前
Redis内存暴涨,没想到是AOF重写捣的鬼
前端·人工智能·后端
ikoala11 小时前
让 Codex 自己查账:一个省 token 的小技巧
前端·后端·ai编程
计算机毕设定制辅导-无忧学长13 小时前
《基于微信小程序的居家医疗陪护预约系统设计与实现》
java·spring boot·微信小程序·uniapp·居家医疗陪护预约系统
wo_jack15 小时前
C++ 入门笔记(十六):第16课 vector 模拟实现十问十答 —— 从三指针到迭代器失效
c++·后端·面试·stl·vector