1

I am trying to add custom functionality to health check endpoint. Created class according to this post :

@Component public class CustomHealthCheck extends AbstractHealthIndicator { @Override protected void doHealthCheck(Health.Builder builder) throws Exception { boolean someValue = true; if (someValue) { builder.withDetail("MyCustomField", "MyValue"); builder.up(); } else { builder.down(); } } } 

But when accessing to health endpoint via postman or via browser (/actuator/health) I got response

{ "status": "UP" } 

i.e. custom field was not added to the response I also see in debugger , that doHealthCheck method of CustomHealthCheck was executed

Here are relevant definitions from application.properties :

management.endpoints.enabled-by-default=true management.endpoint.health.enabled=true management.endpoint.info.enabled=true management.endpoints.web.exposure.include=health,info 

Is there something missing in the code or definitions ? Thanks in advance

0

1 Answer 1

1

By providing a bean implementing HealthIndicator, you contribute a custom health indicator, rather than overriding some default. The base /actuator/health then returns an aggregate over all registered beans, including yours.

Try naming your bean CustomHealthIndicator and you should be able to see your detail under /actuator/health/custom.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.