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为注册的应用程序提供以下功能:
一、在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:
application:
name: admin-client
boot:
admin:
client:
url: http://localhost:8391
server:
port: 8768
management:
endpoints:
web:
exposure:
include: '*'
endpoint:
health:
show-details: ALWAYS