将Spring Boot Actuator健康检查端点更改为自定义端点

20

可能是Prometheus Actuator的自定义路径的重复问题。 - Vlad Mamaev
2个回答

29

是的,这是可能的。

如何自定义您的执行器端点路径在文档的这个部分中有定义。

文档说明:

如果您想将端点映射到不同的路径,则可以使用management.endpoints.web.path-mapping属性。

以下示例将/actuator/health重新映射为/healthcheck:

application.properties.

management.endpoints.web.base-path=/

management.endpoints.web.path-mapping.health=healthcheck

所以,在您的情况下,您需要:

-- application.properties --
management.endpoints.web.base-path=/myapp
management.endpoints.web.path-mapping.health=apphealth

19
这里已经给出了解决此问题的答案。但是,我在定制执行器健康端点方面遇到了困难,我想分享我的发现,以帮助其他人。以下所有示例都适用于Spring Boot 2.x。
默认的执行器健康端点将是http://localhost:8080/actuator/health

选项1:将/actuator/health更改为自定义路径,例如/actuator/test

将以下内容添加到您的application.properties文件中

-- application.properties --
management.endpoints.web.path-mapping.health=test

路径将会是:http://localhost:8080/actuator/test

选项2:将/actuator/health更改为自定义路径,例如/myapp/test

在您的application.properties文件中添加以下内容

-- application.properties --
management.endpoints.web.base-path=/myapp
management.endpoints.web.path-mapping.health=test

路径应该是:http://localhost:8080/myapp/test
选项三:将/actuator/health更改为像/health这样的自定义路径
在你的application.properties文件中添加以下内容。
-- application.properties --
management.endpoints.web.base-path=/

路径应该是: http://localhost:8080/health
选项4:将/actuator/health更改为自定义路径,例如/test 请在您的application.properties文件中添加以下内容。
-- application.properties --
management.endpoints.web.base-path=/
management.endpoints.web.path-mapping.health=test

路径应该是:http://localhost:8080/test

选项5:将端口从8080更改为自定义端口,如8081

将以下内容添加到您的application.properties文件中。主应用程序将在端口8080上运行。

-- application.properties --
management.server.port=8081

路径为:http://localhost:8081/actuator/health

是否可以保留/actuator作为所有端点的默认路径,除了 health端点?我希望只能为/actuator/*下的一个客户端提供安全访问,但是将"health"端点设置为"/health"并对所有人可访问。显然,通过大量手动配置步骤是可能的,但是否有简单的方法呢? - JoshGough

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接