Tuesday, April 20, 2021

Spring Boot Admin Server - Helps to Monitor Spring Boot Applications via Vue JS UI

 

Spring Boot Admin Server
Image Source: Sprint Boot Admin - Community Project

If you are in a micro services architecture, you will have lot of services and monitoring all of them by using Spring Boot Actuator Endpoint is quite difficult.

The CodeCentric Team provides a Spring Boot Admin Server UI to manage and monitor all your Spring Boot application Actuator endpoints at one place.

The applications register with Admin Server using Spring Boot Admin Client (via HTTP) or are discovered using Spring Cloud (e.g. Eureka, Consul). The Spring Boot Admin UI is a Vue JS application on top of the Spring Boot Actuator endpoints.

Let’s create a spring boot application which acts as a admin server. We will re-use one of the existing project as client, which registers with the admin server and we should be able to see all the information of the client on admin user interface.

Building a Spring Boot Admin Application

Let’s use the spring initializr to generate a spring boot application. Unzip the downloaded project and import it to your IDE.

For building a Spring Boot Admin Server, we need the below dependencies in the build configuration file.

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

Next step is to add the EnableAdminServer annotation in your main Spring Boot application class file. This annotation is used to tell spring boot to make our application as Admin Server to monitor all other micro services.

@EnableAdminServer
@SpringBootApplication
public class AdminConsoleApplication {

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

}

Let’s define some of the server properties in application.properties

# Admin Server Properties
spring.application.name=admin-console
server.servlet.context-path=/
server.port=9090

We are almost ready with Spring Boot Admin service, let’s build and deploy the application. Once the application comes up, type in the URL http://localhost:9090/ on the web browser to access the Spring Boot Admin Server UI.

Sprint Boot Admin Dashboard

Now that we have admin server ready, let’s deploy another spring boot application so that we can monitor and manage it. I am taking an existing project rest-producer application for the exercise.

First, add the following dependencies in the build configuration file.

<dependency>
   <groupId>org.springframework.boot</groupId>
   <artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
   <groupId>de.codecentric</groupId>
   <artifactId>spring-boot-admin-starter-client</artifactId>
   <version>2.3.1</version>
</dependency>

Let’s configure the admin server URL and enable the actuator end points in application.properties.

# Admin Server URL
spring.boot.admin.client.url=http://localhost:9090
# Actuator Properties
management.endpoints.web.exposure.include=*
management.endpoint.health.show-details=always

Now build and deploy the rest-producer application. Once the application, comes up go back to the Admin Server UI and refresh the page. You should be able to see hystrix-rest-producer service registered and visible in admin server. Click on the service name, to get complete details of the service.

Sprint Boot Admin Dashboard

The Spring Boot Admin Server provides the following features for any registered applications:
  • Show Health Status
  • Show details like JVM & Memory, Datasource, Cache Metrics etc.
  • Show build-info number
  • Follow and Download Log file
  • View JVM System & Environmental properties
  • Easy Log Level Management
  • View thread dump, http-traces, audit events, http-endpoints etc.
  • View and Delete Active Sessions (using spring-session)
  • View Flyway / Liquibase Database Migrations
  • Download Heap Dump
  • Event Journal of Status Changes

Please note, the Spring Boot Admin Server has access to the application’s sensitive endpoints, so it’s recommended to add security configurations to both admin and client services. Enable the Spring Security, so that only with valid credentials the admin UI can be accessed and the client services can register with admin service with it.

As usual, the source code for the above spring boot admin server is available over on GitHub.


Tags: , , , ,
Location: Mysuru, Karnataka, India

1 comment:

Featured Post

Benefits & Best Practices of Code Review

Photo by Bochelly Code reviews are methodical assessments of code designed to identify bugs, increase code quality, and help developers lear...