最近研究了一下springboot监控,做一个简单的总结
注:
1.actuator需要api访问;admin提供页面显示及部分分析
2. actuator可以通过配置开启,关闭,较灵活;admin server-client注册机制,有代码侵入
3.插件需要严格遵守与springboot,springcloud版本兼容性,springboot2.0前后配置差异比较大,以下依赖与配置皆以springboot 版本1.5.7.RELEASE,springcloud 版本Dalston.SR4为准。
一.Springboot actuator
1.导入依赖:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</exclusion>
</exclusions>
</dependency>
2.添加配置:
# http安全机制
security:
user:
name: admin
password: 123456
management:
security:
#如果不使用密码,直接false
enabled: true
role: ADMIN
#配置前缀
context-path: /actuator
endpoints:
#关闭全部接口,开启全部为true,默认为true
enabled: false
#开启dump,trace接口,全部开启,以下内容可以注释掉
dump:
enabled: true
trace:
enabled: true
二.Springboot admin
1.server端
a)添加依赖
<dependency>
<groupId>de.codecentric</groupId>
<artifactId>spring-boot-admin-server</artifactId>
<version>1.5.5</version>
</dependency>
<dependency>
<groupId>de.codecentric</groupId>
<artifactId>spring-boot-admin-server-ui</artifactId>
<version>1.5.5</version>
</dependency>
<dependency>
<groupId>de.codecentric</groupId>
<artifactId>spring-boot-admin-starter-client</artifactId>
<version>1.5.5</version>
</dependency>
b)启动类添加注解
@EnableAdminServer
c)添加配置
#添加前缀
spring.boot.admin. context-path= /admin
#要注册到的server url
spring.boot.admin.url= http://localhost:8080/admin
#关闭验证
management.security.enabled= false
2.client端
a)添加依赖
<dependency>
<groupId>de.codecentric</groupId>
<artifactId>spring-boot-admin-starter-client</artifactId>
<version>1.5.5</version>
</dependency>
b)添加配置
#要注册到的server url
spring.boot.admin.url= http://localhost:8080/admin
#关闭验证
management.security.enabled= false
版本兼容对应
| spring-boot-admin | spring-boot | spring-cloud |
|---|---|---|
| 2.5.1 | 2.5.4 | |
| 2.5.0 | 2.5.2 | |
| 2.4.4 | 2.5.2 | |
| 2.4.2 | 2.4.6 | |
| 2.4.1 | 2.4.3 | 2020.0.1 |
| 2.4.0 | 2.4.0 | |
| 2.3.1 | 2.3.3.RELEASE | |
| 2.3.0 | 2.3.2.RELEASE | Hoxton.SR7 |
| 2.2.3 | 2.2.7.RELEASE | Hoxton.SR4 |
| 2.2.0 | 2.2.1.RELEASE | Hoxton |
| 2.1.6 | 2.1.6.RELEASE | Greenwich.SR2 |
| 2.1.4 | 2.1.4.RELEASE | Greenwich.SR1 |
| 2.1.3 | 2.1.3.RELEASE | Greenwich |
| 2.1.2 | 2.1.2.RELEASE | |
| 2.1.0 | 2.1.0.RELEASE | |
| 2.0.6 | 2.0.9.RELEASE | Finchley.SR3 |
| 2.0.5 | 2.0.8.RELEASE | Finchley.SR2 |
| 2.0.4 | 2.0.6.RELEASE | |
| 2.0.3 | 2.0.5.RELEASE | |
| 2.0.0 | 2.0.x.RELEASE | |
| 1.5.5 | 1.5.8.RELEASE | Edgware.SR1 |
| 1.5.5 | 1.5.8.RELEASE | Dalston SR4 |
| 1.5.4 | 1.5.x.RELEASE | Dalston SR3 |
| 1.5.0 | 1.5.x.RELEASE | |
| 1.4.6 | 1.4.4.RELEASE | Camden.SR5 |
| 1.4.5 | 1.4.3.RELEASE | Camden.SR3 |
| 1.4.4 | 1.4.2.RELEASE | Camden.SR2 |
| 1.4.3 | 1.4.1.RELEASE | Camden |
| 1.4.2 | 1.4.1.RELEASE | |
| 1.4.1 | 1.4.0.RELEASE | |
| 1.3.7 | 1.3.8.RELEASE | Brixton.SR6 |
| 1.3.6 | 1.3.6.RELEASE | Brixton.SR4 |
| 1.3.5 | 1.3.6.RELEASE | Brixton.SR3 |
| 1.3.4 | 1.3.5.RELEASE | Brixton.SR1 |
| 1.3.3 | 1.3.5.RELEASE | Brixton |
| 1.3.0 | 1.3.0.RELEASE | |
| 1.2.4 | 1.2.7.RELEASE | |
| 1.2.2 | 1.2.5.RELEASE | Angel.SR3 |
| 1.2.1 | 1.2.3.RELEASE | 1.0.1.RELEASE |
| 1.1.0 | 1.2.0.RELEASE |
个人认为最有用的就是/dump节点(springboot2.0为threaddump)简单分析下线程状态
/heapdump 可以直接导出.gzip堆转储文件,解压后可以使用jdk自带的jvisualvm.exe打开分析堆内存情况
浙公网安备 33010602011771号