在使用 Arthas 之前,當(dāng)遇到 Java 線上問題時(shí),如 CPU 飆升、負(fù)載突高、內(nèi)存溢出等問題,你需要查命令,查網(wǎng)絡(luò),然后 jps、jstack、jmap、jhat、jstat、hprof 等一通操作。最終焦頭爛額,還不一定能查出問題所在。而現(xiàn)在,大多數(shù)的常見問題你都可以使用 Arthas 輕松定位,迅速解決,及時(shí)止損,準(zhǔn)時(shí)下班。
1 Arthas介紹
Arthas 是 Alibaba 在 2018 年 9 月開源的 Java 診斷工具。支持 JDK6+, 采用命令行交互模式,提供 Tab 自動(dòng)不全,可以方便的定位和診斷線上程序運(yùn)行問題。
開源地址:https://github.com/alibaba/arthas
官方文檔:https://alibaba.github.io/arthas
使用教程
其實(shí)跟著官方教程還挺好的

image.png
[arthas@112]$ help
NAME DESCRIPTION
help Display Arthas Help
auth Authenticates the current session
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, fa
il 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 information.
ognl Execute ognl expression.
mc Memory compiler, compiles java files into bytecode and class files in memory.
redefine Redefine classes. @see Instrumentation#redefineClasses(ClassDefinition...)
retransform Retransform classes. @see Instrumentation#retransformClasses(Class...)
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
base64 Encode and decode using Base64 representation
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
vmtool jvm tool
stop Stop/Shutdown Arthas server and exit the console.
help命令可以幫助我們, 然后具體命令的時(shí)候也可以在 -h
此外還可以遠(yuǎn)程監(jiān)聽, 此外很多功能其實(shí)是修改字節(jié)碼來完成的, 可以reset掉