Health information

As with the /info endpoint, there are also some auto-configured indicators for the /health endpoint. We can monitor the status of disk usage, mail service, JMS, data sources, and NoSQL databases, such as MongoDB or Cassandra. If you check out that endpoint from our sample application, you only get the information about disk usage. Let's add MongoDB to the project to test one of the available health indicators, MongoHealthIndicator. MongoDB is not a random selection. It will be useful for us in the future for a more advanced example of the Person microservice. To enable MongoDB use, we need to add the following dependencies to pom.xml. The de.flapdoodle.embed.mongo artifact is responsible for starting the embedded database instance during application startup:

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-mongodb</artifactId>
</dependency>
<dependency>
<groupId>de.flapdoodle.embed</groupId>
<artifactId>de.flapdoodle.embed.mongo</artifactId>
</dependency>

Now, the /health endpoint returns information about disk usage and MongoDB status:

{
"status":"UP",
"diskSpace":{
"status":"UP",
"total":499808989184,
"free":193956904960,
"threshold":10485760
},
"mongo":{
"status":"UP",
"version":"3.2.2"
}
}

In this example, we can see the power of Spring Boot auto-configuration. We didn't have to do anything more than include two dependencies to the project to enable embedded MongoDB. Its status has been automatically added to the /health endpoint. It also has a ready-to-use client connection to Mongo, which can be further used by the repository bean.