Spring Boot添加admin监控

什么是Spring Boot Admin?

Spring Boot Admin是一个用于管理和监控Spring Boot应用程序的Web应用程序。应用程序通过我们的Spring Boot Admin Client(通过HTTP)注册,或者使用Spring Cloud(例如Eureka, Consul)进行注册。

入门

设置Admin Server服务

  • 添加Spring Boot Admin Server starter依赖:
1
2
3
4
5
6
7
8
9
<dependency>
<groupId>de.codecentric</groupId>
<artifactId>spring-boot-admin-starter-server</artifactId>
<version>${spring-boot-admin.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
  • 在主配置类上添加@EnableAdminServer注解启用Server:
1
2
3
4
5
6
7
8
@Configuration
@EnableAutoConfiguration
@EnableAdminServer
public class SpringBootAdminApplication {
public static void main(String[] args) {
SpringApplication.run(SpringBootAdminApplication.class, args);
}
}

注册客户端应用

Spring Boot Admin Client

  • 添加spring-boot-admin-starter-client依赖:
1
2
3
4
5
<dependency>
<groupId>de.codecentric</groupId>
<artifactId>spring-boot-admin-starter-client</artifactId>
<version>${spring-boot-admin.version}</version>
</dependency>
  • 配置Spring Boot Admin Server的URL已注册应用:
1
2
spring.boot.admin.client.url=http://localhost:8080
management.endpoints.web.exposure.include=*

使用 Spring Cloud Discovery 注册

  • 添加spring-cloud-starter-eureka依赖:
1
2
3
4
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
  • 添加@EnableDiscoveryClient注解启用服务发现:
1
2
3
4
5
6
7
8
9
@Configuration
@EnableAutoConfiguration
@EnableDiscoveryClient
@EnableAdminServer
public class SpringBootAdminApplication {
public static void main(String[] args) {
SpringApplication.run(SpringBootAdminApplication.class, args);
}
}
  • 配置服务发现地址:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
eureka:
instance:
leaseRenewalIntervalInSeconds: 10
health-check-url-path: /actuator/health
metadata-map:
startup: ${random.int} #needed to trigger info and endpoint update after restart
client:
registryFetchIntervalSeconds: 5
serviceUrl:
defaultZone: ${EUREKA_SERVICE_URL:http://localhost:8761}/eureka/

management:
endpoints:
web:
exposure:
include: "*"
endpoint:
health:
show-details: ALWAYS

监控效果

浏览器访问http://localhost:8080

upload successful

upload successful

upload successful

upload successful

upload successful

upload successful

upload successful

upload successful

upload successful

upload successful

更多

Github
更多功能和官方文档

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