1. The introduction
In the previous article “Spring Boot (9) : Monitoring Spring Boot Actuator In Detail we introduce Spring Boot based on Spring Boot Monitoring services. Spring Boot Actuator provides monitoring for a single Spring Boot, with information including application status, memory, thread, stack, etc., and comprehensively monitors the entire life cycle of Spring Boot applications. However, the Spring Boot Actuator only provides data interfaces for us to monitor, and the amount of data returned is very large. It is impossible for us to analyze the returned data by means of artificial eyes, but it must hope to have a graphical interface to help us analyze the information. Meanwhile, in the micro-service system, The number of our services is very large, which is also not convenient 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 used to manage and monitor the running status of Spring Boot applications. Each Spring Boot application is treated as a client and registered with the administration server. Data collection behind the scenes is provided by Spring Boot Actuator endpoints. Use VueJs to display data in the front end.
This article shows you how to use Spring Boot Admin to monitor Spring Boot.
3. Engineering practice
3.1 Creating a parent project spring-boot-admin
The dependency file pom.xml is as follows:
Code listing: 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. The SR3 < / spring - cloud. Version > < spring - the boot - admin. Version > 2.1.5 < / spring - the 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>
Copy the code
- in
<dependencyManagement>
addspring-boot-admin-dependencies
Version configuration, becausespring-boot-admin
Related version information is not integrated inspring-boot-dependencies
I don’t know why, and I’m afraid to ask.
3.2 Creating a subproject Spring-boot-admin-server
Spring Boot Admin can be used to monitor a single service or a cluster. This section describes how to monitor a single service.
The pom.xml configuration file is as follows:
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>
Copy the code
Note: If only a single service is used, you only need to introduce the spring-boot-admin-starter-server dependency. Spring-cloud-starter – Netflix-eureka-client This dependency is used by spring Boot Admin based on the Eureka service center.
The configuration file application.yml is as follows:
Code listing: spring – the boot – admin/spring – the boot – admin server/SRC/main/resources/application. The 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
Copy the code
Note: Eureka.***.*** and other related contents are not required for the stand-alone version.
Start the main class SpringBootAdminServerApplication. Java is as follows:
Code list: spring-boot-admin/spring-boot-admin-server/src/main/java/com/springboot/springbootadminserver/SpringBootAdminServerAppli cation.java
@SpringBootApplication @EnableAdminServer @EnableEurekaClient public class SpringBootAdminServerApplication { public static void main(String[] args) { SpringApplication.run(SpringBootAdminServerApplication.class, args); }}Copy the code
Note: The @enableeurekaclient annotation is not required for the standalone version.
3.3 Creating a subproject Spring-boot-admin-clienta
This project is a Spring Boot Admin standalone demo case.
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>
Copy the code
- This project only needs to introduce
spring-boot-admin-starter-client
The Spring Boot Admin client is ok.
The configuration file application.yml is as follows:
Code listing: spring – the boot – admin/spring – the boot – admin – clienta/SRC/main/resources/application. The 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
Copy the code
spring.application.name
The configured name is displayed in the Spring Boot Admin UI.spring.boot.admin.client.url
This is the address configured for our Spring Boot Admin server.management.endpoints.web.exposure.include
Enable all monitoring of the Spring Boot Actuator.management.endpoint.health.show-details
Enable Spring Boot Actuator monitoring applications with detailed application health information.
Start spring-boot-admin-server project and spring-boot-admin-clienta, wait a moment, Spring-boot-admin-clienta is automatically registered with spring-boot-admin-server.
Open the browser and visit http://localhost:8888/, then we can see the Spring Boot Admin monitoring diagram 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 Creating a subproject Spring-boot-admin-client
This project example is an example of using the micro-service version of Spring Boot Admin. In this example, the service center Eureka is used to register services. Spring Boot Admin reads related information from the service center Eureka to monitor services. In this way, you do not need to configure the Spring Boot Admin service address on the client. If the Spring Boot Admin service migrates the address, you do not need to modify the configuration file on the client.
The Eureka code examples are not listed here, but if you need to take a refresher course, you can visit my Spring Cloud series.
The project relies on POM.xml as follows:
Code listing: 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>
Copy the code
- Here only the Spring Boot Admin client and Spring Cloud Eureka client dependencies are added.
The configuration file application.yml is as follows:
Code listing: spring – the boot – admin/spring – the boot – admin – client/SRC/main/resources/application. The 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
Copy the code
- Compared with the previous stand-alone version, the configuration of the Spring Boot Admin service address is removed and the configuration of the Eureka service center is added.
Start the main class SpringBootAdminClientApplication. Java is as follows:
Code list:
@SpringBootApplication @EnableEurekaClient public class SpringBootAdminClientApplication { public static void main(String[] args) { SpringApplication.run(SpringBootAdminClientApplication.class, args); }}Copy the code
@EnableEurekaClient
The Eureka client is enabled on the Eureka client
Testing:
Modify the editor IDEA configuration, start the sub-project spring-boot-admin-client on two different ports, open the SPRING Boot Admin UI, and the following output is displayed:
As you can see, two APPLICATIONS are shown here, one is our spring-boot-admin-server itself monitoring, and the other is our spring-boot-admin-client application. There are two INSTANCES of this application, located on two different ports 8080 and 8081 respectively. Click in to see the details of the corresponding instance.
4. sample code
Example code -Github
Example code -Gitee
Reference 5.
Run the spring-boot-admin command to monitor the Spring Boot service