Arthas应用诊断-常用命令介绍

1 简介

Arthas 是一款线上监控诊断产品,通过全局视角实时查看应用 load、内存、gc、线程的状态信息,并能在不修改应用代码的情况下,对业务问题进行诊断,包括查看方法调用的出入参、异常,监测方法执行耗时,类加载信息等,大大提升线上问题排查效率。

官方文档:arthas

2 下载安装

wget https://arthas.aliyun.com/arthas-boot.jar;
java -jar arthas-boot.jar

3 Thread:线程相关堆栈信息

# 查看处于等待状态的线程(WAITING、BLOCKED)
thread --state WAITING
# 查看线程状态
thread
# 查看阻塞的线程信息        
thread -b

4 Monitor:监控方法的执行情况

# 监控com.example.demo.controller.DemoController类,并且每5S更新一次状态。
monitor com.example.demo.controller.DemoController helloWord -c 5

5 Watch:检测函数返回值

# 查看方法执行的返回值
watch com.example.demo.controller.DemoController helloWord returnObj
# 观察com.example.demo.controller.DemoController类中helloWord方法出参和返回值,结果属性遍历深度为2。
# params:表示所有参数数组(因为不确定是几个参数)。
# returnObject:表示返回值
watch com.example.demo.controller.DemoController helloWord "{params,returnObj}" -x 2

# 查看方法中的属性
watch com.example.demo.controller.DemoController helloWord "{target}" -x 2 -b
# 查看某一属性的值
watch com.example.demo.controller.DemoController helloWord "{target.demoService}" -x 2 -b

# 检测方法在执行前-b、执行后-s的入参params、属性target和返回值returnObj
watch com.example.demo.controller.DemoController helloWord "{params,target,returnObj}" -x 2 -b -s -n 2

6 Trace:根据路径追踪,并记录消耗时间

# trace函数指定类的指定方法
trace com.example.demo.controller.DemoController helloWord
# 据调用耗时过滤,trace大于0.5ms的调用路径
trace com.example.demo.controller.DemoController helloWord '#cost > .5'
# 可以用正则表匹配路径上的多个类和函数,一定程度上达到多层trace的效果。
trace -E com.test.ClassA|org.test.ClassB method1|method2|method3

7 Stack:输出当前方法被调用的调用路径

# 获取primeFactors的调用路径
stack com.example.demo.controller.DemoController helloWord
# 条件表达式来过滤,第0个参数的值小于0,-n表示获取2次
stack com.example.demo.controller.DemoController helloWord 'params[1]<20' -n 2
# 据执行时间来过滤,耗时大于0.5毫秒
stack com.example.demo.controller.DemoController helloWord '#cost>0.5'

8 tt:时间隧道,记录多个请求

# 最基本的使用来说,就是记录下当前方法的每次调用环境现场。
tt -t com.example.demo.controller.DemoController helloWord
# 对现有记录进行检索
tt -l
# 需要筛选出 `helloWord` 方法的调用信息
tt -s 'method.name=="helloWord"'
# 查看某条记录详细信息
tt -i 1002

8 jad:反编译已加载类源码

# 反编译MathGame方法
jad com.example.demo.controller.DemoController
# 反编绎时只显示源代码(排除ClassLoader信息)。
# 默认情况下,反编译结果里会带有ClassLoader信息,通过--source-only选项,可以只打印源代码。方便和mc/redefine命令结合使用。
jad --source-only com.example.demo.controller.DemoController
# 反编译到指定文件中
jad --source-only com.example.demo.controller.DemoController > DemoController.java
# 只反编译mathGame类型中main方法
jad com.example.demo.controller.DemoController helloWord

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值