简体   繁体   English

将弹簧引导执行器运行状况端点更改为自定义端点

[英]Changing spring boot actuator health end point to a custom end point

Is it possible to change the spring boot actuator health end point to a custom end point?是否可以将弹簧靴执行器健康端点更改为自定义端点? Something like the below.像下面这样的东西。

http://localhost:8080/actuator/health http://localhost:8080/actuator/health

to

http://localhost:8080/myapp/apphealth http://localhost:8080/myapp/apphealth

Wanted only the name change but not the response of the actuator/health.只想更改名称,而不是执行器/健康的响应。 Is it possible?是否可以?

Yes , it is possible.是的,这是可能的。

How to customize the paths to your actuator endpoints is defined in this section of the documentation.文档的这一部分定义了如何自定义执行器端点的路径。

The documentation states:该文件指出:

If you want to map endpoints to a different path, you can use the management.endpoints.web.path-mapping property.如果要将端点映射到不同的路径,可以使用 management.endpoints.web.path-mapping 属性。

The following example remaps /actuator/health to /healthcheck:以下示例将 /actuator/health 重新映射到 /healthcheck:

application.properties.应用程序属性。

management.endpoints.web.base-path=/ management.endpoints.web.base-path=/

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

So, in your case you want:所以,在你的情况下,你想要:

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

The answers given here, have already provided the solution for this question.这里给出的答案,已经为这个问题提供了解决方案。 But, I was struggling in customising the actuator health endpoint for different purposes, and I would like to share my findings to help someone else as well.但是,我在为不同目的定制执行器健康端点时遇到了困难,我想分享我的发现以帮助其他人。 All examples below are for Spring Boot 2.x .以下所有示例均适用于Spring Boot 2.x

The default actuator health endpoint would be http://localhost:8080/actuator/health .默认的执行器健康端点是http://localhost:8080/actuator/health


Option 1: Change /actuator/health to be a Custom Path like /actuator/test选项 1:将/actuator/health更改为自定义路径,例如/actuator/test

Add the following to your application.properties file将以下内容添加到您的application.properties文件中

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

the path would be: http://localhost:8080/actuator/test路径将是: http://localhost:8080/actuator/test


Option 2: Change /actuator/health to be a Custom Path like /myapp/test选项 2:将/actuator/health更改为自定义路径,例如/myapp/test

Add the following to your application.properties file将以下内容添加到您的application.properties文件中

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

the path would be: http://localhost:8080/myapp/test路径将是: http://localhost:8080/myapp/test


Option 3: Change /actuator/health to be a Custom Path like /health选项 3:将/actuator/health更改为自定义路径,例如/health

Add the following to your application.properties file将以下内容添加到您的application.properties文件中

-- application.properties --
management.endpoints.web.base-path=/

the path would be: http://localhost:8080/health路径是: http://localhost:8080/health


Option 4: Change /actuator/health to be a Custom Path like /test选项 4:将/actuator/health更改为自定义路径,例如/test

Add the following to your application.properties file将以下内容添加到您的application.properties文件中

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

the path would be: http://localhost:8080/test路径将是: http://localhost:8080/test


Option 5: Change Port from 8080 to custom port like 8081选项 5:将端口从8080更改为8081等自定义端口

Add the following to your application.properties file.将以下内容添加到您的application.properties文件中。 The main application will run on Port 8080 .主应用程序将在端口8080上运行。

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

the path would be: http://localhost:8081/actuator/health路径将是: http://localhost:8081/actuator/health

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM