# 01-Arthas
# 一、官网地址 (opens new window)
下载
curl -O https://arthas.aliyun.com/arthas-boot.jar
启动
java -jar arthas-boot.jar #打印帮助信息 java -jar arthas-boot.jar -h
# 二、命令列表 (opens new window)
命令 | 说明 |
---|---|
dashboard (opens new window) | 当前系统的实时数据面板,按 ctrl+c 退出 |
thread (opens new window) | 查看当前线程信息,查看线程的堆栈 |
jvm (opens new window) | 查看当前JVM信息 |
sysprop (opens new window) | 查看当前JVM的系统属性(System Property ) |
sysenv (opens new window) | 查看当前JVM的环境属性(System Environment Variables ) |
vmoption (opens new window) | 查看,更新VM诊断相关的参数 |
perfcounter (opens new window) | 查看,当前JVM的 Perf Counter信息 |
logger (opens new window) | 查看logger信息,更新logger level |
mbean (opens new window) | 查看 Mbean 的信息 |
getstatic (opens new window) | 查看类的静态属性,使用方法为getstatic class_name field_name 推荐直接使用ognl (opens new window)命令,更加灵活 |
ognl (opens new window) | 执行ognl表达式 |
sc (opens new window) | “Search-Class” 的简写,查看JVM已加载的类信息 |
sm (opens new window) | “Search-Method” 的简写,查看已加载类的方法信息 |
dump (opens new window) | dump 已加载类的 bytecode 到特定目录 |
heapdump (opens new window) | dump java heap, 类似jmap命令的heap dump功能。 |
jad (opens new window) | 反编译指定已加载类的源码 |
classloader (opens new window) | 查看classloader的继承树,urls,类加载信息 |
mc (opens new window) | Memory Compiler/内存编译器,编译.java 文件生成.class 。 |
retransform (opens new window) | 加载外部的.class 文件,retransform jvm已加载的类。 |
redefine (opens new window) | 加载外部的.class 文件,redefine jvm已加载的类。 |
monitor (opens new window) | 方法执行监控 |
watch (opens new window) | 方法执行数据观测 |
trace (opens new window) | 方法内部调用路径,并输出方法路径上的每个节点上耗时 |
stack (opens new window) | 输出当前方法被调用的调用路径 |
tt (opens new window) | 方法执行数据的时空隧道,记录下指定方法每次调用的入参和返回信息,并能对这些不同的时间下调用进行观测 |
profiler (opens new window) | 使用async-profiler (opens new window)生成火焰图 |
cat (opens new window) | 打印文件内容,和linux里的cat命令类似。 |
echo (opens new window) | 打印参数,和linux里的echo命令类似 |
grep (opens new window) | 类似传统的grep 命令 |
base64 (opens new window) | base64编码转换,和linux里的 base64 命令类似。 |
tee (opens new window) | 类似传统的tee 命令, 用于读取标准输入的数据,并将其内容输出成文件。tee指令会从标准输入设备读取数据,将其内容输出到标准输出设备,同时保存成文件 |
pwd (opens new window) | 返回当前的工作目录,和linux命令类似 |
options (opens new window) | 全局开关 |
Arthas 基础命令 | |
help | 查看命令帮助信息 |
cls | 清空当前屏幕区域 |
session | 查看当前会话的信息 |
reset (opens new window) | 重置增强类,将被 Arthas 增强过的类全部还原,Arthas 服务端关闭时会重置所有增强过的类 |
version | 输出当前目标 Java 进程所加载的 Arthas 版本号 |
history | 打印命令历史 |
quit | 退出当前 Arthas 客户端,其他 Arthas 客户端不受影响 |
stop | 关闭 Arthas 服务端,所有 Arthas 客户端全部退出 |
keymap (opens new window) | Arthas快捷键列表及自定义快捷键 |
# 三、案例:
Arthas ——生产环境排查 CPU 飚高问题
- 登录服务器,执行 top命令,查看java进程是否cpu使用率较高
- 启动arthas,执行 dashboard 命令,找到cpu使用率较高的线程
- 执行 thread [ID] 命令,定位代码行