Arthas(阿尔萨斯)

Arthas(阿尔萨斯)

简介

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

Arthas 能为你做什么?

当你遇到以下类似问题而束手无策时,Arthas可以帮助你解决:

  1. 这个类从哪个 jar 包加载的?为什么会报各种类相关的 Exception?

  2. 我改的代码为什么没有执行到?难道是我没 commit?分支搞错了?

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

  4. 线上遇到某个用户的数据处理有问题,但线上同样无法 debug,线下无法重现!

  5. 是否有一个全局视角来查看系统的运行状况?

  6. 有什么办法可以监控到 JVM 的实时运行状态?

  7. 怎么快速定位应用的热点,生成火焰图?

  8. 怎样直接从 JVM 内查找某个类的实例?

Arthas 支持 JDK 6+,支持 Linux/Mac/Windows,采用命令行交互模式,同时提供丰富的 Tab 自动补全功能,进一步方便进行问题的定位和诊断

Arthas安装和启动

curl -O https://arthas.aliyun.com/arthas-boot.jar
java -jar arthas-boot.jar
  • 执行该程序的用户需要和目标进程具有相同的权限。比如以admin用户来执行:sudo su admin && java -jar arthas-boot.jarsudo -u admin -EH java -jar arthas-boot.jar

  • 如果 attach 不上目标进程,可以查看~/logs/arthas/ 目录下的日志。

  • 如果下载速度比较慢,可以使用 aliyun 的镜像:

    `java -jar arthas-boot.jar --repo-mirror aliyun --use-http
  • java -jar arthas-boot.jar -h 打印更多参数信息

选择应用 java 进程

 

 

比如想跟踪 com.example.demo.DemoApplication则输入1后回车

[INFO] arthas home: D:\tools\arthas-packaging-3.6.7-bin
[INFO] The target process already listen port 3658, skip attach.
[INFO] arthas-client connect 127.0.0.1 3658
,---. ,------. ,--------.,--. ,--. ,---.   ,---.
/ O \ | .--. ''--. .--'| '--' | / O \ '   .-'
| .-. || '--'.'   | |   | .--. || .-. |`. `-.
| | | || |\ \   | |   | | | || | | |.-'   |
`--' `--'`--' '--'   `--'   `--' `--'`--' `--'`-----'

wiki       https://arthas.aliyun.com/doc
tutorials https://arthas.aliyun.com/doc/arthas-tutorials.html
version   3.6.7
main_class
pid       5132
time       2023-03-19 16:44:31

常用命令

watch命令

查看方法的入参(params)、返回值(returnObj)、调用方法的(target)、

target : the object
method : the constructor or method
params : the parameters array of method
params[0..n] : the element of parameters array
returnObj : the returned object of method
throwExp : the throw exception of method
isReturn : the method ended by return
isThrow : the method ended by throwing exception
#cost : the execution time in ms of method invocation

语法格式

watch 类名 方法名 需要监听的参数
watch 类名 方法名 # 默认监听 入参,target、返回值
watch 类名 方法名 '{params,target,returnObj}'

举例

watch org.apache.commons.lang.StringUtils isBlank
watch org.apache.commons.lang.StringUtils isBlank '{params, target, returnObj, throwExp}' -x 2
watch *StringUtils isBlank params[0] params[0].length==1
watch *StringUtils isBlank params '#cost>100'
watch -f *StringUtils isBlank params
watch *StringUtils isBlank params[0]
watch -E -b org\.apache\.commons\.lang\.StringUtils isBlank params[0]

类名和方法名可以使用通配符*

-x 表示对象的显示层级,可以写大点

可以使用tab补全

 

 

trace命令

跟踪方法内部的调用路径,并输出方法路径上的每一个节点上的耗时

命令格式:

trace 类名 方法名

 

 

 

Arthas(阿尔萨斯)

简介

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

Arthas 能为你做什么?

当你遇到以下类似问题而束手无策时,Arthas可以帮助你解决:

  1. 这个类从哪个 jar 包加载的?为什么会报各种类相关的 Exception?

  2. 我改的代码为什么没有执行到?难道是我没 commit?分支搞错了?

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

  4. 线上遇到某个用户的数据处理有问题,但线上同样无法 debug,线下无法重现!

  5. 是否有一个全局视角来查看系统的运行状况?

  6. 有什么办法可以监控到 JVM 的实时运行状态?

  7. 怎么快速定位应用的热点,生成火焰图?

  8. 怎样直接从 JVM 内查找某个类的实例?

Arthas 支持 JDK 6+,支持 Linux/Mac/Windows,采用命令行交互模式,同时提供丰富的 Tab 自动补全功能,进一步方便进行问题的定位和诊断

Arthas安装和启动

curl -O https://arthas.aliyun.com/arthas-boot.jar
java -jar arthas-boot.jar
  • 执行该程序的用户需要和目标进程具有相同的权限。比如以admin用户来执行:sudo su admin && java -jar arthas-boot.jarsudo -u admin -EH java -jar arthas-boot.jar

  • 如果 attach 不上目标进程,可以查看~/logs/arthas/ 目录下的日志。

  • 如果下载速度比较慢,可以使用 aliyun 的镜像:

    `java -jar arthas-boot.jar --repo-mirror aliyun --use-http
  • java -jar arthas-boot.jar -h 打印更多参数信息

选择应用 java 进程

image-20230319211539696

比如想跟踪 com.example.demo.DemoApplication则输入1后回车

[INFO] arthas home: D:\tools\arthas-packaging-3.6.7-bin
[INFO] The target process already listen port 3658, skip attach.
[INFO] arthas-client connect 127.0.0.1 3658
,---. ,------. ,--------.,--. ,--. ,---.   ,---.
/ O \ | .--. ''--. .--'| '--' | / O \ '   .-'
| .-. || '--'.'   | |   | .--. || .-. |`. `-.
| | | || |\ \   | |   | | | || | | |.-'   |
`--' `--'`--' '--'   `--'   `--' `--'`--' `--'`-----'

wiki       https://arthas.aliyun.com/doc
tutorials https://arthas.aliyun.com/doc/arthas-tutorials.html
version   3.6.7
main_class
pid       5132
time       2023-03-19 16:44:31

常用命令

watch命令

查看方法的入参(params)、返回值(returnObj)、调用方法的(target)、

target : the object
method : the constructor or method
params : the parameters array of method
params[0..n] : the element of parameters array
returnObj : the returned object of method
throwExp : the throw exception of method
isReturn : the method ended by return
isThrow : the method ended by throwing exception
#cost : the execution time in ms of method invocation

语法格式

watch 类名 方法名 需要监听的参数
watch 类名 方法名 # 默认监听 入参,target、返回值
watch 类名 方法名 '{params,target,returnObj}'

举例

watch org.apache.commons.lang.StringUtils isBlank
watch org.apache.commons.lang.StringUtils isBlank '{params, target, returnObj, throwExp}' -x 2
watch *StringUtils isBlank params[0] params[0].length==1
watch *StringUtils isBlank params '#cost>100'
watch -f *StringUtils isBlank params
watch *StringUtils isBlank params[0]
watch -E -b org\.apache\.commons\.lang\.StringUtils isBlank params[0]

类名和方法名可以使用通配符*

-x 表示对象的显示层级,可以写大点

可以使用tab补全

image-20230319212645349

trace命令

跟踪方法内部的调用路径,并输出方法路径上的每一个节点上的好事

命令格式:

trace 类名 方法名

 

posted @ 2023-03-19 21:35  ilovetesting  阅读(167)  评论(0编辑  收藏  举报