【问题标题】:Metrics don't show up on the /prometheus endpoint指标未显示在 /prometheus 端点上
【发布时间】:2018-05-02 23:04:56
【问题描述】:

我有两个服务,pingpong,其中pingpong 发送请求。此指标显示在ping 服务的/metrics 端点上:

gauge.servo.hystrix.hystrixcommand.http://pong.pongclient#hello().90

但它没有出现在/prometheus 端点上。其他指标出现在此端点上,但没有包含有关 Feign/Hystrix http 请求信息的伺服指标。

如何让这些指标显示在/prometheus 端点上?

我的build.gradle 有以下依赖项

compile 'org.springframework.boot:spring-boot-starter-web'
compile 'org.springframework.boot:spring-boot-starter-actuator'
compile 'org.springframework.cloud:spring-cloud-starter-eureka'
compile 'org.springframework.cloud:spring-cloud-starter-hystrix'
compile 'org.springframework.cloud:spring-cloud-starter-feign'
compile 'org.springframework.retry:spring-retry'
compile "io.micrometer:micrometer-core:${micrometerVersion}"
compile "io.micrometer:micrometer-spring-legacy:${micrometerVersion}"
compile "io.micrometer:micrometer-registry-prometheus:${micrometerVersion}"

以下版本

springCloudVersion = 'Dalston.SR4'
micrometerVersion = '1.0.0-rc.4'

代码可以在这里找到https://github.com/fiunchinho/spring-resiliency

【问题讨论】:

标签: spring-boot spring-cloud hystrix prometheus micrometer


【解决方案1】:

Hystrix需要手动添加插件:

HystrixPlugins.getInstance().registerMetricsPublisher(new MicrometerMetricsPublisher(Metrics.globalRegistry));

您可以将其添加到配置中的@PostConstruct

我创建了https://github.com/micrometer-metrics/micrometer/issues/237 来解决未来的缺点。

【讨论】:

    【解决方案2】:

    checketts 的 answer 对我不起作用,并在启动时抛出了 java.lang.IllegalStateException: Another strategy was already registered.,但添加了 HystrixMetricsBinder bean,它在内部或多或少地完成了相同的操作。

    @Configuration
    public class MetricsConfig {
    
      @Bean
      HystrixMetricsBinder registerHystrixMetricsBinder() {
        return new HystrixMetricsBinder();
      }
    }
    

    取自https://stackoverflow.com/a/52740957/60518

    【讨论】:

      【解决方案3】:

      您需要检测和配置 Spring Boot 服务以使用 Prometheus 进行监控,如下所示:

      1. 您需要在 gradle.build 文件中包含一个依赖项
      2. 您需要实现 Metric 端点​​
      3. 您需要从 Prometheus JVM 添加标准导出器

      有关如何执行此操作的更多实施细节,请参阅示例 herehere

      【讨论】:

      • 明确一点:我在 /prometheus 端点上看到了指标。只是我没有看到 servo 指标,其中包含有关使用 Feign/Hystrix 发出的 http 请求的信息。
      • 这都是通过他使用micrometer-spring-legacy来解决的。 Micrometer.io 将成为未来监控 Spring 应用程序的首选方式,因为它已融入 SpringBoot 2。
      • 这个答案并没有具体解决有关 Hystrix 指标未显示的问题,并且两个示例都没有引用 Hystrix。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-11-12
      • 1970-01-01
      • 1970-01-01
      • 2020-02-07
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多