Reputation: 35264
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
to
http://localhost:8080/myapp/apphealth
Wanted only the name change but not the response of the actuator/health. Is it possible?
Upvotes: 25
Views: 30221
Reputation: 13572
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
.
The default actuator health endpoint would be http://localhost:8080/actuator/health.
Option 1: Change /actuator/health
to be a Custom Path like /actuator/test
Add the following to your application.properties
file
-- application.properties --
management.endpoints.web.path-mapping.health=test
the path would be: http://localhost:8080/actuator/test
Option 2: Change /actuator/health
to be a Custom Path like /myapp/test
Add the following to your application.properties
file
-- application.properties --
management.endpoints.web.base-path=/myapp
management.endpoints.web.path-mapping.health=test
the path would be: http://localhost:8080/myapp/test
Option 3: Change /actuator/health
to be a Custom Path like /health
Add the following to your application.properties
file
-- application.properties --
management.endpoints.web.base-path=/
the path would be: http://localhost:8080/health
Option 4: Change /actuator/health
to be a Custom Path like /test
Add the following to your application.properties
file
-- application.properties --
management.endpoints.web.base-path=/
management.endpoints.web.path-mapping.health=test
the path would be: http://localhost:8080/test
Option 5: Change Port from 8080
to custom port like 8081
Add the following to your application.properties
file. The main application will run on Port 8080
.
-- application.properties --
management.server.port=8081
the path would be: http://localhost:8081/actuator/health
Upvotes: 26
Reputation: 12751
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.
The following example remaps /actuator/health to /healthcheck:
application.properties.
management.endpoints.web.base-path=/
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
Upvotes: 35