Prometheus 端点不工作 Spring Boot 2.0.0.RC1 Spring Webflux 已启用

Prometheus Endpoint Not Working Spring Boot 2.0.0.RC1 Spring Webflux enabled

我遵循了此处的文档 (https://docs.spring.io/spring-boot/docs/2.0.0.RC1/reference/htmlsingle/#production-ready-endpoints-enabling-endpoints) 并确保 application.yml 文件具有以下

management:
  metrics:
    export:
      prometheus:
        enabled: true
  endpoints:
    web:
      expose:
        health, info, httptrace, metrics, threaddump, mappings, prometheus

根据文档 (https://docs.spring.io/spring-boot/docs/current-SNAPSHOT/actuator-api/html/#prometheus),以下内容不起作用。

curl 'http://localhost:8080/actuator/prometheus' -i

我收到 404 未找到处理程序映射异常。有人可以让我知道如何为抓取目的启用普罗米修斯端点以及我需要使用什么 URL 端点来测试它吗?

o.s.w.r.r.m.a.RequestMappingHandlerMapping[276] - Did not find handler method for [/actuator/prometheus]

所有其他端点运行状况、信息、httptrace、threaddump、映射都运行良好。

您可以检查一些内容:

  1. 您是否添加了必要的 MeterRegistry 实现,以便存在 Micrometer 检测库的 Prometheus "subsystem"? (从 Spring Boot 2.0 开始,Micrometer 库为 Actuator 实现提供支持)

    <dependency>
        <groupId>io.micrometer</groupId>
        <artifactId>micrometer-registry-prometheus</artifactId>
    </dependency>
    

    如果没有特定的 MeterRegistry 实施,您最终会得到由 SimpleMeterRegistry 实施提供支持的常规 /actuator/metrics 端点。

  2. 您是否真的将提到的属性放在 application.[yml,yaml] 文件而不是 application.properties 中? (我只是偶然发现了一个用 Spring Initializr 生成的新演示项目。)

我遇到了同样的问题,并通过在配置中添加 "include" 标签设法解决了这个问题:

management:
  metrics:
    export:
      prometheus:
        enabled: true
  endpoints:
    web:
      exposure:
        include: prometheus,info,metrics,threaddump

有点晚了 - 但只是为了记录 - 我可以验证这在 2.0 中现在有效。0.RELEASE。

依赖关系(gradle):

compile('org.springframework.boot:spring-boot-starter-web')
compile('org.springframework.boot:spring-boot-starter-actuator')
compile('io.micrometer:micrometer-registry-prometheus')

application.yaml (reference)

management:
  endpoints:
    web:
      exposure:
        include: health,info,prometheus

我还用 RC1 进行了测试——由于某种原因,prometheus 端点没有出现——就像@ROCKY 解释的那样。

我将应用程序从 1.5 升级到 2.1.3 时遇到了同样的问题。能够按照此 Spring Boot 2.0 Prometheus Backward Compatibility

修复它

您需要 micrometer-registry-prometheus 在您的依赖项列表中并将以下添加到您的 SpringBootApplication class

@Bean
public CollectorRegistry collectorRegistry() {
    return CollectorRegistry.defaultRegistry;
}

spring 默认情况下启动不会公开 prometheus 端点,即使您的类路径中有 >micrometer-registry-prometheus

<dependency>
            <groupId>io.micrometer</groupId>
            <artifactId>micrometer-registry-prometheus</artifactId>
    </dependency>  

您需要明确告诉 spring 启动以在 属性 下方公开 prometheus 端点。

management.endpoints.web.exposure.include=health,info,metrics,prometheus