Arthas的基础使用(二)

本文介绍了使用Arthas进行线上问题排查的各种命令,包括查看最忙线程、查找阻塞线程、监控JVM信息、反编译代码、跟踪方法调用路径、异常监控、性能慢查询诊断以及关键方法监控,帮助开发者快速定位和解决问题。
摘要由CSDN通过智能技术生成

使用场景介绍(常用总结)

1.展示当前最忙的前N个线程并打印堆栈

[arthas@106752]$ thread -n 3
"System Clock" Id=17 cpuUsage=2.02% deltaTime=4ms time=20590539ms TIMED_WAITING on java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject@28a1bb09
    at sun.misc.Unsafe.park(Native Method)
    -  waiting on java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject@28a1bb09
   ....
"arthas-command-execute" Id=142 cpuUsage=0.87% deltaTime=1ms time=10225ms RUNNABLE
    at sun.management.ThreadImpl.dumpThreads0(Native Method)
    at sun.management.ThreadImpl.getThreadInfo(ThreadImpl.java:448)
    at com.taobao.arthas.core.command.monitor200.ThreadCommand.processTopBusyThreads(ThreadCommand.java:199)
    ...

2.找出当前阻塞其他线程的线程(只支持synchronized)

有时候我们发现应用卡住了, 通常是由于某个线程拿住了某个锁, 并且其他线程都在等待这把锁造成的。
为了排查这类问题, arthas提供了thread -b, 一键找出那个罪魁祸首

	[arthas@106752]$ thread -b
	No most blocking thread found!

3.查看当前JVM信息

[arthas@106752]$ jvm
 THREAD                                                                                                                                                                                                                                          
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
 COUNT(JVM当前活跃的线程数)                                                                98                                                                                                                                                                         
 DAEMON-COUNT(JVM当前活跃的守护线程数)                                                         56                                                                                                                                                                         
 PEAK-COUNT(从JVM启动开始曾经活着的最大线程数)                                                           102                                                                                                                                                                        
 STARTED-COUNT(从JVM启动开始总共启动过的线程次数)                                                        135                                                                                                                                                                        
 DEADLOCK-COUNT(JVM当前死锁的线程数)                                                       0                                                                                                                                                                          
                                                                                                                                                                                                                                                 
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
 FILE-DESCRIPTOR                                                                                                                                                                                                                                 
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
 MAX-FILE-DESCRIPTOR-COUNT(JVM进程最大可以打开的文件描述符数)                                            65535                                                                                                                                                                      
 OPEN-FILE-DESCRIPTOR-COUNT(JVM当前打开的文件描述符数)    

4.线上反编译

[arthas@106752]$jad com.secusoft.xxxx.service.impl.xxxxxServiceImpl 

ClassLoader:                                                                                                                                                                                                                                     
+-org.springframework.boot.loader.LaunchedURLClassLoader@47f37ef1                                                                                                                                                                                
  +-sun.misc.Launcher$AppClassLoader@18b4aac2                                                                                                                                                                                                    
    +-sun.misc.Launcher$ExtClassLoader@445b84c0                                                                                                                                                                                                  

Location:                                                                                                                                                                                                                                        
file:/root/web/xxxx/xxxx-2.1.2-SNAPSHOT.jar!/BOOT-INF/classes!/                                                                                                                                                                  

        public String xxxxxx(String id, String type, int localPort) {
/*165*/     String url = "";
            xxxxDto xxxdto = this.xxxMapper.getById(id);
/*168*/     if (xxxdto != null) {
/*169*/         url = this.checkHlsUtis.convertPlayUrl(id, type);
            }
/*172*/     return url;
        }

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

[arthas@106752]$ stack com.secusoft.xxxx.service.impl.xxxxxServiceImpl xxxxxx

Press Q or Ctrl+C to abort.
Affect(class count: 3 , method count: 3) cost in 459 ms, listenerId: 23
ts=2021-03-27 14:24:57;thread_name=http-nio-8009-exec-1;id=3c;is_daemon=true;priority=5;TCCL=org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedWebappClassLoader@13658f29
    @com.secusoft.xxxx.service.impl.xxxxxServiceImpl.xxxxxx()
        at com.secusoft.xxxx.service.impl.xxxxxServiceImpl$$FastClassBySpringCGLIB$$9f40ac0c.invoke(<generated>:-1)
        at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204)
		....
