0

SpringBoot v2.5.1

我希望所有执行器端点(在文档中描述)都可用。在docs之后,添加了执行器启动器依赖项和属性,但大多数端点不可用(HTTP 404)。

唯一可用的端点是GET /actuator/health,但它显示了无用的信息:{"status": "UP"}

添加属性management.endpoints.enabled-by-default=true

添加依赖:

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

的结果GET /actuator

{
    "_links": {
        "self": {
            "href": "http://localhost:9999/actuator",
            "templated": false
        },
        "health-path": {
            "href": "http://localhost:9999/actuator/health/{*path}",
            "templated": true
        },
        "health": {
            "href": "http://localhost:9999/actuator/health",
            "templated": false
        }
    }
}

启用执行器端点的最小设置是什么?

4

1 回答 1

0

在文件中添加micrometer-core和依赖项:micrometer-registry-prometheuspom.xml

<!-- Spring boot actuator to expose metrics endpoint -->
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-actuator</artifactId>
</dependency>

<!-- Micormeter core dependecy -->
<dependency>
    <groupId>io.micrometer</groupId>
    <artifactId>micrometer-core</artifactId>
</dependency>

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

application.properties文件中添加以下属性:

#Metrics related configurations
management.endpoint.metrics.enabled          = true
management.endpoints.web.exposure.include    = *
management.endpoint.prometheus.enabled       = true
management.metrics.export.prometheus.enabled = true

如果您需要通过 HTTP 公开所有内容,则需要management.endpoints.web.exposure.include如上例所示进行设置。在您的代码中,此属性缺失。如果您希望公开特定端点,请参考spring 文档。我还在上面的示例中添加了依赖项,这些依赖项是公开prometheus相关端点所必需的。

于 2021-06-17T13:51:22.170 回答