首页 > 解决方案 > 如何在 Spring-Boot 中禁用指标?

问题描述

我使用 DropWizard 来收集我自己的端点指标。我喜欢我的解决方案,因为我可以根据需要添加自己的尺寸。

除了这个 Spring 自动收集并向 Dropwizard 添加我不需要的其他指标数据。如何禁用 Spring-Boot 中的指标以禁用此功能?

我找到了MetricsDropwizardAutoConfiguration.classDropwizardMetricServices.class但似乎没有一个属性或配置可以关闭它们。

所以我的下一个想法是关闭 Spring-Boot-Actuator 的指标。我在调试时发现了这些 application.properties,但这些并没有关闭指标日志记录:

endpoints:
  metrics:
    enabled: false
management.endpoints.metrics.enabled: false
spring:
  metrics:
    export:
      enabled: false

编辑

springBootVersion = '1.5.9.RELEASE'

标签: springspring-bootspring-boot-actuator

解决方案


对于1.5.9这些应该工作:

endpoints.enabled=false # Enable endpoints.
endpoints.actuator.enabled=false # Enable the endpoint.

这应该在 2.x 中工作:

在应用程序属性中:

management.endpoint.metrics.enabled=false

在 yaml 中:

management:
  endpoint:
    metrics:
      enabled: false

推荐阅读