1. Introduction
In the last article Spring Boot (9): Details of Spring Boot Actuator for Microservice Application Monitoring We introduce Spring Boot service monitoring based on Spring Boot Actuator. Spring Boot Actuator provides the monitoring of a single Spring Boot. The information includes application status, memory, threads, stacks and so on. It comprehensively monitors the whole life cycle of Spring Boot application. However, Spring Boot Actuator only provides us with a monitoring data interface, and the amount of data returned is very large. We can not analyze these returned data by artificial naked eyes. We certainly hope to have a graphical interface to help us analyze these information. At the same time, in the micro-service system, the number of our services is very large. It is also inconvenient for us to manage manually. In this context, another open source software was born, which is also introduced in this article: Spring Boot Admin.
2. Introduction to Spring Boot Admin
Spring Boot Admin is a Web application that manages and monitors the running status of Spring Boot applications. Each Spring Book application is treated as a client and registered with the management server. The data collection behind is provided by the Spring Boot Actuator endpoint. The front-end Spring Boot Admin UI presentation uses VueJs to display data on the front-end.
This article describes how to use Spring Boot Admin to monitor Spring Boot.
3. Engineering Practice
3.1 Create parent project spring-boot-admin
The dependency file pom.xml is as follows:
List of code: spring-boot-admin/pom.xml
<properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> <java.version>1.8</java.version> <spring-cloud.version>Greenwich.SR3</spring-cloud.version> <spring-boot-admin.version>2.1.5</spring-boot-admin.version> </properties> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-actuator</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> </dependencies> <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> <dependency> <groupId>de.codecentric</groupId> <artifactId>spring-boot-admin-dependencies</artifactId> <version>${spring-boot-admin.version}</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies> </dependencyManagement>
- Add the version configuration of spring-boot-admin-dependencies in dependency management, because the version information of spring-boot-admin is not integrated into spring-boot-dependencies, and we don't know why, nor dare we ask.
3.2 Create a sub-project spring-boot-admin-server
Spring Boot Admin can be used to monitor a single service or a cluster. First, we introduce the monitoring configuration of a single service.
The pom.xml configuration file is as follows:
List of code: spring-boot-admin/spring-boot-admin-server/pom.xml
<dependency> <groupId>de.codecentric</groupId> <artifactId>spring-boot-admin-starter-server</artifactId> </dependency> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId> </dependency>
Note: If only a single service is used, only the dependency of spring-boot-admin-starter-server can be introduced. spring-cloud-starter-netflix-eureka-client is the dependency that Spring Boot Admin will use based on Eureka Service Center.
The configuration file application.yml is as follows:
List of code: spring-boot-admin/spring-boot-admin-server/src/main/resources/application.yml
server: port: 8888 spring: application: name: spring-boot-admin-server eureka: instance: leaseRenewalIntervalInSeconds: 10 health-check-url-path: /actuator/health client: registryFetchIntervalSeconds: 5 serviceUrl: defaultZone: ${EUREKA_SERVICE_URL:http://localhost:8761}/eureka/ management: endpoints: web: exposure: include: "*" endpoint: health: show-details: ALWAYS
Note: The stand-alone version does not need to configure eureka. ***. *** and other related content.
Start the main class SpringBootAdminServerApplication.java as follows:
List of code: spring-boot-admin/spring-boot-admin-server/src/main/java/com/spring boot/spring bootadmin server/Spring Boot Admin Server Application.java
@SpringBootApplication @EnableAdminServer @EnableEurekaClient public class SpringBootAdminServerApplication { public static void main(String[] args) { SpringApplication.run(SpringBootAdminServerApplication.class, args); } }
Note: There is no need to add the @Enable EurekaClient annotation to the stand-alone version.
3.3 Create sub-project spring-boot-admin-clienta
This project is a demonstration case of Spring Boot Admin stand-alone version.
Pom.xml is as follows: spring-boot-admin/spring-boot-admin-clienta/pom.xml
Code List:
<dependency> <groupId>de.codecentric</groupId> <artifactId>spring-boot-admin-starter-client</artifactId> </dependency>
- This project only needs to introduce the client of spring-boot-admin-starter-client Spring Boot Admin.
The configuration file application.yml is as follows:
List of code: spring-boot-admin/spring-boot-admin-clienta/src/main/resources/application.yml
server: port: 9090 spring: application: name: spring-boot-clienta boot: admin: client: url: http://localhost:8888 management: endpoints: web: exposure: include: "*" endpoint: health: show-details: ALWAYS
- The name of the spring.application.name configuration is displayed in the UI interface of Spring Boot Admin.
- spring.boot.admin.client.url is configured with the address of our Spring Boot Admin server.
- management.endpoints.web.exposure.include opens all monitoring of Spring Boot Actuator.
- management.endpoint.health.show-details opens detailed application health information for Spring Boot Actuator monitoring applications.
Start the spring-boot-admin-server project and spring-boot-admin-clienta. After a moment, spring-boot-admin-clienta will automatically register on spring-boot-admin-server.
Open Browser Access http://localhost 8888/, then we can see the Spring Boot Admin monitoring chart, as follows:
Click to enter the details of the application. We can see that Spring Boot Admin uses a graphical interface to display various information of the application, as follows:
3.4 Create a sub-project spring-boot-admin-client
This engineering example is the Spring Boot Admin usage example of the microservice version, in which the service center Eureka is used to register the service, and Spring Boot Admin reads relevant information from the service center Eureka for service monitoring. In this way, we do not need to configure Spring Boot Admin's service address on the client side, nor do we need to modify the client's configuration file if the Spring Boot Admin service migrates and so on.
Eureka code examples are not listed here. If you need to make up lessons, you can visit the author's Spring Cloud Series Articles .
Engineering dependency on pom.xml is as follows:
List of code: spring-boot-admin/spring-boot-admin-client/pom.xml
<dependency> <groupId>de.codecentric</groupId> <artifactId>spring-boot-admin-starter-client</artifactId> </dependency> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId> </dependency>
- Only Spring Boot Admin's client and Spring Cloud Eureka's client dependencies are added here.
The configuration file application.yml is as follows:
List of code: spring-boot-admin/spring-boot-admin-client/src/main/resources/application.yml
server: port: 8080 spring: application: name: spring-boot-admin-client eureka: instance: leaseRenewalIntervalInSeconds: 10 health-check-url-path: /actuator/health client: registryFetchIntervalSeconds: 5 serviceUrl: defaultZone: ${EUREKA_SERVICE_URL:http://localhost:8761}/eureka/ management: endpoints: web: exposure: include: "*" endpoint: health: show-details: ALWAYS
- Compared with the previous single-machine configuration, the Spring Boot Admin service address configuration is removed and the Eureka service center configuration is added.
Start the main class SpringBootAdminClientApplication.java as follows:
Code List:
@SpringBootApplication @EnableEurekaClient public class SpringBootAdminClientApplication { public static void main(String[] args) { SpringApplication.run(SpringBootAdminClientApplication.class, args); } }
- @ Enable Eureka Client means to enable the Eureka client. It's also true that even if you don't write it here, you'd better write it down.
Test:
Modify the editor idea configuration, and open the UI interface of Spring Boot Admin in two different port starter projects, spring-boot-admin-client, as shown below:
As you can see, here are two APPLICATIONS (Application S), one is the monitoring of our spring-boot-admin-server itself, and the other is our spring-boot-admin-client application, which has two instances (INSTANCES) on two different ports 8080 and 8081, respectively. Point in and you can see the details of the corresponding instance.
4. Sample code
5. Reference
Monitoring Spring Boot Service with spring-boot-admin
If my article is helpful to you, please pay close attention to the author's public number: Get the latest dry goods push:)