Manage Spring boot applications using Spring boot admin

Siva K
7 min readMar 4, 2019

--

Manage and monitor your spring boot applications using nice UI with spring boot admin. There are lots of options out there for APM (Application process monitoring) spring boot applications such as Micrometer , Prometheus and Grafana.I was looking for something from spring ecosystem itself, although we have lots of others options with respect to APM (Application process monitoring) .

I wanted to monitor our spring applications; In this search, I have come across ‘Spring boot admin‘.

Spring Boot Actuator

Actuator is a Spring Boot module, which adds REST/JMX endpoints to your application, so you can easily monitor and manage it in production.It offers health-check, metrics monitoring, access to logs, thread dumps, heap dumps, environmental info and more through end points.

Spring Boot Admin

Spring Boot Admin is a web application, used for managing and monitoring Spring Boot applications. Each application is considered as a client and registers to the admin server. Behind the scenes, the magic is given by the Spring Boot Actuator endpoints.Spring boot admin is a yet another spring boot application to monitor your other spring boot applications.

The official Spring website gives some useful insights on Spring boot admin. (! some of the information are not updated, in spring generally things will be little different based on which version you use).Please check official spring framework website here for more details. 24. Monitoring and Management.

Spring Boot Admin is not a core module provided by the Spring team, it was created by a company called Codecentric. Still, the code is publicly available on Github and it is free.

Overview of Spring boot admin:

Overview

What you can monitor using spring boot admin:

Spring boot admin provides the following features for registered application:

  • Show health status
  • Show details, like
  • JVM & memory metrics
  • micrometer.io metrics
  • Datasource metrics
  • Cache metrics
  • Show build-info number
  • Follow and download logfile
  • View jvm system- & environment-properties
  • View Spring Boot Configuration Properties
  • Support for Spring Cloud’s postable /env- &/refresh-endpoint
  • Easy log level management
  • Interact with JMX-beans
  • View thread dump
  • View http-traces
  • View audit events
  • View http-endpoints
  • View scheduled tasks
  • View and delete active sessions (using spring-session)
  • View Flyway / Liquibase database migrations
  • Download heapdump
  • Notification on status change (via e-mail, Slack, Hipchat , …)
  • Event journal of status changes (non persistent)

What I am going to do?

  1. Develop our spring boot admin application
  2. Develop two spring boot client applications and register to the admin application
  3. Show what are the basic features can be seen from the admin application.

Technologies used:

  1. Spring boot 2.1.0.RELEASE
  2. Spring boot admin 2.1.0
  3. Java 1.8
  4. Gradle 5.2.1

1. Develop our spring boot admin application

A simple spring boot application which will have spring boot admin added as dependency. This is going to be our monitoring application which is nothing but a spring boot admin application.

I have used Spring Initializr to create spring boot applications. I have created application with the following details:

build.gradle

Simple Spring boot application ‘Spring boot admin starter server’(de.codecentric:spring-boot-admin-starter-server) is added as a dependency.

application.properties

spring.security.user.name=admin 
spring.security.user.password=admin

In application properties, I have very minimal configuration, administrator credentials for our monitoring admin application. i.e my admin boot server will run on 8080 (default port).

Now in your Client you need to add these credentials as well, otherwise it will not be able to register with the server:

WebSecurityConfig.java

If you look at the build.gradle we have added ‘org.springframework.boot:spring-boot-starter-security‘ in the dependencies.

We need is to add Spring Security configuration to protect the Admin user interface:

The above configuration is to restrict the admin UI only to authenticated users using HTTP basic authentication and form login. Otherwise, you could not log in. Then there is a cookie-based Cross-Site Request Forgery protection.

SpringBootAdminApplication.java

This is the main application class of our app, we need to add ‘@EnableAdminServer’ in order to make this application as a spring boot admin server.

Spring boot admin Application class

Running the admin server:

We are done with the spring boot admin server development and necessary configurations. Let us try to start the server.

In the command prompt execute the following:

gradle clean bootRun

Upon opening http://localhost:8080 in browser, You will be asked to login:

Now you can use user name and password you have configured in the application.properties file.

In our case, it is ‘admin/admin’.

After successful login, you will see:

Now there are no client applications registered to monitor. Hence instances are zero.

2. Develop and configure two spring boot client applications

We have successfully started a spring boot admin server. Now we will develop two client boot applications for demonstration purpose.The client applications will be simple spring boot applications, which will have actuators and spring boot admin client modules included as dependency.

We need to do the following in our client applications in order to be registered to the admin application.

  • Adding actuator and spring boot admin client modules as dependencies in build.gradle:
org.springframework.boot:spring-boot-starter-actuator
de.codecentric:spring-boot-admin-starter-client
  • Adding spring boot admin credentials and admin url to register as client in application.properties
  • adding ‘management.endpoints.web.exposure.include=*’ — To expose all the Actuator endpoints in application.properties
  • adding ‘management.endpoint.health.show-details=always’ — Always show details in Health check section in application.properties

Client Setup

Same as with server setup, the first step is to add a proper dependency to an existing application:

You need to define URL where is your Admin Server running. Add this line to your application.properties:

spring.boot.admin.client.url=http://localhost:8080

However, most of the endpoints are not exposed by Actuator by default. You need to change your configuration in application.properties to expose them:

management.endpoints.web.exposure.include=*

build.gradle

If you look at the build.gradle: we have added actuator module, spring boot admin client module and security( to make our app secure).

application.properties

Start Monitoring

When you open Admin Server UI, you should see your application. When you click the app name, a page with application details should show up.

After exposing your Actuator endpoints, you should see much more information in your Admin interface:

Monitoring:

Audit Logs:

Threads:

Notifications

Once you have monitoring in place, you want to get notified when something goes wrong. The good news is that Spring Admin provides a wide variety of notification options.

If you visit the Admin Server page for the first time, it asks you for permission to display push notifications on your computer. Whenever there is an issue, you’ll get a popup message.

There are some other notifications and it need a simple configuration. Just providing a few entries in your application.properties will suffice.

The following services are supported:

  • Mail
  • Slack
  • HipChat
  • PagerDuty
  • OpsGenie
  • Let’s Chat
  • Telegram
  • Microsoft Team

Email Notification

you need to add Spring email dependency to your Server part:

dependencies {      
implementation 'org.springframework.boot:spring-boot-starter-mail'
}

Then you need to define your SMTP server, which will be used to send email notifications and credentials. Update your application.properties of your Admin Server.

spring.mail.host=smtp.foo.com 
spring.mail.username=smtp-server-user
spring.mail.password=smtp-server-password

Then you need to define recipients and sender.

# Sender email address 
spring.boot.admin.notify.mail.from="Spring Boot Admin <noreply@mks.com>"
# Comma-delimited list of recipient email addresses spring.boot.admin.notify.mail.to=ram@mks.com,bob@mks.com
# Comma-delimited list of carbon copy recipient email addresses spring.boot.admin.notify.mail.cc=joe@mks.com

Code

You can find the source code of this article in Source github.

Conclusion

Spring Boot Admin offers a nice and useful UI layer on top of Actuator Endpoints. And it allows you to centrally monitor multiple applications with multiple instances, which is very useful when working in the cloud and with microservices. Make sure though, that you sufficiently protect both your Client and Server.

References:

Tags: actuator, spring boot, spring boot admin, spring boot admin client

Originally published at www.mksiva.com on March 4, 2019.

--

--