【问题标题】:How to exclude Hystrix Metrics from the Actuator /metrics endpoint?如何从 Actuator /metrics 端点中排除 Hystrix Metrics?
【发布时间】:2016-04-26 02:14:09
【问题描述】:

我有一个启用了 Actuator 和 Hystrix 的 spring-boot-app。
Spring-Boot-版本:1.3.1.RELEASE

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-eureka</artifactId>
</dependency>
<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-hystrix</artifactId>
</dependency>

当我将@HystrixCommand添加到某些方法时,/metrics Endpoint 会显示来自 hystrix 的所有指标:

gauge.hystrix.HystrixCommand.RestEndpoints.TestController.test.errorPercentage: 0,
gauge.hystrix.HystrixThreadPool.RestEndpoints.rollingMaxActiveThreads: 1,
...

问题:
如何从/metricsendpoint 中完全排除 hystrix-metrics?


更新 1
我试图用这些方法排除 ServoMetrics 和 SpectatorMetrics:

1)

@EnableAutoConfiguration(exclude={ServoMetricsAutoConfiguration.class,
 SpectatorMetricsAutoConfiguration.class} )

2)

@SpringBootApplication(exclude={ServoMetricServices.class, SpectatorMetricServices.class})

但两者都没有达到预期的效果。

【问题讨论】:

  • 目前无法排除它们,除非您从依赖项中排除 com.netflix.hystrix:hystrix-metrics-event-stream,这也会导致 /hystrix.stream 也停止工作。
  • @spencergibb 感谢您的澄清。太糟糕了......这可能值得一个功能请求......
  • 完成,看我的新答案。
  • 哇,真快!谢谢你一千次!

标签: spring spring-boot spring-cloud hystrix spring-boot-actuator


【解决方案1】:

issue 已创建并已修复。在快照中,您现在可以设置以下内容: hystrix.metrics.enabled=false.

【讨论】:

  • 在 Spring 代码/配置中有效地设置这个参数并不是很简单。但是将其设置为系统变量可以正常工作。
【解决方案2】:

如果您不想要任何其他指标,更好的解决方案是创建自己的 MetricsRegistry。这样,未来的任何其他代码更改(添加更多具有更多内置指标的 jar)都不会受到影响。

@Configuration
public class MetricsConfiguration {

  private MetricRegistry metricRegistry;

  MetricsConfiguration() {
    //avoid other metrics already registered
    metricRegistry = new MetricRegistry();
  }

}

注意:创建 MetricRegistry 类型的 @Bean 没有帮助,因为 Spring 自动配置将使用此 Bean 对象而不是 MetricsRegistry object from MetricsDropwizardAutoConfiguration.java

【讨论】:

    猜你喜欢
    • 2019-06-21
    • 2017-07-19
    • 1970-01-01
    • 1970-01-01
    • 2023-03-08
    • 2017-11-11
    • 2018-07-05
    • 2021-09-12
    • 1970-01-01
    相关资源
    最近更新 更多