Spring Boot Admin 监控SpringBoot 服务的运行情况
https://codecentric.github.io/spring-boot-admin/2.3.0/#spring-boot-admin-server
1. Spring Boot Admin Server 服务端配置
生产环境,配合:Spring Boot Admin 授权配置 一起使用
建一个Web 项目,POM 配置如入
<?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>com.vipsoft.his</groupId> <artifactId>his-parent</artifactId> <version>1.0-SNAPSHOT</version> </parent> <groupId>com.vipsoft</groupId> <artifactId>vipsoft-admin</artifactId> <version>1.0.0</version> <name>vipsoft-admin</name> <description>Admin for vipsoft</description> <properties> </properties> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>de.codecentric</groupId> <artifactId>spring-boot-admin-starter-server</artifactId> <version>2.3.0</version> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> <exclusions> <exclusion> <groupId>org.junit.vintage</groupId> <artifactId>junit-vintage-engine</artifactId> </exclusion> </exclusions> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build> </project>
启动文件添加 @EnableAdminServer
/** * vipsoft Admin * @author Jimmy */ @ComponentScan(basePackages = {"com.vipsoft"}) @EnableAdminServer @SpringBootApplication public class VipsoftAdminApplication { public static void main(String[] args) { SpringApplication.run(vipsoftAdminApplication.class, args); } }
启动服务
2. 应用端(Client)配置,只要修改 pom、yml 代码无需改动
POM 配置
<!--如果不加,Spring Boot Admin 中健康状况无法监控--> <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>2.3.0</version> </dependency>
.yml 配置
server: port: 22586 logging: file: name: ./logs/info.log #如果不指定文件,Spring Boot Admin 将不显示日志记录(比较坑的是只能显示一个文件) pattern: file: "%clr(%d{yyyy-MM-dd HH:mm:ss.SSS}){faint} %clr(%5p) %clr(${PID}){magenta} %clr(---){faint} %clr([%15.15t]){faint} %clr(%-40.40logger{39}){cyan} %clr(:){faint} %m%n%wEx" spring: boot: admin: client: url: http://192.168.3.95:22589 #这里配置admin server 的地址 instance: name: VipSoft His Api Dev service-url: http://192.168.0.66:22586 # 对于IP 映射或 Docker 很方便 prefer-ip: true #true 注册时 admin 中显示IP地址不显示主机名 #开放端点用于SpringBoot Admin的监控 management: endpoints: web: exposure: include: '*' endpoint: health: show-details: always health: redis: enabled: false db: enabled: false