Spring Boot Admin是一个开源社区项目,用于管理和监控SpringBoot应用程序。 应用程序作为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 Admin为注册的应用程序提供以下功能:
- 显示健康状况
- 显示详细信息,例如
- JVM和内存指标
- micrometer.io指标
- 数据源指标
- 缓存指标
- 显示构建信息编号
- 关注并下载日志文件
- 查看jvm system-和environment-properties
- 查看Spring Boot配置属性
- 支持Spring Cloud的postable / env-和/ refresh-endpoint
- 轻松的日志级管理
- 与JMX-beans交互
- 查看线程转储
- 查看http-traces
- 查看auditevents
- 查看http-endpoints
- 查看计划任务
- 查看和删除活动会话(使用spring-session)
- 查看Flyway / Liquibase数据库迁移
- 下载heapdump
- 状态变更通知(通过电子邮件,Slack,Hipchat,......)
- 状态更改的事件日志(非持久性)
一、在bulid.gradle中添加
dependencies {
compile group: 'de.codecentric', name: 'spring-boot-admin-starter-server', version: '2.1.6'
compile group: 'org.springframework.boot', name: 'spring-boot-starter-mail'
compile group: 'com.alibaba.cloud', name: 'spring-cloud-starter-alibaba-nacos-discovery'
// 安全配置
compile group: 'org.springframework.boot', name: 'spring-boot-starter-security'
compile group: 'org.springframework.boot', name: 'spring-boot-starter-actuator'
compile group: 'org.springframework.boot', name: 'spring-boot-starter-web'
}
二、bootstrap.yml中
server:
port: 8391
tomcat:
max-threads: 500 # Maximum amount of worker threads.
min-spare-threads: 50 # Minimum amount of worker threads
pigframe:
nacos:
server-addr: 127.0.0.1:8848
namespace: 701cead9-85b6-4818-b411-130eef6d4240
spring:
application:
name: monitor
main:
allow-bean-definition-overriding: true
security:
user:
name: admin #SpringBootAdmin登录时的用户名
password: pigframe #SpringBootAdmin登录时的密码
cloud:
nacos:
discovery:
server-addr: ${pigframe.nacos.server-addr}
namespace: ${pigframe.nacos.namespace}
metadata:
user.name: ${spring.security.user.name}
user.password: ${spring.security.user.password}
boot:
admin:
notify:
mail:
enabled: true
to: 250502876@qq.com
from: xxx@163.com
# ignore-changes: UNKNOWN:UP
ignore-changes:
- "*:UP" #从任何状态到up状态都不要发邮件通知
ui:
title: 小猪快速开发框架监控
turbine:
clusters: default
#,unieap-eureka-server-single
location: monitor #turbine
routes:
endpoints: env,metrics,trace,dump,jolokia,info,configprops,trace,logfile,refresh,flyway,liquibase,heapdump,loggers,auditevents,hystrix.stream,turbine.stream,activiti
monitor:
# 超时时间(单位:ms)
read-timeout: 20000
mail:
host: smtp.163.com
port: 465
protocol: smtp
test-connection: false
default-encoding: UTF-8
username: xxx@163.com
password: 123456
properties:
mail:
imap:
ssl:
socketFactory:
fallback: false
smtp:
ssl:
enable: true
socketFactory:
class: com.fintech.modules.util.MailSSLSocketFactory
auth : true
timeout : 2000
starttls:
enable : true
required : true
turbine:
app-config: gateway #收集监控信息的服务名
combine-host-port: true
cluster-name-expression: new String('default') #集群名称
#设置最大超时时间
ribbon:
eager-load:
enabled: true
ServerListRefreshInterval: 10 #刷新服务列表源的间隔时间
OkToRetryOnAllOperations: true
MaxAutoRetries: 1
MaxAutoRetriesNextServer: 1
ReadTimeout: 16000
ConnectTimeout: 16000
management:
endpoints:
web:
exposure:
include: "*"
endpoint:
health:
show-details: always
三、启动类
@EnableAdminServer
@EnableDiscoveryClient
@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class})
public class MonitorApplication {
public static void main(String[] args) {
SpringApplication.run(MonitorApplication.class, args);
System.out.println("==================MonitorApplication Start============");
}
}
四、注册到注册中心的客户端
management:
endpoints:
web:
exposure:
include: '*'
endpoint:
health:
show-details: ALWAYS
五、如果是不注册到注册中的客户端平配置
compile group: 'de.codecentric', name: 'spring-boot-admin-starter-client'
- spring.boot.admin.client.url:要注册的Spring Boot Admin Server的URL。
- management.endpoints.web.exposure.include:与Spring Boot 2一样,默认情况下,大多数actuator的端口都不会通过http公开,* 代表公开所有这些端点。对于生产环境,应该仔细选择要公开的端点。
spring:
application:
name: admin-client
boot:
admin:
client:
url: http://localhost:8391
server:
port: 8768
management:
endpoints:
web:
exposure:
include: '*'
endpoint:
health:
show-details: ALWAYS