Spring Boot Admin 是一个管理和监控 Spring Boot 应用程序的开源软件。每个应用都认为是一个客户端,通过 HTTP 或者使用 Eureka 注册到 admin server 中进行展示,Spring Boot Admin UI 部分使用 VueJs 将数据展示在前端。

项目地址:

一、Admin Server 端

项目依赖

  1. <dependencies>
  2. <dependency>
  3. <groupId>de.codecentric</groupId>
  4. <artifactId>spring-boot-admin-starter-server</artifactId>
  5. <version>2.1.0</version>
  6. </dependency>
  7. <dependency>
  8. <groupId>org.springframework.boot</groupId>
  9. <artifactId>spring-boot-starter-web</artifactId>
  10. </dependency>
  11. </dependencies>

配置文件

server:
  port: 8000

服务端设置端口为:8000。

启动类
添加 @EnableAdminServer 注解:

@SpringBootApplication
@EnableAdminServer
public class AdminServerApplication {
    public static void main(String[] args) {
        SpringApplication.run(AdminServerApplication.class, args);
    }
}

完成上面三步之后,启动服务端,浏览器访问http://localhost:8000可以看到界面

以下是添加一个客户端服务后的管理界面:
Snipaste_2021-01-04_20-51-38.png

二、Admin Client 端

项目依赖

<dependencies>
    <dependency>
      <groupId>de.codecentric</groupId>
      <artifactId>spring-boot-admin-starter-client</artifactId>
      <version>2.1.0</version>
    </dependency>
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
</dependencies>

配置文件

management:
  endpoints:
    web:
      exposure:
        include: '*'
server:
  port: 8001
spring:
  application:
    name: Admin Client
  boot:
    admin:
      client:
        url: 'http://localhost:8000'
  • spring.boot.admin.client.url 配置 Admin Server 的地址
  • management.endpoints.web.exposure.include=* 打开客户端 Actuator 的监控。

启动类

@SpringBootApplication
public class AdminClientApplication {
  public static void main(String[] args) {
    SpringApplication.run(AdminClientApplication.class, args);
  }
}

配置完成之后,启动 Client 端,Admin 服务端会自动检查到客户端的变化,并展示。