How to Visualise Spring Boot Actuator Health Indicators in Spring Boot Admin
The Spring Boot Admin project provides a user-friendly way to manage and monitor a Spring Boot application with very little effort.
The Spring Boot Admin project provides a user-friendly way to manage and monitor a Spring Boot application with very little effort.
Spring Boot Admin is a web application that helps you to monitor and manage a Spring Boot application. It can gather auditing, health and metric data. In this blogpost, we will first shed light on what a health indicator is and how to create a custom one. Next, we’re going to visualize our custom health indicator by means of Spring Boot Admin.
Health indicator
A Spring Boot Actuator Health Indicator provides health information of a Spring Boot Application. This health information is accessible at the /health endpoint and can be consumed by monitoring software. By default, multiple Health Indicators are auto-configured.
Custom health indicator
A custom health indicator can be defined by implementing the HealthIndicator interface. As an example, I created a BlogEnpointStatusHealthIndicator bean. This bean returns 2 values: “Health status” and “Up since”. The “Health status” property indicates whether our endpoint is up or not and the “Up Since” property indicates since when our endpoint has been up. These properties will automatically be added to the JSON of the /health endpoint:
@Component
public class BlogEndpointStatusHealthIndicator implements HealthIndicator {
private BlogService blogService;
@Override
public Health health() {
try {
Health.Builder healthBuilder;
healthBuilder = blogService.isBlogEndpointUp() ? Health.up() : Health.down();
DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ISO_DATE_TIME;
LocalDateTime availableSince = blogService.getAvailableSince();
return healthBuilder.withDetail("up since", uptime.format(dateTimeFormatter))
.build();
} catch (Exception e) {
return Health.down(e).build();
@Autowired
public void setBlogService(BlogService blogService) {
this.blogService = blogService;
}
Resulting JSON:
{
"status":"UP",
"blogEndpointStatus":{
"status":"UP",
"up since":"2017-06-26T15:56:28.574"
"diskSpace":{
"status":"UP",
"total":497687719936,
"free":201710972928,
"threshold":10485760
}
Spring Boot Admin
The Spring Boot Admin project simplifies the administration of Spring Boot applications by providing a simple user interface. In order to incorporate Spring Boot Admin into your application, you first need to set up a separate Spring Boot Admin server. This server will collect data from one or more Spring Boot Admin clients.
Setup Spring Boot Admin Server
To set up a Spring Boot Admin server, create a separate Spring Boot project. After your Spring Boot project has been created, add the following info to your pom.xml :
<dependency>
<groupId>de.codecentric</groupId>
<artifactId>spring-boot-admin-server</artifactId>
<version>1.5.2</version>
</dependency>
<dependency>
<groupId>de.codecentric</groupId>
<artifactId>spring-boot-admin-server-ui</artifactId>
<version>1.5.2</version>
</dependency>
Next, add the @EnableAdminServer annotation to your configuration. By defining this annotation, the application will automatically pull in the Spring Boot Admin Server configuration.
@Configuration
@EnableAutoConfiguration
@EnableAdminServer
public class SpringBootAdminApplication {
public static void main(String[] args) {
SpringApplication.run(SpringBootAdminApplication.class, args);
}
Finally, add the property management.security.enabled to your properties file. This property will disable the security on your Spring Boot Admin server endpoints (don’t use this in a production environment!). To secure your endpoints, look at how to Secure Spring Boot Admin : management.security.enabled=false
Setup Spring Boot Admin Client
To register an application to a Spring Boot Admin Server, you have to include the Spring Boot Admin Client project in your pom.xml :
<dependency>
<groupId>de.codecentric</groupId>
<artifactId>spring-boot-admin-starter-client</artifactId>