SpringBoot服务监控

SpringBoot服务监控分为客户端和服务端,即服务端是监控方,客户端为被监控方。

例如需要对线上的SpringBoot服务project-A进行监控,则project-A 为客户端。而监控的服务project-B则为服务端。客户端将被监控的数据信息发送到服务端进行UI展示。

客户端project-A依赖的jar:     

     <!--应用监控-->
        <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>1.5.6</version>
        </dependency>        

 在配置文件中添加配置:

spring.application.name=project-A
server.port=5566
#将该服务的各指标监控信息在app-monitor服务上展示
spring.boot.admin.url=http://xxxx.xxxx.xxx.com:8056/app-monitor
#关闭安全校验
management.security.enabled=false

服务端project-B依赖的jar:

      <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>
        <dependency>
            <groupId>de.codecentric</groupId>
            <artifactId>spring-boot-admin-server</artifactId>
            <version>1.5.6</version>
        </dependency>
        <dependency>
            <groupId>de.codecentric</groupId>
            <artifactId>spring-boot-admin-server-ui</artifactId>
            <version>1.5.6</version>
        </dependency>    

 配置文件的配置:

spring.application.name=app-monitor
server.port=8056
server.context-path=/app-monitor  

在服务端的启动类上添加如下注解:

@EnableAdminServer

然后启动这两个服务,打开project-B服务的url 

http://xxxx.xxxx.xxx.com:8056/app-monitor
看到如下的界面:

 

                                                                                                                                     

原文地址:https://www.cnblogs.com/wrong5566/p/9548731.html