撸起Arthas排雷

本文介绍了Arthas的安装及使用方法,通过演示案例详细展示了Arthas的强大功能,包括进程监控、线程分析、JVM信息查看等,是Java开发者必备的调试工具。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >


title: 撸起Arthas排雷
date: 2020-08-08 00:19:00
categories: JVM
description: Arthas

1. 目录

java_arthas_logo

2. 下载

Github中Arthas下载

3. 解压

下载出来是一个Zip压缩包,不多说,直接解压到目录下。

[root@centos8 data]$ unzip arthas-bin-3.3.7.zip -d arthas/
Archive:  arthas-bin-3.3.7.zip
   creating: arthas/async-profiler/
  inflating: arthas/arthas-spy.jar   
  inflating: arthas/arthas-core.jar  
  inflating: arthas/logback.xml      
  inflating: arthas/arthas.properties  
  inflating: arthas/arthas-agent.jar  
  inflating: arthas/arthas-client.jar  
  inflating: arthas/arthas-boot.jar  
  inflating: arthas/arthas-demo.jar  
  inflating: arthas/install-local.sh  
  inflating: arthas/as.sh            
  inflating: arthas/as.bat           
  inflating: arthas/as-service.bat   
  inflating: arthas/async-profiler/libasyncProfiler-linux-arm.so  
  inflating: arthas/async-profiler/libasyncProfiler-linux-x64.so  
  inflating: arthas/async-profiler/libasyncProfiler-mac-x64.so 

4. 使用简介

4.1. 启动演示Demo

原生Arthas 提供一个用于学习和演示用的 Demo,我们这里直接启动它,arthas-demo.jar,它是一个简单的程序,每隔一秒生成一个随机数,再执行质因数分解,并打印出分解结果。

[root@centos8 arthas]$ java -jar arthas-demo.jar
illegalArgumentCount:  1, number is: -121785, need >= 2
illegalArgumentCount:  2, number is: -71779, need >= 2
illegalArgumentCount:  3, number is: -108566, need >= 2
67261=67261
illegalArgumentCount:  4, number is: -22833, need >= 2
illegalArgumentCount:  5, number is: -24786, need >= 2
illegalArgumentCount:  6, number is: -101489, need >= 2
illegalArgumentCount:  7, number is: -95959, need >= 2
165377=59*2803

4.2. 启动Arthas

在启动中会让你输入需要监控的进程,演示环境中我这里只有 1,输入 1 回车。


[root@centos8 arthas]$ java -jar arthas-boot.jar
[INFO] arthas-boot version: 3.3.7
[INFO] Found existing java process, please choose one and input the serial number of the process, eg : 1. Then hit ENTER.
* [1]: 1714 arthas-demo.jar
1
[INFO] arthas home: /data/arthas
[INFO] Try to attach process 1714
[INFO] Attach process 1714 success.
[INFO] arthas-client connect 127.0.0.1 3658
  ,---.  ,------. ,--------.,--.  ,--.  ,---.   ,---.                           
 /  O  \ |  .--. ''--.  .--'|  '--'  | /  O  \ '   .-'                          
|  .-.  ||  '--'.'   |  |   |  .--.  ||  .-.  |`.  `-.                          
|  | |  ||  |\  \    |  |   |  |  |  ||  | |  |.-'    |                         
`--' `--'`--' '--'   `--'   `--'  `--'`--' `--'`-----'                          
                                                                                

wiki      https://alibaba.github.io/arthas                                      
tutorials https://alibaba.github.io/arthas/arthas-tutorials                     
version   3.3.7                                                                 
pid       1714                                                                  
time      2020-08-07 11:08:57                                                   

## 4.3. 常用命令集

经常用的命令我基本罗列出来,当然也不都是最好用,当然这里头既有实际情况和个人喜好在里面!

命令详解
dashboard展示当前进程的信息
thread线程栈信息,在实际应用比较有用,可以定位问题线程
jvm查看当前JVM信息,感觉有点类似 jinfo
sc查看JVM已加载的类信息
trace方法内部调用路径,并输出方法路径上的每个节点上耗时
monitor方法执行监控,是一个非实时返回命令.
vmoption查看和修改JVM里诊断相关的option

4.3.1. dashboard

前系统的实时数据面板,按 ctrl+c 退出。

当运行在Ali-tomcat时,会显示当前tomcat的实时信息,如HTTP请求的qps, rt, 错误数, 线程池信息等等。

dashboard仪表盘

4.3.1.1. 说明
  • ID: Java级别的线程ID,注意这个ID不能跟jstack中的nativeID一一对应

  • NAME: 线程名

  • GROUP: 线程组名

  • PRIORITY: 线程优先级, 1~10之间的数字,越大表示优先级越高

  • STATE: 线程的状态

  • CPU%: 线程消耗的cpu占比,采样100ms,将所有线程在这100ms内的cpu使用量求和,再算出每个线程的cpu使用占比。

  • TIME: 线程运行总时间,数据格式为分:秒

  • INTERRUPTED: 线程当前的中断位状态

  • DAEMON: 是否是daemon线程

4.3.1.2. 样例图

dashboard仪表盘

4.3.2. thread

查看当前线程信息,查看线程的堆栈。

参数名称参数说明
id线程id
[n:]指定最忙的前N个线程并打印堆栈
[b]找出当前阻塞其他线程的线程
[i ]指定cpu占比统计的采样间隔,单位为毫秒

thread-1

thread-2

4.3.3. JVM

查看当前JVM信息。

  • 和Thread有关的参数

    • COUNT: JVM当前活跃的线程数
    • DAEMON-COUNT: JVM当前活跃的守护线程数
    • PEAK-COUNT: 从JVM启动开始曾经活着的最大线程数
    • STARTED-COUNT: 从JVM启动开始总共启动过的线程次数
    • DEADLOCK-COUNT: JVM当前死锁的线程数
  • 文件描述符

此处省略

jvm

4.3.4. sc

查看JVM已加载的类信息

“Search-Class” 的简写,这个命令能搜索出所有已经加载到 JVM 中的 Class 信息,这个命令支持的参数有 [d]、[E]、[f] 和 [x:]。

参数名称参数说明
class-pattern类名表达式匹配
method-pattern方法名表达式匹配
[d]输出当前类的详细信息,包括这个类所加载的原始文件来源、类的声明、加载的ClassLoader等详细信息。
如果一个类被多个ClassLoader所加载,则会出现多次
[E]开启正则表达式匹配,默认为通配符匹配
[f]输出当前类的成员变量信息(需要配合参数-d一起使用)
[x:]指定输出静态变量时属性的遍历深度,默认为 0,即直接使用 toString 输出

sc

4.3.5. trace

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

参数名称参数说明
class-pattern类名表达式匹配
method-pattern方法名表达式匹配
condition-express条件表达式
[E]开启正则表达式匹配,默认为通配符匹配
[n:]命令执行次数
#cost方法执行耗时

trace

4.3.6. monitor

方法执行监控

对匹配 class-pattern/method-pattern的类、方法的调用进行监控。

参数名称参数说明
class-pattern类名表达式匹配
method-pattern方法名表达式匹配
[E]开启正则表达式匹配,默认为通配符匹配
[c:]统计周期,默认值为120秒

monitor

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

王老邪

你的鼓励将是我创作的最大动力

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

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

打赏作者

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

抵扣说明:

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

余额充值