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

相关推荐
{{uname}}8 小时前
利用WebSocket实现实时通知
网络·spring boot·websocket·网络协议
小马爱打代码8 小时前
Minor GC与Full GC分别在什么时候发生?
jvm
goTsHgo9 小时前
Spring Boot 自动装配原理详解
java·spring boot
炒空心菜菜10 小时前
SparkSQL 连接 MySQL 并添加新数据:实战指南
大数据·开发语言·数据库·后端·mysql·spark
alden_ygq11 小时前
当java进程内存使用超过jvm设置大小会发生什么?
java·开发语言·jvm
蜗牛沐雨12 小时前
Rust 中的 `PartialEq` 和 `Eq`:深入解析与应用
开发语言·后端·rust
Python私教12 小时前
Rust快速入门:从零到实战指南
开发语言·后端·rust
秋野酱13 小时前
基于javaweb的SpringBoot爱游旅行平台设计和实现(源码+文档+部署讲解)
java·spring boot·后端
小明.杨13 小时前
Django 中时区的理解
后端·python·django
有梦想的攻城狮13 小时前
spring中的@Async注解详解
java·后端·spring·异步·async注解