如何在 Spring-Boot 中禁用指标?

How to disable metrics in Spring-Boot?

我使用 DropWizard 收集我自己的端点指标。我喜欢我的解决方案,因为我可以根据需要向其中添加自己的维度。

除此之外 Spring 自动收集额外的指标数据并将其添加到我不需要的 Dropwizard。如何在 Spring-Boot 中禁用指标以禁用此功能?

我找到了 MetricsDropwizardAutoConfiguration.classDropwizardMetricServices.class,但是 none 似乎有一个 属性 或配置来关闭它们。

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

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

编辑

springBootVersion = '1.5.9.RELEASE'

对于 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

我的解决方案是禁用自动配置:MetricsDropwizardAutoConfiguration.class 使用 @SpringBootApplication(exclude = MetricsDropwizardAutoConfiguration.class})。这样我就不得不引入自己的MetricRegistry @Bean.