Arthas 简单使用

Arthas基本操作

启动

非正常环境下启动

在docker环境下运行,并且没有jdk,只有jre环境,而且pid进程好为1,可以使用下发的方式启动。

# 1、进入容器
docker exec -it [container_id | container_name] bin/bash
# 2、查询当前jre环境所在位置
which java
# 3、下在arthas的编译压缩包
wget -O arthas.zip "https://arthas.aliyun.com/download/latest_version?mirror=aliyun"
# 4、将压缩包解压在 jre 的,如果没有安装 zip 解压工具,将arthas解压到java同一级目录下
apt update
apt install zip
unzip arthas.zip -d /opt/arthas
# 5、安装 jattach 工具
apt install jattach
# 6、jattach 当前运行的java进程,使用ps命令查询pid,开源工具 https://github.com/jattach/jattach
ps aux|grep java
jattach pid load instrument false /opt/arthas/arthas-agent.jar
# 7、arthas连接该进程,启动
java -jar /opt/arthas/arthas-client.jar 127.0.0.1 3658

常用命令

观察函数入参

watch cn.catguild.auth.oauth.service.CatUserDetailsService loadUserByUsername "{params,returnObj}" -x 2 -b

参考