目录
指标监控可视化文档:用于管理 Spring Boot 应用程序的管理 UIhttps://github.com/codecentric/spring-boot-adminSpring Boot Admin Reference Guide
https://codecentric.github.io/spring-boot-admin/2.5.1/#getting-started
一、创建项目
就勾选Spring Web项目即可
二、基础设置
(1) 依赖引入
<dependency>
<groupId>de.codecentric</groupId>
<artifactId>spring-boot-admin-starter-server</artifactId>
<version>2.5.1</version>
</dependency>
(2) 开启服务器监控功能
import de.codecentric.boot.admin.server.config.EnableAdminServer;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@EnableAdminServer //开启服务器监控功能
@SpringBootApplication
public class BootAdminServerApplication {
public static void main(String[] args) {
SpringApplication.run(BootAdminServerApplication.class, args);
}
}
(3) SpringBoot配置文件
server.port=8888
(4) 启动项目
浏览器输入:http://localhost:8888/
打开的管理页面如下:
三、注册客户端
客户端中的数据需要被服务器收集
(1) 添加依赖
<dependency>
<groupId>de.codecentric</groupId>
<artifactId>spring-boot-admin-starter-client</artifactId>
<version>2.5.1</version>
</dependency>
(2) 客户端把数据传递给服务器
在需要监控的项目中的application.yaml配置:(注意是另一个项目的application.yaml,因为要监控另一个项目)
spring:
boot:
admin:
client:
url: http://localhost:8888
开启所有端点的监控,同样是在需要被监控的项目中进行配置(这里还是application.yaml)
# management 是所有actuator的配置
# management.endpoint.端点名.xxxx 对某个端点的具体配置
management:
endpoints:
enabled-by-default: true #默认开启所有监控端点 true
web:
exposure:
include: '*' # 以web方式暴露所有端点
四、监控项目
客户端和服务器连接好后,就可以打开SpringBoot Admin Server的管理界面了,实时监控项目