Spring Boot Actuators 仅暴露有限的端点

问题描述 投票:0回答:1

我正在尝试在 Spring Boot 2.3 服务中公开其他执行器端点。尝试添加端点(例如普罗米修斯)和监控指标。但由于某种原因,暴露的端点被锁定到默认记录器、健康、信息。

对于某些背景,在组织内,有一个父 Spring 依赖项,它自动带来所有 Spring 必需品,以及一些在组织内有用的通用代码。我在许多其他项目中使用了这种依赖关系,并且能够成功公开这些额外的执行器端点。但是,在这个具有多个工件的项目中,我无法编辑默认公开的执行器端点。

打印

configurableEnvironment
初始化后始终显示曝光属性,如下

management.endpoints.web.exposure.include = loggers,health,info

这是在尝试使用以下方法将此属性覆盖到扩展列表(记录器,健康,信息,Prometheus,metrics)之后:

  • 通过
    management.endpoint.metrics.enabled: true
  • 启用特定端点
  • 在 application.yaml 中指定这些值
  • 将其作为命令行参数传递
    Dmanagement.endpoints.web.exposure.include=loggers,health,info,prometheus,metrics
  • 使用
    mvn dependency:tree
    排除任何传递执行器依赖性

我不认为这是由于组织的父 pom 造成的,可能是由于我们正在使用的另一个依赖项造成的。但由于该项目的规模,很难删除依赖项来进行测试。有什么方法可以追踪这些属性的设置位置。或者也许有其他方法可以强制暴露我想要的其他端点?

——

执行器配置

management:
  endpoints:
    web:
      exposure:
        include: metrics,prometheus,info,health,logging
  endpoint:
    env:
      enabled: true
    metrics:
      enabled: true
    info:
      enabled: true
    health:
      enabled: true
      show-details: always
    beans:
      enabled: true
    caches:
      enabled: true
    threaddump:
      enabled: true
    prometheus:
      enabled: true

执行器信息

{"_links":{"self":{"href":"http://localhost:9050/actuator","templated":false},"health":{"href":"http://localhost:9050/actuator/health","templated":false},"health-path":{"href":"http://localhost:9050/actuator/health/{*path}","templated":true},"info":{"href":"http://localhost:9050/actuator/info","templated":false},"loggers":{"href":"http://localhost:9050/actuator/loggers","templated":false},"loggers-name":{"href":"http://localhost:9050/actuator/loggers/{name}","templated":true}}}

java spring spring-boot spring-boot-actuator
1个回答
0
投票

您的问题缺乏一些背景知识,例如您的 pom.xml 或 build.gradle 文件以及完整的 application.yml 配置。

我将完成您可能错过的基本步骤。

首先,请确保您已包含 Prometheus 依赖项:

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

另外,不要忘记某些指标需要 AOP 依赖项(例如自定义计时器):

<dependency>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-starter-aop</artifactId>
</dependency>

要启用 Prometheus 指标公开,您应该在 application.yml 文件中指定此类配置(看起来您做得正确,但让我们在此处列出它以获得完整图片):

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

要验证 Prometheus 端点是否已公开,请使用对此 URL 的 GET 请求:

http://localhost:8080/actuator/prometheus

如果这些步骤不能帮助您解决问题,请在您的问题中添加更多详细信息。

© www.soinside.com 2019 - 2024. All rights reserved.