How to implement a custom Spring-Boot Application HealthIndicator

For those who use Spring-Boot or even better JHipster as based stack for their Java Enterprise Application, you are probably familiar with Spring-Boot « health » endpoint within Actuator project.


If you want to read more about those endpoints, here is the only doc:

By default there are few health indicators (mail and database servers connectivity and free disk space) around which JHipster built a web interface.

Here i’m about to add a new health indicator to this monitoring page. In deed the application for which i integrated this change is an SMS and Call Scheduling web application that i built for a Research & Development Institute. This application interacts with two external APIs

  • a REST API provided by the Interactive Voice & Call Center platform i also develop ( for the phone calls
  • a simple HTTP API provided by an SMS provider for (no surprise) the SMS

I needed to have a view on the availability of those APIs, absolutely necessary to global value delivery, to the health endpoint (and web page)

Now better than words, let’s see some codes 🙂 (the whole classes are here on Github

* @author zoumana
* @since 20160612
* AfricaSys custom HealthIndicator check for our FAI SMS provider APIs
public class SMSProviderHealthIndicator extends AbstractHealthIndicator {

private final Logger log = LoggerFactory.getLogger(SMSProviderHealthIndicator.class);
private ContactService contactService;

public SMSProviderHealthIndicator(ContactService contactService) {
Assert.notNull(contactService, "contactService must not be null");
this.contactService = contactService;

protected void doHealthCheck(Health.Builder builder) throws Exception {
log.debug("Initializing SMSProvider health indicator");
try {

} catch (Exception e) {
log.debug("Cannot connect to SMS API server. Error: {}", e.getMessage());

This is how it looks like on JHipster health web page (i shutdown the internet connectivity on my development environment of course :-)) to simulate outage. You can see that i can even view the exception


What is cool about this « health » REST endpoints, is that we can easily write probes and integrate them within our existing monitoring application (such as Nagio, Centreon, Chicken…). You just have to query the health check result as Sping-Boot is already taking care of regular checks runs.


2 réactions sur “How to implement a custom Spring-Boot Application HealthIndicator

Votre commentaire

Entrez vos coordonnées ci-dessous ou cliquez sur une icône pour vous connecter:


Vous commentez à l’aide de votre compte Déconnexion /  Changer )

Image Twitter

Vous commentez à l’aide de votre compte Twitter. Déconnexion /  Changer )

Photo Facebook

Vous commentez à l’aide de votre compte Facebook. Déconnexion /  Changer )

Connexion à %s