Spring Boot Admin 是一个管理和监控Spring Boot 应用程序的开源监控软件,针对spring-boot 的 actuator接口进行UI美化并封装
可以在管理界面中浏览所被监控spring-boot项目的基本信息,详细的health信息、内存信息、JVM信息、垃圾回收信息、各种配种信息(比如数据源、缓存列表和命中率)等,
还可以直接修改logger的level,Spring Boot Admin 提供的丰富详细的监控信息给Spring Boot 应用的监控、维护、和优化都带来了极大的便利
第一步、新建一个Spring Boot 项目
新建mango-monitor项目
第二步、配置pom文件
1、在mango-pom的pom文件中添加mango-monitor
<module>../mango-monitor</module>
2、在mango-monitor的pom中添加Spring Boot和Spring Boot Admin依赖
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.4.4</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.louis</groupId>
<artifactId>mango-monitor</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>mango-monitor</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<!-- spring boot -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<!--spring-boot-admin-->
<dependency>
<groupId>de.codecentric</groupId>
<artifactId>spring-boot-admin-server</artifactId>
<version>2.1.2</version>
</dependency>
<dependency>
<groupId>de.codecentric</groupId>
<artifactId>spring-boot-admin-server-ui</artifactId>
<version>2.1.2</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
第三步、添加配置
将application.properties修改为application.yml
server:
port: 8000
spring:
application:
name: mango-monitor
第四步、配置启动类
在启动类上添加@EnableAdminServer注解,开启监控服务
@EnableAdminServer
@SpringBootApplication
public class MangoMonitorApplication {
public static void main(String[] args) {
SpringApplication.run(MangoMonitorApplication.class, args);
}
}
配置完成后,我们启动项目,在浏览器访问http://localhost:8000/
可以看到没有监控的项目,因为还没有监控客户端被注册
我们需要在admin和backup项目中添加监控客户端依赖
<!--spring-boot-admin-client-->
<dependency>
<groupId>de.codecentric</groupId>
<artifactId>spring-boot-admin-starter-client</artifactId>
<version>2.1.2</version>
</dependency>
何修改修改admin和backup的yml文件配置监控服务器的地址和开放监控接口
spring:
application:
name: mango-admin
boot:
admin:
client:
url: http://localhost:8000
management:
endpoints:
web:
exposure:
include: "*"
spring:
application:
name: mango-backup
boot:
admin:
client:
url: http://localhost:8000
management:
endpoints:
web:
exposure:
include: "*"
修改完后我们启动mango-admin
、mango-backup、mango-monitor三个项目
启动后我们再访问
http://localhost:8000/
此时可以看到,我们已经有2个监控的服务了
点击wallboard可以看到项目
点击项目可以对各自的项目进行管理
如果启动项目后访问浏览器IDEA报错:
[f4aeb71d] Error [java.io.IOException: 你的主机中的软件中止了一个已建立的连接。] for HTTP GET "/applications", but ServerHttpResponse already committed (200 OK)
请检查你的server 端口和 client 端口是否一致
你的客户端是否启动