Use Spring-boot-admin of Spring boot of service monitoring

To monitor requires two Project, one is the Admin Server end, responsible for monitoring the Spring boot of the project, and the other end is the Admin Client, it is being monitored Spring boot service.

 

Admin Server 端

First pom.xml profile dependent import function.

 1 <?xml version="1.0" encoding="UTF-8"?>
 2 <project xmlns="http://maven.apache.org/POM/4.0.0"
 3          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 4          xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
 5     <modelVersion>4.0.0</modelVersion>
 6 
 7     <groupId>admin</groupId>
 8     <artifactId>admin</artifactId>
 9     <version>1.0-SNAPSHOT</version>
10 
11     <parent>
12         <groupId>org.springframework.boot</groupId>
13         <artifactId>spring-boot-starter-parent</artifactId>
14         <version>2.1.6.RELEASE</version>
15     </parent>
16 
17     <dependencies>
18         <dependency>
19             <groupId>org.springframework.boot</groupId>
20             <artifactId>spring-boot-starter-web</artifactId>
21             <version>2.1.6.RELEASE</version>
22         </dependency>
23 
24         <dependency>
25             <groupId>de.codecentric</groupId>
26             <artifactId>spring-boot-admin-starter-server</artifactId>
27             <version>2.1.6</version>
28         </dependency>
29 
30         <!--监控-->
31         <dependency>
32             <groupId>org.springframework.boot</groupId>
33             <artifactId>spring-boot-starter-actuator</artifactId>
34         </dependency>
35 
36         <dependency>
37             <groupId>de.codecentric</groupId>
38             <artifactId>spring-boot-admin-server-ui</artifactId>
39             <version>2.0.1</version>
40         </dependency>
41     </dependencies>
42 </project>

Then write the configuration file application.yml

1 spring:
2   application:
3     name: admin-server
4 server:
5   port: 9090

Finally, fill the main class of the whole project

 1 package cy;
 2 
 3 import de.codecentric.boot.admin.server.config.EnableAdminServer;
 4 import org.springframework.boot.SpringApplication;
 5 import org.springframework.boot.autoconfigure.SpringBootApplication;
 6 
 7 @SpringBootApplication
 8 @EnableAdminServer
 9 
10 public class TestApplication {
11     public static void main(String[] args) {
12         SpringApplication.run(TestApplication.class, args);
13 
14     }
15 }

Then enter  HTTP: // localhost: 9090 /  see the following interface represents the first step on the Server side has been completed.

 

Admin Client end

Add the following dependencies in the pom.xml file to be monitored Project file

1 <dependencies>
2     <dependency>
3       <groupId>de.codecentric</groupId>
4       <artifactId>spring-boot-admin-starter-client</artifactId>
5       <version>2.1.0</version>
6     </dependency>
7 </dependencies>

Configuration files are divided into two categories, if you are configuring a application.yml

 1 //application.yml
 2 server:
 3   port: 8080
 4 spring:
 5   application:
 6     name: Admin Client
 7   boot:
 8     admin:
 9       client:
10         url: http://localhost:9090
11 management:
12   endpoints:
13     web:
14       exposure:
15         include: '*'

If you are configuring application.properties

1 //application.properties
2 server.port=8080
3 spring.application.name=Admin Client
4 spring.boot.admin.client.url=http://localhost:9090  
5 management.endpoints.web.exposure.include=*

The difference can be seen https://www.cnblogs.com/chenyun-/p/11306854.html

Client running the main class, you can see

Choose to enter the project, you can see

This time we will be able to monitor the indicators of service.

 

The last article we explain the meaning of the configuration file, we recommend application.yml, here for the convenience of the layout used application.properties:

 server.port = 8080  is monitored projects running at the port;

 spring.application.name=Admin Client Client名称;

 = HTTP spring.boot.admin.client.url: // localhost: 9090  monitoring program in place, so that both can be found;

 management.endpoints.web.exposure.include=* 开放给监控程序的权限,这里的✳代指所有的权限。

 

Guess you like

Origin www.cnblogs.com/chenyun-/p/11307118.html