最近几个月天天加班,好久没更新博客了。
这两天排查一个CPU飙高导致服务假死的问题,常规套路:
jps
top -H -p 进程ID
jstack -l 高CPU线程
以上常规套路相信大家都比较熟练,但是当节点比较多的时候,就需要挨个进到机器或容器内,查看jvm堆栈情况,耗时耗力,如果能使用可视化工具就方便多了。Arthas(阿尔萨斯)需要单独部署成进程,部署复杂;springboot actuator作为信息采集客户端,springboot admin作为可视化页面,侵入性较小,因此选择后者,废话不多,上代码
1、业务服务(监控客户端)
1)pom
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>de.codecentric</groupId>
<artifactId>spring-boot-admin-starter-client</artifactId>
<version>2.3.1</version>
</dependency>
2)配置
server:
port: 8080
spring:
application:
name: test_server
admin:
enabled: true
boot:
admin:
client:
# 如果不是在同一个节点,只要使用内网地址和端口即可,容器部署需要将容器端口映射到宿主机
# springboot admin server 地址
url: http://127.0.0.1:3001
# springboot admin client 地址
instance:
service-url: http://127.0.0.1:8080
# springboot actuator
management:
endpoints:
web:
exposure:
include: info,health,metrics,httptrace,env,scheduledtasks,threaddump,heapdump
endpoint:
health:
show-details: always
2、监控及可视化服务(监控服务端)
1)pom
<dependencyManagement>
<dependencies>
<dependency>
<groupId>de.codecentric</groupId