【问题标题】:Turn off selected spring boot system metrics关闭选定的 Spring Boot 系统指标
【发布时间】:2018-02-28 05:17:10
【问题描述】:
目前 Spring Boot 执行器指标返回各种系统参数的指标。我想打开一些选定的指标参数,例如;仅显示与内存和处理器相关的指标。我曾多次尝试找出解决方案,但对我没有任何帮助。我看到SystemPublicMetrics注册了所有的基本系统指标和管理系统矩阵,我怎么只打开其中的几个?
需要的输出:
{
"mem": 495055,
"mem.free": 372397,
"processors": 4
}
【问题讨论】:
标签:
java
spring-boot
spring-boot-actuator
【解决方案1】:
您将无法禁用特定指标。相反,您将只能在端点启用/禁用。
以下是您可以在 application.properties 中添加的标志,以启用/禁用 Spring Boot Actuator 中的特定端点
endpoints.autoconfig.enabled=false
endpoints.beans.enabled=false
endpoints.configprops.enabled=false
endpoints.dump.enabled=false
endpoints.env.enabled=false
endpoints.health.enabled=true
endpoints.info.enabled=true
endpoints.metrics.enabled=false
endpoints.mappings.enabled=false
endpoints.shutdown.enabled=false
endpoints.trace.enabled=false
【解决方案2】:
您可以通过将指标类添加到排除列表来禁用启动时 Spring Boot 自动配置的 CacheMetricsAutoConfiguration。
例如要禁用缓存指标,请在启动时添加以下内容:
导入 org.springframework.boot.actuate.autoconfigure.metrics.cache.CacheMetricsAutoConfiguration;
@EnableAutoConfiguration(排除 = {CacheMetricsAutoConfiguration.class})
公共类应用程序扩展 SpringBootServletInitializer {
...
...
这应该会有所帮助..