介绍
arthas是阿里开源的java监控和调试工具
Arthas 是基于 Greys 进行二次开发的全新在线诊断工具,利用Java6的Instrumentation特性,
动态增强你所指定的类,获取你想要到的信息, 采用命令行交互模式,同时提供丰富的 Tab 自动补全功能,
让你在定位、分析诊断问题时看每一个操作都看起来是强大
doc --> https://alibaba.github.io/arthas/
code --> https://github.com/alibaba/arthas/releases/tag/arthas-all-3.0.5
- 这个类从哪个 jar 包加载的?为什么会报各种类相关的 Exception?
- 我改的代码为什么没有执行到?难道是我没 commit?分支搞错了?
- 遇到问题无法在预发 debug 一下,难道只能通过加日志再重新预发布吗?
- 线上遇到某个用户的数据处理有问题,但线上同样无法 debug,线下无法重现,怎么办?
- 是否有一个全局视角来查看系统的运行状况? 有什么办法可以监控到容器和中间件的实时运行状态?
安装
arthas 3.0.5
https://github.com/alibaba/arthas/releases/download/arthas-all-3.0.5/arthas-3.0.5-bin.zip
the orginal startup command is not ok for me. So I write my own one.
step1:
extract arthas-3.0.5-bin.zip, and get those files
step2:
run_demo.bat ( for win)
set JAVA_HOME=C:/Progra~1/Java/jdk1.8.0_66
%JAVA_HOME%/bin/java -jar arthas-demo.jar
run.bat( for win)
set JAVA_HOME=C:/Progra~1/Java/jdk1.8.0_66
%JAVA_HOME%/bin/jps -m
set as_h=.
set as_pid=???
set as_ip=127.0.0.1
set as_telnet_port=13658
set as_http_port=18563
%JAVA_HOME%/bin/java -Dfile.encoding=UTF-8 -Xbootclasspath/a:%JAVA_HOME%\lib\tools.jar -jar arthas-core.jar -pid "%as_pid%" -target-ip %as_ip% -telnet-port %as_telnet_port% -http-port %as_http_port% -core arthas-core.jar -agent arthas-agent.ja
pause
??? is demo appliation PID, it comes from jps command. See red. it is 2248
if you want remote, please set as_ip as the pc ip, which run run.bat. Here I use 127.0.0, I just use it in local development pc.
run_demo.sh ( for linux)
? add later
run.sh ( for linux)
? add later
step3:
execute run_demo.bat to start a demo for test
execute run.bat to attach Arthas to demo PID
step4:
connect by telnet
I use putty
final
connect by web console
final
do test based on demo
sc
sc demo*
sc demo* // search class by name, for example it will be demo.MathGame
sc -d demo.MathGame // it will list all info of this class
sm
sm -d demo.MathGame // list all methods of this class
trace
trace demo.MathGame * // statck of method call, here it is *, means all methods
monitor
monitor demo.MathGame * // method calling statistic
it is slow, not show result immediately, wait a while
watch
watch demo.MathGame primeFactors '{params[0],returnObj}' // params[0] is the first input parameter of this method, returnObj means return value of this method.