Arthas(Java 线上问题定位处理的终极利器)

在使用 Arthas 之前,当遇到 Java 线上问题时,如 CPU 飙升、负载突高、内存溢出等问题,你需要查命令,查网络,然后 jps、jstack、jmap、jhat、jstat、hprof 等一通操作。最终焦头烂额,还不一定能查出问题所在。而现在,大多数的常见问题你都可以使用 Arthas 轻松定位,迅速解决,及时止损,准时下班。

1 Arthas介绍
Arthas 是 Alibaba 在 2018 年 9 月开源的 Java 诊断工具。支持 JDK6+, 采用命令行交互模式,提供 Tab 自动不全,可以方便的定位和诊断线上程序运行问题。
开源地址:https://github.com/alibaba/arthas

官方文档:https://alibaba.github.io/arthas

使用教程

其实跟着官方教程还挺好的


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命令可以帮助我们, 然后具体命令的时候也可以在 -h

此外还可以远程监听, 此外很多功能其实是修改字节码来完成的, 可以reset掉

你可能感兴趣的:(Arthas(Java 线上问题定位处理的终极利器))