0%

SpringBoot-使用Admin监控

前言

Spring Boot Admin 是一个管理和监控Spring Boot 应用程序的开源软件。应用程序作为Spring Boot Admin Client向为Spring Boot Admin Server注册(通过HTTP)或使用SpringCloud注册中心(例如Eureka,Consul)发现。UI是Vue.js应用程序,展示Spring Boot Admin Client的Actuator端点上的一些监控。服务端采用Spring WebFlux + Netty的方式。 是一个针对spring-boot的actuator接口进行UI美化封装的监控工具。可以在列表中浏览所有被监控spring-boot项目的基本信息,详细的Health信息、内存信息、JVM信息、垃圾回收信息、各种配置信息(比如数据源、缓存列表和命中率)等,还可以直接修改logger的level。Actuator监控可参考SpringBoot 使用Actuator监控

搭建 Spring Boot Admin Server

pom.xml文件

spring-boot-admin-server-ui在2.0之后采用了Vue.js应用程序。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
<dependencies>
<!--admin-server-->
<dependency>
<groupId>de.codecentric</groupId>
<artifactId>spring-boot-admin-server</artifactId>
<version>2.1.5</version>
</dependency>
<!--admin-server-ui-->
<dependency>
<groupId>de.codecentric</groupId>
<artifactId>spring-boot-admin-server-ui</artifactId>
<version>2.1.5</version>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

启动类

添加注解@EnableAdminServer。

1
2
3
4
5
6
7
8
9
@SpringBootApplication
@EnableAdminServer
public class SpringbootAdminServerApplication {

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

}

启动项目

启动项目后访问,可以看到页面。
image.png

搭建 Spring Boot Admin Client

pom.xml文件

服务端采用Spring WebFlux + Netty的方式,我们的项目使用web+Tomcat方式。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>de.codecentric</groupId>
<artifactId>spring-boot-admin-starter-client</artifactId>
<version>2.1.5</version>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

配置文件

  • 因为spring-boot-admin-starter-client依赖包含spring-boot-starter-actuator依赖,所以这里可以直接配置actuator属性。
  • spring.boot.admin.client.url:要注册的Spring Boot Admin Server的URL。
  • management.endpoints.web.exposure.include:* 代表公开所有这些端点。
  • management.endpoints.web.exposure.exclude:设置屏蔽的端点。
  • info为端点项目信息。
  • 因为本机项目,需要设置不同的端口。
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    server:
    port: 8083

    spring:
    boot:
    admin:
    client:
    url: http://localhost:8080
    instance:
    name: ReactiveCrud

    info:
    name: spring-boot-actuator-test
    description: springboot-admin-client-description
    version: 1.0.0

    management:
    endpoints:
    web:
    exposure:
    include: "*"
    #屏蔽env,beans监控点
    exclude: env,beans

    启动项目

    image.png
    image.png
    image.png

欢迎关注我的其它发布渠道