源码地址
原文地址:http://www.waphnb.com/article/78
Spring Boot Admin简介
Spring Boot Admin是一个开源社区项目,用于管理和监控SpringBoot应用程序。 应用程序作为Spring Boot Admin Client向为Spring Boot Admin Server注册(通过HTTP)或使用SpringCloud注册中心(例如Eureka,Consul)发现。 UI是的AngularJs应用程序,展示Spring Boot Admin Client的Actuator端点上的一些监控。常见的功能或者监控如下:
- 显示健康状况
- 显示详细信息,例如
- JVM和内存指标
- micrometer.io指标
- 数据源指标
- 缓存指标
- 显示构建信息编号
- 关注并下载日志文件
- 查看jvm系统和环境属性
- 查看Spring Boot配置属性
- 支持Spring Cloud的postable / env-和/ refresh-endpoint
- 轻松的日志级管理
- 与JMX-beans交互
- 查看线程转储
- 查看http跟踪
- 查看auditevents
- 查看http-endpoints
- 查看计划任务
- 查看和删除活动会话(使用spring-session)
- 下载heapdump
- 状态变更通知(通过电子邮件,Slack,Hipchat,......)
- 状态更改的事件日志(非持久性)
一、快速开始,创建admin-server工程加入依赖如下
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>spingcloud-study</artifactId>
<groupId>spingcloud</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>admin-server</artifactId>
<dependencies>
<dependency>
<groupId>de.codecentric</groupId>
<artifactId>spring-boot-admin-starter-server</artifactId>
<version>2.1.4</version>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.jolokia</groupId>
<artifactId>jolokia-core</artifactId>
</dependency>
</dependencies>
</project>
二、yml配置文件如下
spring:
application:
name: admin-server
profiles:
active:
- secure
server:
port: 9997
# tag::configuration-eureka[]
eureka: #<1>
instance:
leaseRenewalIntervalInSeconds: 10
health-check-url-path: /actuator/health
client:
registryFetchIntervalSeconds: 5
serviceUrl:
defaultZone: http://localhost:7081/eureka/,http://localhost:7082/eureka/,http://localhost:7083/eureka/
management:
endpoints:
web:
exposure:
include: "*" #<2>
endpoint:
health:
show-details: ALWAYS
# end::configuration-eureka[]
---
spring:
profiles: insecure
---
spring:
profiles: secure
security:
user:
name: "user"
password: "password"
eureka:
instance:
metadata-map:
user.name: "user" #These two are needed so that the server
user.password: "password" #can access the protected client endpoints
三、启动项目,查看是否注册到注册中心
四、admin-server启动注册成功之后,在前文的各个系统中依次加入如下配置
spring:
boot:
admin:
client:
url: "http://localhost:9997"
period: 600
management:
endpoints:
web:
exposure:
include: '*'
endpoint:
health:
show-details: ALWAYS
并加入pom依赖
<dependency>
<groupId>de.codecentric</groupId>
<artifactId>spring-boot-admin-starter-client</artifactId>
<version>2.1.4</version>
</dependency>
五、依次启动项目,浏览器访问http://localhost:9997 打开springboot admin 输入账号/密码:user/password,
可以看到服务已经可以在SpringBootAdmin中展现出来了,如果服务出问题会标红,这里config-server标红是因为git仓库密码不对,大家可以改成自己仓库的地址和账号密码,我们可以通过springboot进行文章开始之前描述的各种功能啦