Project monitoring management using Spring Boot Admin
1. What is Spring Boot Admin
Spring Boot Admin (SBA) is a community open source project for managing and monitoring Spring Boot applications.Applications register to Spring Boot management clients through http, or through Spring Cloud's service discovery mechanism, then visually manage data through Vue.js for the actuator interface.
For us, Spring Boot Admin allows us to browse all monitored Spring Boot projects, including detailed Health information, memory information, JVM system and environment properties, garbage collection information, and so on.
2. Spring Boot Admin Start
Spring Boot Admin consists of two roles: the Server side and the Client side, the application to be monitored.The following two roles are configured:
Spring Boot Admin Server
Introducing dependencies [pom.xml]
<dependency> <groupId>de.codecentric</groupId> <artifactId>spring-boot-admin-starter-server</artifactId> <version>2.0.0</version> </dependency>
@EnableAdminServer comment
@SpringBootApplication @EnableAdminServer public class AdminApplication { public static void main(String[] args) { SpringApplication.run(AdminApplication.class, args); } }
application.yml Configuration
spring: application: name: spring-boot-admin-server server: port: 8080 management: endpoint: health: show-details: always endpoints: web: exposure: include: '*'
After booting, you can see a UI interface by visiting http://localhost:8080
At this point, both the application and the instance are because we have not registered the client, and then we implement the client.
Spring Boot Admin Client
Introducing Client Dependency [pom.xml]
<dependency> <groupId>de.codecentric</groupId> <artifactId>spring-boot-admin-starter-client</artifactId> <version>2.0.0</version> </dependency>
There is no special need to modify the program entry
@SpringBootApplication public class AdminClientApplication { public static void main(String[] args) { SpringApplication.run(AdminClientApplication.class, args); } }
application.yml Configuration
spring: application: name: spring-boot-admin-client boot: admin: client: url: http://localhost:8080 server: port: 8081
Visit localhost:8080 again to find a new application instance, as shown in the following figure:
So here we have a basic Spring Boot Admin application configured successfully.
Click on the wallboard in the menu bar, and then click on the application you want to view to access information about the application, such as memory status information:
3. SBA Combined with Spring Cloud Registration Center
In addition to configuring the corresponding SBA configuration directly on the client side in the above case, you can also collaborate with Spring Cloud's service registration and discovery applications (for example, Eureka, Consul), and then demonstrate how to configure:
New Unified Dependency Management
<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.jojo</groupId> <artifactId>admin-demo-dependencies</artifactId> <version>1.0.0-SNAPSHOT</version> <packaging>pom</packaging> <name>admin-demo-dependencies</name> <description>Demo project for Spring Boot Admin</description> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.1.0.RELEASE</version> <relativePath/> </parent> <properties> <!-- Environment Settings --> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> <java.version>1.8</java.version> <!-- Spring Settings --> <spring-cloud.version>Finchley.SR2</spring-cloud.version> <spring-boot-admin.version>2.1.0</spring-boot-admin.version> </properties> <dependencyManagement> <dependencies> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-dependencies</artifactId> <version>${spring-cloud.version}</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies> </dependencyManagement> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build> </project>
Carrier Service Registry
Introducing dependencies
<dependencies> <!-- Spring Boot Begin --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> <!-- Spring Boot End --> <!-- Spring Cloud Begin --> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-netflix-eureka-server</artifactId> </dependency> <!-- Spring Cloud End --> </dependencies>
Application Entry
@SpringBootApplication @EnableEurekaServer public class EurekaServerApplication { public static void main(String[] args) { SpringApplication.run(EurekaServerApplication.class, args); } }
application.yml
spring: application: name: admin-demo-eureka server: port: 8761 eureka: instance: hostname: localhost client: service-url: default-zone: http://${eureka.instance.hostname}:${server.port}/eureka register-with-eureka: false fetch-registry: false management: endpoints: web: exposure: include: "*" endpoint: health: show-details: ALWAYS
After successful configuration, launch the application and visit localhost:8761 to see a UI interface similar to the following:
Create SBA Server
Introducing dependencies
<dependency> <groupId>de.codecentric</groupId> <artifactId>spring-boot-admin-starter-server</artifactId> <version>2.1.0</version> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId> </dependency> <dependency> <groupId>org.jolokia</groupId> <artifactId>jolokia-core</artifactId> </dependency>
Application Entry
@SpringBootApplication @EnableAdminServer @EnableDiscoveryClient public class AdminServerApplication { public static void main(String[] args) { SpringApplication.run(AdminServerApplication.class, args); } }
application.yml Configuration
spring: application: name: admin-demo-admin-server server: port: 8769 eureka: client: registryFetchIntervalSeconds: 5 service-url: defaultZone: ${EUREKA_SERVICE_URL:http://localhost:8761}/eureka/ instance: leaseRenewalIntervalInSeconds: 10 health-check-url-path: /actuator/health management: endpoints: web: exposure: include: "*" endpoint: health: show-details: ALWAYS
Create SBA Client
Introducing dependencies
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-webflux</artifactId> </dependency> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-actuator</artifactId> </dependency>
applicaion.yml configuration file
spring: application: name: admin-demo-admin-client server: port: 8762 eureka: instance: leaseRenewalIntervalInSeconds: 10 health-check-url-path: /actuator/health client: registryFetchIntervalSeconds: 5 service-url: defaultZone: ${EUREKA_SERVICE_URL:http://localhost:8761}/eureka/ management: endpoints: web: exposure: include: "*" endpoint: health: show-details: ALWAYS
Application Entry
@SpringBootApplication @EnableDiscoveryClient public class AdminClientApplication { public static void main(String[] args) { SpringApplication.run(AdminClientApplication.class, args); } }
After three applications have been started, you can monitor how each application works by visiting localhost:8769:
IV. Integrated Mail Notification
Mail notifications can also be integrated in SBA to send messages to specified mailboxes when registered services go offline or go down.It is also easy to configure by configuring the sender of the mailbox and the recipient of the mail in the yaml configuration file, and by introducing a dependency of `` in the pom file.The following demonstrates this configuration:
pom.xml Configuration: Dependency to join mail
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-mail</artifactId> </dependency>
application.yml: Configure recipient and sender information in the configuration file and turn on mailbox alerts
spring: boot: admin: notify: mail: enabled: true from: youemail@example.com ... spring.mail.host: smtp.example.com spring.mail.username: youemail@example.com spring.mail.password: # Authorization Number spring.boot.admin.notify.mail.to: admin@example.com
After configuring and starting, you can try to abort the Client project:
Then open the recipient's mailbox and you can see the messages sent by SBA
5. Reference
Official SBA documentation: https://codecentric.github.io/spring-boot-admin/current/