首页  

arthas使用     所属分类 arthas 浏览量 1827
arthas-3.1.4-bin.zip
https://github.com/alibaba/arthas/releases/download/arthas-all-3.1.4/arthas-3.1.4-bin.zip

install-local.sh

使用本地安装
远程安装需要远程下载

文档
https://arthas.aliyun.com/doc/


./as.sh pid

./as.sh 11593
Arthas script version: 3.1.4
[INFO] JAVA_HOME: /Library/Java/JavaVirtualMachines/jdk1.8.0_121.jdk/Contents/Home
[INFO] Process 11593 already using port 3658
[INFO] Process 11593 already using port 8563

./as.sh 5013
Error: unzip is not installed. Try to use java -jar arthas-boot.jar
 
没有 unzip 命令 使用 arthas-boot.jar 代替
java -jar arthas-boot.jar 5013



3658 telnet端口
8563 http端口

Thu Jan 02 13:18:18 CST 2020 com.taobao.arthas.agent.ArthasClassloader@4dda9611 JM.Log:INFO Log root path: /Users/dugang/logs/
Thu Jan 02 13:18:18 CST 2020 com.taobao.arthas.agent.ArthasClassloader@4dda9611 JM.Log:INFO Set arthas log path: /Users/dugang/logs/arthas


查看 Mbean 信息

列出所有 Mbean 的名称 mbean
查看 Mbean 的元信息 mbean -m java.lang:type=Threading
查看mbean属性信息  mbean java.lang:type=Threading 


通配符匹配特定的属性字段
mbean java.lang:type=Threading *Count

使用-E命令切换为正则匹配
mbean -E java.lang:type=Threading PeakThreadCount|ThreadCount|DaemonThreadCount

使用-i命令实时监控
mbean -i 1000 java.lang:type=Threading *Count


常用命令
getstatic 获取静态属性 (支持私有的静态属性)

getstatic class_name field_name

//  结合 ognl ,可更新数据
getstatic xxx.CacheInfo dataMap 'put("key","value")'



ognl调用静态方法  获取静态属性

ognl '@System@getProperties()'

