Arthas

准备

1
2
3
mkdir -p /opt/arthas
wget https://github.com/alibaba/arthas/releases/download/arthas-all-3.7.1/arthas-bin.zip
unzip arthas-bin.zip -d /opt/arthas

命令行启动 arthas

  • 查询要监控的 java 程序的 pid
1
2
3
# 命令根据实际情况调整
ps aux |grep admin |grep java
# 取得 pid:1383245
  • 执行启动命令
1
2
3
4
5
6
sudo -u tomcat /opt/jdk/jdk1.8.0_331/bin/java -Xbootclasspath/a:/opt/jdk/jdk1.8.0_331/lib/tools.jar \
 -jar /opt/arthas/arthas-core.jar \
 -pid 1383245 \
 -target-ip 127.0.0.1 -telnet-port 3658 -http-port 8563 \
 -core /opt/arthas/arthas-core.jar \
 -agent /opt/arthas/arthas-agent.jar
  • 查看 3658 端口是否已监听
1
2
3
$ sudo ss -anlp|grep 3658
# PID 也有之前获取的进程对应
tcp   LISTEN 0      100                                        [::ffff:127.0.0.1]:3658                   *:*         users:(("java",pid=1383245,fd=231))  

运行 arthas-client

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
$ sudo -u tomcat /opt/jdk/jdk1.8.0_331/bin/java -jar arthas-client.jar 127.0.0.1 3658
  ,---.  ,------. ,--------.,--.  ,--.  ,---.   ,---.
 /  O  \ |  .--. ''--.  .--'|  '--'  | /  O  \ '   .-'
|  .-.  ||  '--'.'   |  |   |  .--.  ||  .-.  |`.  `-.
|  | |  ||  |\  \    |  |   |  |  |  ||  | |  |.-'    |
`--' `--'`--' '--'   `--'   `--'  `--'`--' `--'`-----'

wiki       https://arthas.aliyun.com/doc
tutorials  https://arthas.aliyun.com/doc/arthas-tutorials.html
version    3.7.1
main_class
pid        1383245
time       2023-09-23 15:53:00

[arthas@1383245]$

抓取数据

  • 启动 profiler
1
2
[arthas@1383245]$ profiler start
Profiling started
  • 查看已采集的 sample 的数量
1
2
$ profiler getSamples
12
  • 查看 profiler 状态
1
2
[arthas@1383245]$ profiler status
Profiling is running for 59 seconds

停止并生成 html

1
2
3
[arthas@1383245]$ profiler stop --format html
OK
profiler output file: /usr/local/platform/tomcats/chengquan/admin/arthas-output/20230923-160236.html

参考