Arthas

Arthas(阿尔萨斯)是阿里巴巴开源的 Java 诊断工具
在线文档
在线教程
Arthas 可以帮助解决以下问题:

  1. 这个类从哪个 jar 包加载的?
  2. 我改的代码为什么没有执行到?难道是我没 commit?分支搞错了?

通过jad反编译指令,查看指定类的源码和来源信息

image.png
  1. 遇到问题无法在线上 debug,难道只能通过加日志再重新发布吗?

通过watch指令观察到指定方法的调用情况。能观察的范围为:返回值、抛出异常、入参

参数说明

watch 的参数比较多,主要是因为它能在 4 个不同的场景观察对象

假设访问 http://localhost/user/0 ,会返回500异常:

{"timestamp":1550223186170,"status":500,"error":"Internal Server Error","exception":"java.lang.IllegalArgumentException","message":"id < 1","path":"/user/0"}

在Arthas里执行:

watch com.example.demo.arthas.user.UserController * '{params, throwExp}'

第一个参数是类名,支持通配
第二个参数是函数名,支持通配,*指匹配所有
第三个参数是返回值表达式,是一个ognl表达式,它支持一些内置对象:
loader、clazz、method、target、params、returnObj、throwExp、isBefore、isThrow、isReturn
更多参考: https://arthas.aliyun.com/doc/advice-class.html

访问http://localhost/user/0 ,watch命令会打印调用的参数和异常

$ watch com.example.demo.arthas.user.UserController * '{params, throwExp}'
Press Q or Ctrl+C to abort.
Affect(class-cnt:1 , method-cnt:2) cost in 53 ms.
ts=2019-02-15 01:35:25; [cost=0.996655ms] result=@ArrayList[
@Object[][isEmpty=false;size=1],
@IllegalArgumentException[java.lang.IllegalArgumentException: id < 1],

  • 满足特定条件,触发响应
watch com.example.demo.arthas.user.UserController * '{params, throwExp}' 'params[0] >100'
  • 出现异常时,触发响应
watch com.example.demo.arthas.user.UserController * '{params, throwExp}' -e

4.线上遇到某个用户的数据处理有问题,但线上同样无法 debug,线下无法重现!
tt命令对方法执行数据的时空隧道,记录下指定方法每次调用的入参和返回信息,并能对这些不同的时间下调用进行观测
https://arthas.aliyun.com/doc/tt.html

你可能感兴趣的:(Arthas)