文章前言
上篇文章了解了 Spring Boot Actuator,引入后即可通过访问不同的端点,来获得相应的监控信息。
对应 HTTP 方式请求,返回的数据都是 JSON 格式,这对于运维或是其他人员来说当然不是很方便直观,特别是当需要监控的应用越来越多时,如果还依旧通过地址栏来逐个访问,就显得过于繁琐和低效了。下面,我们再来认识下 Spring Boot Admin 这个 Spring Boot Application UI 监控管理工具。
快速上手
Spring Boot Admin 由 Server 和 Client 两个端组成,其中 Client 端通常是需要被监控的应用。先来配置下 Server 端的依赖,考虑到安全性方面的问题,这里还额外加入了 Security:
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>de.codecentric</groupId>
<artifactId>spring-boot-admin-starter-server</artifactId>
</dependency>
</dependencies>
接着在 application.yml
文件中配置登录用户及密码:
spring:
security:
user:
name: admin
password: admin
必要的 Security 配置:
@Configuration
public class SecuritySecureConfig extends WebSecurityConfigurerAdapter {
private final String adminContextPath;
public SecuritySecureConfig(AdminServerProperties adminServerPr