?Alibaba開(kāi)源JAVA診斷工具Arthas
Arthas 是Alibaba開(kāi)源的Java診斷工具,深受開(kāi)發(fā)者喜愛(ài)。在線排查問(wèn)題,無(wú)需重啟;動(dòng)態(tài)跟蹤Java代碼;實(shí)時(shí)監(jiān)控JVM狀態(tài)。
當(dāng)你遇到以下類似問(wèn)題而束手無(wú)策時(shí),Arthas可以幫助你解決:
1)這個(gè)類從哪個(gè) jar 包加載的?為什么會(huì)報(bào)各種類相關(guān)的 Exception?
2)我改的代碼為什么沒(méi)有執(zhí)行到?難道是我沒(méi) commit?分支搞錯(cuò)了?
3)遇到問(wèn)題無(wú)法在線上 debug,難道只能通過(guò)加日志再重新發(fā)布嗎?
4)線上遇到某個(gè)用戶的數(shù)據(jù)處理有問(wèn)題,但線上同樣無(wú)法 debug,線下無(wú)法重現(xiàn)!
5)是否有一個(gè)全局視角來(lái)查看系統(tǒng)的運(yùn)行狀況?
6)有什么辦法可以監(jiān)控到JVM的實(shí)時(shí)運(yùn)行狀態(tài)?
7)怎么快速定位應(yīng)用的熱點(diǎn),生成火焰圖?
Arthas支持JDK 6+,支持linux/mac/Winodws,采用命令行交互模式,同時(shí)提供豐富的 Tab 自動(dòng)補(bǔ)全功能,進(jìn)一步方便進(jìn)行問(wèn)題的定位和診斷。
Github: https://github.com/alibaba/arthas
文檔: https://alibaba.github.io/arthas/
下面介紹arthas的安裝以及簡(jiǎn)單使用
1、下載arthas
在線方式快速安裝
curl -O https://alibaba.github.io/arthas/arthas-boot.jar
java -jar arthas-boot.jar
離線的方式
https://github.com/alibaba/arthas/releases/tag/arthas-all-3.3.6
下載arthas-bin.zip
rz上傳到服務(wù)器某個(gè)目錄,例如/homemkdir arthas
unzip arthas-bin.zip -d arthas
cd arthassh install-local.sh
2、啟動(dòng)arthas
1)用as.sh啟動(dòng)
./as.sh
2)用arthas-boot啟動(dòng)
java -jar arthas-boot.jar
選擇應(yīng)用java進(jìn)程
例如kafka進(jìn)程是第1個(gè),輸入1回車,Arthas會(huì)attach到目標(biāo)進(jìn)程上
3、help命令查看命令幫助
[arthas@10528]$ help
NAME DESCRIPTION
help Display Arthas Help
keymap Display all the available keymap for the specified connection.
sc Search all the classes loaded by JVM
sm Search the method of classes loaded by JVM
classloader Show classloader info
jad Decompile class
getstatic Show the static field of a class
monitor Monitor method execution statistics, e.g. total/success/failure count, average rt, fail rate, etc.
stack Display the stack trace for the specified class and method
thread Display thread info, thread stack
trace Trace the execution time of specified method invocation.
watch Display the input/output parameter, return object, and thrown exception of specified method invocation
tt Time Tunnel
jvm Display the target JVM information
perfcounter Display the perf counter infornation.
ognl Execute ognl expression.
mc Memory compiler, compiles java files into bytecode and class files in memory.
redefine Redefine classes. @see Instrumentation#redefineClasses(ClassDefinition...)
dashboard Overview of target jvm's thread, memory, gc, vm, Tomcat info.
dump Dump class byte array from JVM
heapdump Heap dump
options View and change various Arthas options
cls Clear the screen
reset Reset all the enhanced classes
version Display Arthas version
session Display current session information
sysprop Display, and change the system properties.
sysenv Display the system env.
vmoption Display, and update the vm diagnostic options.
logger Print logger info, and update the logger level
history Display command history
cat Concatenate and print files
echo write arguments to the standard output
pwd Return working directory name
mbean Display the mbean information
grep grep command for pipes.
tee tee command for pipes.
profiler Async Profiler. https://github.com/jvm-profiling-tools/async-profiler
stop Stop/Shutdown Arthas server and exit the console. [arthas@10528]$
4、jvm——查看當(dāng)前 JVM 的信息
5、thread——查看當(dāng)前 JVM 的線程堆棧信息
例如thread -n 3 查看占CPU資源最多的前3個(gè)線程
6、dashboard 當(dāng)前系統(tǒng)的實(shí)時(shí)數(shù)據(jù)面板
更多用法就不一一介紹,具體可以參考https://alibaba.github.io/arthas/官方文檔
7、一圖掌握Arthas—常用命令匯總
若圖片不清晰,請(qǐng)后臺(tái)聯(lián)系作者索要高清大圖
或者如下地址下載高清大圖
https://user-images.githubusercontent.com/31468811/71954111-3010be00-321f-11ea-9900-e88195c2a570.png






