Setup Monitoring System for your Spring Boot applications Using Spring Boot Admin

unsplash-logoZdeněk Macháček

In past few microservices articles, We discuss different Spring Cloud features.In microservices architecture we have lot of services doing small small tasks. Monitoring all these application becomes very critical and integral part of your technology stack.
Spring Boot Admin is Community project provides an admin interface for Spring Boot applications.
let check how we can setup and use Spring Boot Admin.

The code for this post is available for download here.

Setting Up Spring Boot Admin Server

To Add admin server in project we need to add below spring boot starter dependancy

spring boot admin starter server
1
2
3
4
  <dependency>
<groupId>de.codecentric</groupId>
<artifactId>spring-boot-admin-starter-server</artifactId>
</dependency>

Add @EnableAdminServer on Main Application.

Admin Main Class
1
2
3
4
5
6
7
8
@SpringBootApplication
@EnableAdminServer
public class SpringBootAdminServerApplication {

public static void main(String[] args) {
SpringApplication.run(SpringBootAdminServerApplication.class, args);
}
}

Now if we Start the application, the admin UI should be available

Register clients with admin Server

Each application that wants to register has to include the Spring Boot Admin Client dependancy.

Client
1
2
3
4
  <dependency>
<groupId>de.codecentric</groupId>
<artifactId>spring-boot-admin-starter-client</artifactId>
</dependency>

And add Admin.client url in application.properties
spring.boot.admin.client.url=http://localhost:8080/
Spring Boot Admin will use spring.application.name property to display the name of application.

Our application is registered on Admin Consol, But apart for Status no other information is available

Magic of Spring Boot Actuator and Spring Boot Admin Server

Spring Boot Admin depends on Actuators endpoints to provide information. let’s enable Actuator endpoints.
put below in client application.
management.endpoints.web.exposure.include=*
Note, Expose only needed endpoints.

Tips and tricks

Display Build Info
To Display Build Info, Simply add build-info Goal in spring-boot-maven-plugin plugin

Build Info
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
  <build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>build-info</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>

Display Git Commit info
To know which commit id is deployed, We can simply use git-commit-id-plugin, git information will be available in info endpoint and will be displayed on admin ui.

Build Info
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
  <build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>build-info</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>pl.project13.maven</groupId>
<artifactId>git-commit-id-plugin</artifactId>
</plugin>
</plugins>
</build>

Logs
By default the log file is not accessible via actuator endpoints and therefore not visible in Spring Boot Admin. In order to enable the logfile actuator endpoint you need to configure Spring Boot to write a logfile, either by setting logging.path or logging.file.
Add below property in Client application.
logging.file=target/sample-boot-application.log
At run time we can also change the logs level, Which is useful in lower environments.
Multiple Instance
Admin Will Automatically Group applications based on application names and will show consolidated view.
Tags
Tags are a way to add visual markers per instance, they will appear in the application list as well as in the instance view.
spring.boot.admin.client.instance.metadata.tags.environment=QA

Notification

By default Spring Boot Admin will send registered application changes to DOWN or OFFLINE. We can do lot of customizations for Notifications.
Below is configurations for sending emails using google smpt server.
Use spring-boot-starter-mail dependancy in admin.

Email Config in Admin
1
2
3
4
5
6
spring.mail.host=smtp.gmail.com
spring.mail.port=587
spring.mail.username=XYZ@gmail.com
spring.mail.password=XYZ
spring.boot.admin.notify.mail.to=XYZ
spring.mail.properties.mail.smtp.starttls.enable=true

Discovery Clients

The Spring Boot Admin Server can use Spring Clouds DiscoveryClient to discover applications. The advantage is that the clients don’t have to include the spring-boot-admin-starter-client. You just have to add a DiscoveryClient implementation to your admin server - everything else is done by AutoConfiguration.

Security

As Admin Server is an spring boot application, Securing admin server is same as securing normal spring boot application.

Reference

Documentation
The code for this post is available for download here.

Share Comments