1
votes

When using Spring Boot health actuator
http://localhost:8080/health

{"status":"UP","diskSpace":{"status":"UP","total":122588196864,"free":59227926528,"threshold":10485760},"mongo":{"status":"UP","version":"3.2.6"}}


Now I want to check for other condition, so as to check dependent action are triggered when status is down. I want something like

{"status":"Down"}
2

2 Answers

2
votes

You can write your custom 'Health Indicator' which would override the default Health Indicator and write your implementation (e.g. Always return status as down).

Now, as this is only needed to test the app, I would recommend annotating this with @Profile so that it only gets activated when the app is started with let's say test profile, e.g.:

@Component
@Profile("test")
public class MyHealthIndicator implements HealthIndicator {

By this way, if you start the app with any profile other than test, default HealthIndicator will be used.

0
votes

First disable the default /health endpoint or customize it to some different endpoint. You can disable it follow

endpoints.health.disabled=true 

Once this is disabled, implement your own custom endpoints at /health and define your custom conditions with whatever you like to check.

You can take a look here for creating custom endpoints Don't forget to use test profile while creating custom endpoint