?Alibaba開源JAVA診斷工具Arthas
Arthas 是Alibaba開源的Java診斷工具,深受開發(fā)者喜愛。在線排查問題,無需重啟;動態(tài)跟蹤Java代碼;實時監(jiān)控JVM狀態(tài)。
當(dāng)你遇到以下類似問題而束手無策時,Arthas可以幫助你解決:
1)這個類從哪個 jar 包加載的?為什么會報各種類相關(guān)的 Exception?
2)我改的代碼為什么沒有執(zhí)行到?難道是我沒 commit?分支搞錯了?
3)遇到問題無法在線上 debug,難道只能通過加日志再重新發(fā)布嗎?
4)線上遇到某個用戶的數(shù)據(jù)處理有問題,但線上同樣無法 debug,線下無法重現(xiàn)!
5)是否有一個全局視角來查看系統(tǒng)的運行狀況?
6)有什么辦法可以監(jiān)控到JVM的實時運行狀態(tài)?
7)怎么快速定位應(yīng)用的熱點,生成火焰圖?
Arthas支持JDK 6+,支持linux/mac/Winodws,采用命令行交互模式,同時提供豐富的 Tab 自動補全功能,進一步方便進行問題的定位和診斷。
Github: https://github.com/alibaba/arthas
文檔: https://alibaba.github.io/arthas/
下面介紹arthas的安裝以及簡單使用
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ù)器某個目錄,例如/homemkdir arthas
unzip arthas-bin.zip -d arthas
cd arthassh install-local.sh
2、啟動arthas
1)用as.sh啟動
./as.sh
2)用arthas-boot啟動
java -jar arthas-boot.jar
選擇應(yīng)用java進程
例如kafka進程是第1個,輸入1回車,Arthas會attach到目標(biāo)進程上
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個線程
6、dashboard 當(dāng)前系統(tǒng)的實時數(shù)據(jù)面板
更多用法就不一一介紹,具體可以參考https://alibaba.github.io/arthas/官方文檔
7、一圖掌握Arthas—常用命令匯總
若圖片不清晰,請后臺聯(lián)系作者索要高清大圖
或者如下地址下載高清大圖
https://user-images.githubusercontent.com/31468811/71954111-3010be00-321f-11ea-9900-e88195c2a570.png