ts=2021-03-27 14:24:57;thread_name=http-nio-8009-exec-1;id=3c;is_daemon=true;priority=5;TCCL=org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedWebappClassLoader@13658f29
    @com.secusoft.xxxx.service.impl.xxxxxServiceImpl$$EnhancerBySpringCGLIB$$bc4fd5c7.xxxxxx()
        at com.secusoft.xxxx.service.impl.xxxxxServiceImpl$$FastClassBySpring
        ....
        at com.secusoft.xxxx.service.impl.xxxxxServiceImpl$$EnhancerBySpringCGLIB$$ab6177ed.xxxxxx(<generated>:25)
        at com.secusoft.xxxx.controller.xxxController.getUrl(xxxController.java:413)
        at com.secusoft.xxxx.controller.xxxController$$FastClassBySpringCGLIB$$1eecdca2.invoke(<generated>:-1)
        at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204)

6.诊断线上方法执行异常 对入参结果监控

watch 监控起流核心方法 xxxxxx 

[arthas@19715]$ watch com.secusoft.xxxx.service.impl.xxxxxServiceImpl xxxxxx "{params,returnObj}" -x 2
Press Q or Ctrl+C to abort.
Affect(class count: 3 , method count: 1) cost in 413 ms, listenerId: 4
method=com.secusoft.xxxx.service.impl.xxxxxServiceImpl.xxxxxx location=AtExit
ts=2021-03-24 15:43:38; [cost=1042.500795ms] result=@ArrayList[
    @Object[][
        @xxxxVO[xxxxVO{appId='125412', id='34020000001320000127', type=''}],
    ],
    @String[55Camera 08],
]

7.诊断线上方法执行过慢诊断

trace 根据起流方法判断耗时
[arthas@19715]$ trace com.secusoft.xxxx.service.impl.xxxxxServiceImpl xxxxxx 
Press Q or Ctrl+C to abort.
Affect(class count: 3 , method count: 1) cost in 659 ms, listenerId: 5
`---ts=2021-03-24 15:47:04;thread_name=stream-control-%dpool-20-thread-10;id=86e;is_daemon=false;priority=5;TCCL=org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedWebappClassLoader@aaf1e32
    `---[1092.334566ms] com.secusoft.xxxx.service.impl.xxxxxServiceImpl:xxxxxx()
        +---[0.032045ms] com.secusoft.xxxx.model.vo.xxxxVO:getxxx() #378
        +---[0.04669ms] com.secusoft.xxxx.model.vo.xxxxVO:getxxx() #379
        +---[2.411973ms] com.secusoft.xxxx.mapper.CatalogMapper:selectOne() #382
        +---[0.83488ms] com.secusoft.xxxx.mapper.xxxMapper:getxxxByxxx() #385
        +---[0.021067ms] com.secusoft.xxxx.model.vo.xxxxVO:getTime() #387
        +---[0.014321ms] com.secusoft.xxxx.model.vo.xxxxVO:getType() #388
        +---[0.033491ms] com.secusoft.xxxx.model.vo.xxxxVO:getLocalPort() #389
        +---[0.020003ms] com.secusoft.xxxx.model.vo.xxxxVO:getxxx() #390
        +---[0.013023ms] com.secusoft.xxxx.model.vo.xxxxVO:getxxx() #392
		....

8.线上关键方法监控

monitor 监控方法执行
[arthas@19715]$ monitor -c 5 com.secusoft.xxxx.service.impl.xxxxxServiceImpl xxxxxx
Press Q or Ctrl+C to abort.
Affect(class count: 3 , method count: 1) cost in 409 ms, listenerId: 6
 timestamp            class                           method                         total      success   fail       avg-rt(m  fail-rate 
                                                                                                                     s)                  
-----------------------------------------------------------------------------------------------------------------------------------------
 2021-03-24 15:53:06  com.secusoft.xxxx.service.  xxxxxx                 1          1         0          2045.22   0.00%     
                      impl.xxxxxServiceImpl                                                                                             

 timestamp            class                           method                         total      success   fail       avg-rt(m  fail-rate 
                                                                                                                     s)                  
-----------------------------------------------------------------------------------------------------------------------------------------
 2021-03-24 15:53:11  com.secusoft.xxxx.service.  xxxxxx                 0          0         0          0.00      0.00%     
                      impl.xxxxxServiceImpl                                                                                             

 timestamp            class                           method                         total      success   fail       avg-rt(m  fail-rate 
                                                                                                                     s)                  
-----------------------------------------------------------------------------------------------------------------------------------------
 2021-03-24 15:53:16  com.secusoft.xxxx.service.  xxxxxx                 1          1         0          1021.23   0.00%     
                      impl.xxxxxServiceImpl                                                                                             

 timestamp            class                           method                         total      success   fail       avg-rt(m  fail-rate 
                                                                                                                     s)                  
-----------------------------------------------------------------------------------------------------------------------------------------
 2021-03-24 15:53:21  com.secusoft.xxxx.service.  xxxxxx                 0          0         0          0.00      0.00%     
                      impl.xxxxxServiceImpl      
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

一枚开发小咸鱼

原创不宜,请作者喝杯咖啡吧。

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值