Administration of Spring Boot Applications

May 23, 2017
2170 Views
1 Comments

Technology:  Spring Boot Admin is the application for managing and monitoring based on Spring Boot Applications. The application can be registered with Admin Application using HTTP or it can discovered with Spring Cloud. Spring Boot Admin is developed using Spring Actuator Endpoints and user interface is implemented using AngularJS.

SetUp Spring Boot Admin Server:

Add the below dependencies to existing boot application to convert spring boot admin application.

For Maven build tool:

 <Dependency>  
   <groupId>de.codecentric</groupId>  
   <artifactId>spring-boot-admin-server</artifactId>  
   <version>1.5.0</version>  
 </dependency>  
 <dependency>  
   <groupId>de.codecentric</groupId>  
   <artifactId>spring-boot-admin-server-ui</artifactId>  
   <version>1.5.0</version>  
 </dependency>

spring-boot-admin-server provides additional endpoints on top of Spring boot Actuator.

spring-boot-admin-server-ui provides the user interface using angularJS.

Add @EnableAdminServer annotation along with @Configurable annotation on class level annotation.

Registering Client Applications:

For registering application in Spring Boot Admin either include Spring Boot Admin Client Dependency or use Spring Cloud Discovery.

For adding Spring Boot Admin Client dependency need to add below dependency in pom.xml file.

 <dependency>  
   <groupId>de.codecentric</groupId>  
   <artifactId>spring-boot-admin-starter-client</artifactId>  
   <version>1.5.0</version>  
 </dependency>  

And need to specify the URL of the Spring Boot Admin in either property source.

spring.boot.admin.url is the URL of the Spring Boot Admin.

Display client application version number in Spring Boot Admin:

By default Spring Boot Admin depends on META-INF/ build-info.properties to display version in application dashboard.

We can generate this file using spring-boot-maven-plugin, build-info goal.

 <plugin>  
      <groupId>org.springframework.boot</groupId>  
      <artifactId>spring-boot-maven-plugin</artifactId>  
      <executions>  
           <execution>  
                <goals>  
                     <goal>build-info</goal>  
                </goals>  
           </execution>  
      </executions>  
 </plugin>  

JMX Bean Management: Spring Boot Admin Client is depends on Jolokia to interact with JMX beans in Server, by default spring-boot-admin-starter-client will add Jolokia Dependency if not need to add Jolokia dependency in pom.xml file.

Log Level Management: For application using Spring Boot 1.5 later version log levels can be managed out of box, otherwise it will depends on logback, itself depends on Jolokia, so we need to make sure that Jolokia dependency must be present in classpath, include JMXConfigurator.

 <?xml version="1.0" encoding="UTF-8"?>  
 <configuration>  
  <include resource="org/springframework/boot/logging/logback/base.xml"/>  
  <jmxConfigurator/>  
 </configuration>  

Notifications :

RemindingNotifier send the notification of client online/offline availability, and itself delegate notifications another filter.

By default reminder will trigger if the register client application changes to DOWN or OFFLINE.

private String[] reminderStatuses = { “DOWN”, “OFFLINE” }; // constants from RemindingNotifier.class, we can add more statuses if needed by extending the RemindingNotifier and overriding setReminderStatuses() method.

Reminder will start if application status matches with configured statuses, and it will terminate if it doesn`t match.

By default the reminders will sent for every 10 minutes, we can alter using setReminderPeriod(long reminderPeriod) method. By default ReminderNotifier will not start new daemon thread, we need to create spring beans accordingly, so that using spring scheduling notifications will be triggered based on supplied parameters.

 @Configuration  
 public class NotificationConfiguration {  
      @Bean  
      @Primary  
      public RemindingNotifier remindingNotifier() {  
           RemindingNotifier notifier = new RemindingNotifier(filteringNotifier(loggerNotifier()));  
           notifier.setReminderPeriod(TimeUnit.SECONDS.toMillis(10));  
           return notifier;  
      }  
      @Scheduled(fixedRate = 1_000L)  
      public void remind() {  
           remindingNotifier().sendReminders();  
      }  
      @Bean  
      public FilteringNotifier filteringNotifier(Notifier delegate) {  
           return new FilteringNotifier(delegate);  
      }  
      @Bean  
      public LoggingNotifier loggerNotifier() {  
           return new LoggingNotifier();  
      }  
 }  

Mail Notifications:

To enable mail notifications, add below dependency.

 <dependency>  
   <groupId>org.springframework.boot</groupId>  
   <artifactId>spring-boot-starter-mail</artifactId>  
 </dependency>  

We need to provide the mail host details like host, port, username and password using MailProperties class provided by spring boot (using spring.mail prefix)

Ex: Add below properties for spring.mail.host, spring.mail.port spring.mail.username , spring.mail.password and spring.mail.protocol in application.properties.

And below properties are provided by spring boot admin to enable mail notifications.

  1. spring.boot.admin.notify.mail.enabled: enable mail notifications from spring boot admin, and default value is true.
  2. Spring.boot.admin.notify.mail.ignore-changes: Comma-delimited list of status changes to be ignored. Format: “<from-status>:<to-status>”. Wildcards allowed.
  3. spring.boot.admin.notify.mail.to: comma separated mail receipts to whom want to send an email.
  4. spring.boot.admin.notify.mail.cc: comma separated mail receipts to whom want to send carbon copy of an email.
  5. spring.boot.admin.notify.mail.from: from which email address want to send an emails.
  6. spring.boot.admin.notify.mail.subject :mail subject
  7. spring.boot.admin.notify.mail.text : mail body we can form template using spring spEL.

Securing Spring Boot Admin: By default Spring Boot Admin didn`t support the authentication and authorization, but It provides add-on module for supporting security.

Spring-boot-admin-server-ui-login is pluggable application which will support for security, as it is developed on top of spring security we can use spring security configuration to authenticate and authorize.

By extending WebSecurityConfigurerAdapter(provided by Spring Security) we can customize the authentication and authorization process.

After starting admin server and client application we can see the below screens.
spring1

Spring2

spring3

spring4

Conclusion: Spring Boot Admin application is server which is used to monitor Spring Boot applications, and we can get notifications if the client application status changes and we can monitor client JVM state, trace the application request, auditing client request.

One Comment

  1. Pingback: Guideinfoways | Pearltrees