@Properties[
    @String[java.runtime.name]:@String[Java(TM) SE Runtime Environment],
    @String[LOG_FILE_MAX_SIZE]:@String[500MB],
    @String[java.protocol.handler.pkgs]:@String[org.springframework.boot.loader],
    @String[sun.boot.library.path]:@String[/data01/admin/local/jdk8u191/jre/lib/amd64],
    @String[java.vm.version]:@String[25.191-b12],
    @String[java.vm.vendor]:@String[Oracle Corporation],
    @String[java.vendor.url]:@String[http://java.oracle.com/],
    @String[path.separator]:@String[:],
...
]

logger   
log信息  

 name                              ROOT                                                                                                                                                                     
 class                             ch.qos.logback.classic.Logger                                                                                                                                            
 classLoader                       org.springframework.boot.loader.LaunchedURLClassLoader@179d3b25                                                                                                          
 classLoaderHash                   179d3b25                                                                                                                                                                 
 level                             DEBUG                                                                                                                                                                    
 effectiveLevel                    DEBUG                                                                                                                                                                    
 additivity                        true                                                                                                                                                                     
 codeSource                        jar:file:/home/dyyx/myweb2.0.jar!/BOOT-INF/lib/logback-classic-1.2.3.jar!/                                                                        
 appenders                         name            CONSOLE                                                                                                                                                  
                                   class           ch.qos.logback.core.ConsoleAppender                                                                                                                      
                                   classLoader     org.springframework.boot.loader.LaunchedURLClassLoader@179d3b25                                                                                          
                                   classLoaderHash 179d3b25                                                                                                                                                 
                                   target          System.out   



dashboard
当前系统的实时数据面板
dashboard                                                                                                                        
dashboard -n 10                                                                                                                  
dashboard -i 2000   
   
-i, --interval     
-n, --number-of-execution  

thread
查看当前 JVM 的线程堆栈信息

thread 51                                                                                                                        
thread -n -1                                                                                                                     
thread -n 5                                                                                                                      
thread -b                                                                                                                        
thread -i 2000    
   

thread $threadid  输出指定线程的栈信息
-b, --include-blocking-thread    Find the thread who is holding a lock that blocks the most number of threads.          
-i, --sample-interval            
-n, --top-n-threads 
$id                                        Show thread stack  
 
-b  只适用于 synchronized 关键字


jvm
查看当前 JVM 的信息

sc
查看JVM已加载的类信息

Search all the classes loaded by JVM     


sc -d org.apache.commons.lang.StringUtils                                                                                        
sc -d org/apache/commons/lang/StringUtils                                                                                        
sc -d *StringUtils                                                                                                               
sc -d -f org.apache.commons.lang.StringUtils                                                                                     
sc -E org\\.apache\\.commons\\.lang\\.StringUtils                                                                                            


-d, --details     
-E, --regex    

sc  -d  dyyx.util.WebUtil


-d

输出当前类的详细信息,包括这个类所加载的原始文件来源、类的声明、加载的ClassLoader等详细信息。
如果一个类被多个ClassLoader所加载,则会出现多次





sm
查看已加载类的方法信息
Search-Method

Search the method of classes loaded by JVM                                                                                       




sm java.lang.String                                                                                                              
sm -d org.apache.commons.lang.StringUtils                                                                                        
sm -d org/apache/commons/lang/StringUtils                                                                                        
sm *StringUtils *                                                                                                                
sm -Ed org\\.apache\\.commons\\.lang\.StringUtils .*   

sm dyyx.util.WebUtil

只能看到由当前类所声明 (declaring) 的方法,无法看到父类的方法



jad
反编译指定已加载类的源码

jad java.lang.String                                                                                                             
jad java.lang.String toString                                                                                                    
jad --source-only java.lang.String                                                                                               
jad -c 39eb305e org/apache/log4j/Logger                                                                                          
jad -c 39eb305e -E org\\.apache\\.*\\.StringUtils                                                                                
        
-c The hash code of the special class's classLoader    
     

jad dyyx.util.WebUtil



classloader
查看classloader的继承树,urls,类加载信息,使用classloader去getResource

classloader dyyx.util.WebUtil

monitor
方法执行监控

monitor -c 6 dyyx.util.WebUtil run

monitor -c 6 dyyx.util.WebUtil run
Press Q or Ctrl+C to abort.
Affect(class-cnt:1 , method-cnt:1) cost in 148 ms.
 timestamp            class              method  total  success  fail  avg-rt(ms)  fail-rate                                        
---------------------------------------------------------------------------------------------                                       
 2020-01-02 13:57:10  dyyx.util.WebUtil  run     7      7        0     0.71        0.00%                                            

 timestamp            class              method  total  success  fail  avg-rt(ms)  fail-rate   


-c 统计周期,默认值为120秒




watch
方法执行数据观测

watch 命令定义了4个观察事件点,即 -b 方法调用前,-e 方法异常后,-s 方法返回后,-f 方法结束后
4个观察事件点 -b、-e、-s 默认关闭,-f 默认打开,当指定观察点被打开后,在相应事件点会对观察表达式进行求值并输出



watch  javax.servlet.http.HttpServletRequest  getParameter  "{params[0],returnObj}"

watch  javax.servlet.http.HttpServletRequest  getParameter  "{params[0],returnObj}"



ts=2020-01-02 14:06:17; [cost=0.508827ms] result=@ArrayList[
    @String[type],
    null,
]
ts=2020-01-02 14:06:17; [cost=0.078419ms] result=@ArrayList[
    @String[msg],
    @String[123456],
]
ts=2020-01-02 14:06:17; [cost=0.158106ms] result=@ArrayList[
    @String[type],
    null,
]
ts=2020-01-02 14:06:17; [cost=0.118755ms] result=@ArrayList[
    @String[type],
    null,
]



trace
方法内部调用路径,并输出方法路径上的每个节点上耗时

   trace org.apache.commons.lang.StringUtils isBlank                                                                                
   trace *StringUtils isBlank                                                                                                       
   trace *StringUtils isBlank params[0].length==1                                                                                   
   trace *StringUtils isBlank '#cost>100'                                                                                           
   trace -E org\\.apache\\.commons\\.lang\\.StringUtils isBlank                                                                     
   trace -E com.test.ClassA|org.test.ClassB method1|method2|method3     

-j, --jdkMethodSkip                         skip jdk method trace                                                                  
-n, --limits                                       Threshold of execution times    


trace dyyx.util.WebUtil run

Press Q or Ctrl+C to abort.
Affect(class-cnt:1 , method-cnt:1) cost in 48 ms.
`---ts=2020-01-02 14:07:49;thread_name=qtp835648992-307;id=133;is_daemon=false;priority=5;TCCL=org.eclipse.jetty.webapp.WebAppClassLoader@380fb434
    `---[1.167456ms] dyyx.util.WebUtil:run()
        +---[0.174207ms] dyyx.util.WebUtil:get() #283
        +---[0.039783ms] java.util.Set:contains() #288
        +---[0.044108ms] java.util.Map:put() #293
        +---[0.016305ms] java.lang.String:equals() #296
        `---[0.466114ms] dyyx.util.WebUtil:run_echo() #297





stack
输出当前方法被调用的调用路径

   stack org.apache.commons.lang.StringUtils isBlank                                                                                
   stack *StringUtils isBlank                                                                                                       
   stack *StringUtils isBlank params[0].length==1                                                                                   
   stack *StringUtils isBlank '#cost>100'                                                                                           
   stack -E org\.apache\.commons\.lang\.StringUtils isBlank  

据条件表达式来过滤
stack demo.MathGame primeFactors 'params[0]<0' -n 2
据执行时间来过滤
stack demo.MathGame primeFactors '#cost>5'

stack dyyx.util.WebUtil run


tt
方法执行数据的时空隧道,记录下指定方法每次调用的入参和返回信息,并能对这些不同的时间下调用进行观测

tt -t dyyx.util.WebUtil run

INDEX   TIMESTAMP            COST(ms)  IS-RET  IS-EXP  OBJECT          CLASS                         METHOD                        
------------------------------------------------------------------------------------------------------------------------------------
 1003    2020-01-02 17:26:25  0.683188  true    false   NULL            WebUtil                       run                           
 1004    2020-01-02 17:26:25  0.283673  true    false   NULL            WebUtil                       run                           
 1005    2020-01-02 17:26:26  0.154984  true    false   NULL            WebUtil                       run     

reset
重置增强类,将被 Arthas 增强过的类全部还原,Arthas 服务端关闭时会重置所有增强过的类

quit
退出当前 Arthas 客户端,其他 Arthas 客户端不受影响

shutdown
关闭 Arthas 服务端,所有 Arthas 客户端全部退出

上一篇     下一篇
kafka运维常用命令

程序员的誓言 

zookeeper使用场景

编程心法

arthas watch 使用

arthas tt 使用