一、介绍
主要是用于管理和监控SpringBoot的应用
是在Spring Boot Actuator端点上监控和管理的应用程序。
由两部分组成,
客户端(admin client)
将SpringBoot的应用注册到admin server
位于受监视的应用程序中
服务器(admin server)
统一监控这SpringBoot服务状态和配置
包含管理员用户界面,并独立于受监视的应用程序运行
1.1、 场景
适用小型应用
对于大型分布式集群应用不建议使用,而是使用下面的
Apache Skywalking
Prometheus Grafana
二、向Admin Server注册的方式
使用 Spring Boot Admin Client 来注册
使用 Eureka 注册中心 来注册
使用 Consul 注册中心 来注册
三、Spring Boot Admin 提供的功能
- 显示健康状况
- 显示详细信息:JVM和内存指标、micrometer.io指标、 数据源指标、缓存指标
- 显示内部编号
- 关注并下载日志文件
- 查看JVM系统和环境属性
- 查看Spring Boot配置属性
- 支持Spring Cloud的可发布/ env-&/ refresh-endpoint
- 轻松的日志级别管理
- 与JMX-beans交互
- 查看线程转储
- 查看http-traces
- 查看审核事件
- 查看http端点
- 查看预定的任务
- 查看和删除活动会话(使用spring-session)
- 查看Flyway / Liquibase数据库迁移
- 下载heapdump
- 状态更改通知(通过电子邮件,Slack,Hipchat等)
- 状态更改的事件日志(非持久性)
四、配置Spring Boot Admin Server
pom.xml
<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.1</version>
</dependency>
AdminServerApplication
//开启 Admin 的 Server
@EnableAdminServer
@SpringBootApplication
public class AdminServerApplication {
public static void main(String[] args) {
SpringApplication.run(AdminServerApplication.class, args);
}
}
localhost:8080查看效果
界面改中文
五、配置 Spring Boot Admin Client
pom.xml
<dependencies>
<dependency>
<groupId>de.codecentric</groupId>
<artifactId>spring-boot-admin-starter-client</artifactId>
<version>2.3.1</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
application.yml
# 应用程序名称
spring:
application:
name: admin-clientboot:
admin:
client:
# Admin Server的URL,若是要注册到多个admin服务端上,用逗号分隔就可以
# url: http://localhost:8080,http://localhost:8081
url: http://localhost:8080
instance:
# 使用IP的方式
prefer-ip: true
# 应用程序端口
server:
port: 9090
# 默认情况下,大多数Actuator端点都不通过http公开,这里我们公开了所有端点。
# 对于生产,您应该仔细选择要公开的端点。management:
endpoints:
web:
exposure:
include: ["*"]
启动类无需修改,直接启动项目
localhost:8080查看效果
点击应用
点击“应用墙”
点击“日志报表”
六、结合Eureka注册中心使用
1.搭建Eureka注册中心
具体看springCloud介绍
2.Admin 结合Eureka
admin-server 会自己拉取 Eureka 上注册的 服务信息,自动完成注册。
admin-client 端 不需要配置 admin 地址了,一切全部由 admin-server 自己实现。
Admin Server注册到Eureka注册中心
添加Eureka Client依赖
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
<version>2.2.6.RELEASE</version>
</dependency>
启动类,添加@EnableEurekaClient,让注册中心发现
//eureka 客户端
@EnableEurekaClient
修改配置项
# 应用程序名称
spring:
application:
name: admin-server
# 应用程序端口
server:
port: 8080# 默认情况下,大多数端点都不通过http公开,我们公开了所有端点。
# 对于生产,您应该仔细选择要公开的端点。management:
endpoints:
web:
exposure:
include: ["*"]
health:
show-details: always# eureka客户端配置
eureka:
client:
service-url:
defaultZone: http://127.0.0.1:9091/eureka
instance:
# iP方式显示
ip-address: true
#注册中心显示的实例ID,可以用ip地址加端口来区别
instance-id: ${spring.cloud.client.ip-address}:${server.port}
# 检查健康的actuator端点地址
health-check-url-path: /actuator/health
启动服务,注册中心列表和admin都已经完成注册
2.2、Admin Client注册到Eureka注册中心
添加Eureka Client 依赖
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
<version>2.2.6.RELEASE</version>
</dependency>
修改配置文件
# 应用程序名称
spring:
application:
name: admin-client# 应用程序端口
server:
port: 9090
# 通过注册中心发现,就不需要自己注册了
# boot:
# admin:
# client:
# # admin 的server地址
# url: http://localhost:8080
# instance:
# # 使用IP的方式
# prefer-ip: true
# 默认情况下,大多数端点都不通过http公开,我们公开了所有端点。
# 对于生产,您应该仔细选择要公开的端点。management:
endpoints:
web:
exposure:
include: ["*"]
endpoint:
health:
show-details: always
# 通过注册中心发现,就不需要自己注册了
# eureka客户端配置
eureka:
client:
service-url:
defaultZone: http://127.0.0.1:9091/eureka
instance:
# iP方式显示
ip-address: true
#注册中心显示的实例ID,可以用ip地址加端口来区别
instance-id: ${spring.cloud.client.ip-address}:${server.port}
# 检查健康的actuator端点地址
health-check-url-path: /actuator/health
启动类
// Eureka 客户端
@EnableEurekaClient
服务启动,完成Eureka和Admin的注册
2.3、springAdmin显示为IP
修改配置
# admin 中已ip显示
hostname: ${spring.cloud.client.ip-address}
效果