赞
踩
在实际工作中很多的服务都使用docker部署,如果直接在服务器中使用Arthas则找不到运行的服务而无法使用Arthas进行诊断,因此需要进入到容器内部才能使用Arthas进入诊断。
curl -O https://arthas.aliyun.com/arthas-boot.jar
[root@localhost data-service-search]# curl -O https://arthas.aliyun.com/arthas-boot.jar
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 138k 100 138k 0 0 301k 0 --:--:-- --:--:-- --:--:-- 301k
# 复制arthas到容器内根目录下
docker cp arthas-boot.jar d78b2477186c:/arthas-boot.jar
#进入容器内部
docker exec -it d78b2477186c bash;
java -jar arthas-boot.jar
root@d78b2477186c:/# java -jar arthas-boot.jar [INFO] JAVA_HOME: /usr/lib/jvm/java-8-openjdk-amd64/jre [INFO] arthas-boot version: 3.6.7 [INFO] Found existing java process, please choose one and input the serial number of the process, eg : 1. Then hit ENTER. * [1]: 1 data-service-search.jar 1 [INFO] Start download arthas from remote server: https://arthas.aliyun.com/download/3.6.7?mirror=aliyun [INFO] File size: 12.92 MB, downloaded size: 8.95 MB, downloading ... [INFO] Download arthas success. [INFO] arthas home: /root/.arthas/lib/3.6.7/arthas [INFO] Try to attach process 1 Picked up JAVA_TOOL_OPTIONS: [INFO] Attach process 1 success. [INFO] arthas-client connect 127.0.0.1 3658 ,---. ,------. ,--------.,--. ,--. ,---. ,---. / O \ | .--. ''--. .--'| '--' | / O \ ' .-' | .-. || '--'.' | | | .--. || .-. |`. `-. | | | || |\ \ | | | | | || | | |.-' | `--' `--'`--' '--' `--' `--' `--'`--' `--'`-----' wiki https://arthas.aliyun.com/doc tutorials https://arthas.aliyun.com/doc/arthas-tutorials.html version 3.6.7 main_class pid 1 time 2022-12-04 10:29:31 [arthas@1]$
输入命令dashboard就可以看到,到这里就可以对服务进行诊断了,具体的arthas命令见官方文档或安装idea插件
Arthas 官方的工具还不够足够的简单,需要记住一些命令,特别是一些扩展性特别强的高级语法,比如ognl获取spring context 为所欲为,watch、trace 不够简单,需要构造一些命令工具的信息,因此只需要一个能够简单处理字符串信息的插件即可使用。当在处理线上问题的时候需要最快速、最便捷的命令,因此插件还是有存在的意义和价值的。
注意
请注意,这些命令,都通过字节码增强技术来实现的,会在指定类的方法中插入一些切面来实现数据统计和观测,因此在线上、预发使用时,请尽量明确需要观测的类、方法以及条件,诊断结束要执行 stop 或将增强过的类执行 reset 命令。
Arthas 支持使用管道对上述命令的结果进行进一步的处理,如 sm java.lang.String * | grep 'index'
当线上出现偶发的问题,比如需要 watch 某个条件,而这个条件一天可能才会出现一次时,异步后台任务就派上用场了,详情请参考这里
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。