Reputation: 55
Suppose I have an API which calls another API and I want to have a health check of this endpoint as well. Is this possible with Actuator or do I need to write custom code?
Upvotes: 1
Views: 836
Reputation: 2280
You can implement custom health indicator by implementing org.springframework.boot.actuate.health.HealthIndicator
and adding it as bean in spring context. Something like below should get you started:
@Component
public class CustomHealthCheck implements HealthIndicator {
@Override
public Health health() {
int errorCode = check();
if (errorCode != 0) {
return Health.down()
.withDetail("Error Code", errorCode).build();
}
return Health.up().build();
}
public int check() {
// Custom logic to check health
return 0;
}
}
Upvotes: 1