使用 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 指标,我尝试添加以下依赖项:

<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

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

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

手动将其注册为一个 bean。

@Bean
public JvmHeapPressureMetrics jvmHeapPressureMetrics() {
  return new JvmHeapPressureMetrics();
}

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

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

肉三

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值