上个月,阿里开源了一个名为Arthas的监控工具。恰逢近期自己在写多线程处理业务,由此想到了一个问题。

如果在本机开发调试,IDE可以看到当前的活动线程,例如IntelliJ IDEA,线程是运行还是休眠,在Debugger→Threads可以看到。倘若代码写完提交,到测试环境上构建,要怎样才能看到测试服务器上的线程运行情况呢?

前面客套完了,教程GitHub上面也有,这里主要讲下个人在部署的过程和踩到的坑。仅供参考。

GitHub: https://github.com/alibaba/arthas

Docs: https://alibaba.github.io/arthas/index.html

笔者用的是CentOS7裸机。看过教程,按照步骤执行命令:

  1. curl -L https://alibaba.github.io/arthas/install.sh | sh

下载了个名称为as.sh的脚本,执行脚本,发现:

  1. [root@bogon arthas]# ./as.sh 
  2. Arthas script version: 3.0.4
  3. illegal ENV, please set $JAVA_HOME to JDK6+

既然是Java监控,没有Java运行环境是不可能跑得起来的(这不是废话吗)。马上安装JDK配置环境变量……这里笔者装的是JDK8u181

JDK: https://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html

解压到/usr/java,执行vi /etc/profile配置环境变量

  1. export JAVA_HOME=/usr/java/jdk1.8.0_181
  2. export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar:$JAVA_HOME/jre/lib/rt.jar
  3. export PATH=$PATH:$JAVA_HOME/bin

:wq保存退出,再执行命令使配置的变量生效

  1. source /etc/profile

回到刚才的目录,启动arthas

  1. [root@bogon ~]# cd /usr/local/arthas/
  2. [root@bogon arthas]# ./as.sh 
  3. Arthas script version: 3.0.4
  4. Error: no available java process to attach.
  5.  
  6. Usage:
  7.     ./as.sh [-[-f SCRIPT_FILE]] [debug] [--use-version VERSION] [--attach-only] <PID>[@IP:TELNET_PORT:HTTP_PORT]
  8.     [debug]         : start the agent in debug mode
  9.     <PID>           : the target Java Process ID
  10.     [IP]            : the target's IP
  11.     [TELNET_PORT]   : the target's PORT for telnet
  12.     [HTTP_PORT]     : the target's PORT for http
  13.     [-b]            : batch mode, which will disable interactive process selection.
  14.     [-f]            : specify the path to batch script file.
  15.     [--attach-only] : only attach the arthas agent to target jvm.
  16.     [--use-version] : use the specified arthas version to attach.
  17.  
  18. Example:
  19.     ./as.sh <PID>
  20.     ./as.sh <PID>@[IP]
  21.     ./as.sh <PID>@[IP:PORT]
  22.     ./as.sh debug <PID>
  23.     ./as.sh -b <PID>
  24.     ./as.sh -b -f /path/to/script
  25.     ./as.sh --attach-only <PID>
  26.     ./as.sh --use-version 2.0.20161221142407 <PID>
  27.  
  28. Here is the list of possible java process(es) to attatch:

结果发现,无可用Java进程。那就启动一个咯(挖鼻屎),继续……

  1. [root@bogon arthas]# ./as.sh 
  2. Arthas script version: 3.0.4
  3. Found existing java process, please choose one and hit RETURN.
  4. * [1]: 1244 test.jar
  5.  
  6. updating version 3.0.4 ...
  7. ######################################################################## 100.0%
  8. ./as.sh: line 182: unzip: command not found
  9. mv: cannot stat ‘/tmp/temp_3.0.4_1265’: No such file or directory
  10. update fail, ignore this update.
  11. Calculating attach execution time...
  12. Attaching to 1244 using version 3.0.4...
  13. Error: Unable to access jarfile /root/.arthas/lib/3.0.4/arthas/arthas-core.jar
  14. attach to target jvm (1244) failed, check /root/logs/arthas/arthas.log or stderr of target jvm for any exceptions.

然而,程序没有如期运行成功。

……

通过度娘Google各种途径,看了FAQ,作者建议是手动安装+手动拼接命令行启动。但是,有些麻烦,不喜欢(任性)

后面,看到了这个Issue: Error: Unable to access jarfile /root/.arthas/lib/3.0.4/arthas/arthas-core.jar。咦这不就是我共患难的兄弟吗?马上点进去。看到大神ralf0131的回答,顿时茅厕塞顿开:

  1. First, please ensure /root/.arthas/lib/3.0.4/arthas/arthas-core.jar does exist.

cd到/root/.arthas/lib/3.0.4,发现目录下没有jar包。尝不到这瓜有点不甘心,只好手动安装了(真香~)

当前最新的包是3.0.4。下载,解压:

  1. [root@bogon 3.0.4]# wget https://maven.aliyun.com/repository/public/com/taobao/arthas/arthas-packaging/3.0.4/arthas-packaging-3.0.4-bin.zip
  2. ......
  3. [root@bogon 3.0.4]# unzip arthas-packaging-3.0.4-bin.zip 
  4. -bash: unzip: command not found

好吧,我装,我解压……

  1. [root@bogon 3.0.4]# yum -y install unzip
  2. [root@bogon 3.0.4]# unzip arthas-packaging-3.0.4-bin.zip

顿时发现,刚才不是说/root/.arthas/lib/3.0.4/arthas路径下木有jar包吗,刚刚我把jar包解压到/root/.arthas/lib/3.0.4,只要再新建个arthas目录,再把4个jar包移进去就OK了。

  1. [root@bogon 3.0.4]# mkdir arthas
  2. [root@bogon 3.0.4]# mv *.jar arthas/
  3. [root@bogon arthas]# ./as.sh

大功告……你以为这样就结束了?还有问题呢……

  1. Arthas script version: 3.0.4
  2. Found existing java process, please choose one and hit RETURN.
  3. * [1]: 1244 test.jar
  4.  
  5. Calculating attach execution time...
  6. Attaching to 1244 using version 3.0.4...
  7.  
  8. real 0m0.620s
  9. user 0m0.148s
  10. sys 0m0.043s
  11. Attach success.
  12. Connecting to arthas server... current timestamp is 1539615611
  13. ./as.sh: line 423: type: telnet: not found
  14. 'telnet' is required.

还要装telnet-client……

  1. [root@bogon 3.0.4]yum -y install telnet.x86_64

最后再启动,回车,大功告成!

  1. [root@bogon arthas]# ./as.sh 
  2. Arthas script version: 3.0.4
  3. Found existing java process, please choose one and hit RETURN.
  4. * [1]: 1244 test.jar
  5.  
  6. Calculating attach execution time...
  7. Attaching to 1244 using version 3.0.4...
  8.  
  9. real 0m0.132s
  10. user 0m0.050s
  11. sys 0m0.113s
  12. Attach success.
  13. Connecting to arthas server... current timestamp is 1539615853
  14. Trying 127.0.0.1...
  15. Connected to 127.0.0.1.
  16. Escape character is '^]'.
  17.   ,---.  ,------. ,--------.,--.  ,--.  ,---.   ,---.                           
  18.  /  O  \ |  .--. ''--.  .--'|  '--'  | /  O  \ '   .-'                          
  19. |  .-.  ||  '--'.'   |  |   |  .--.  ||  .-.  |`.  `-.                          
  20. |  | |  ||  |\  \    |  |   |  |  |  ||  | |  |.-'    |                         
  21. `--' `--'`--' '--'   `--'   `--'  `--'`--' `--'`-----'  
  22.  
  23. wiki: https://alibaba.github.io/arthas
  24. version: 3.0.4
  25. pid: 1244
  26. timestamp: 1539615854095
  27.  
  28. $

接下来就可以各种命令各种姿势各种把弄了……

总结:

  1. 安装arthas前需要装JDK,配置好JAVA_HOME等环境变量,以及telnet。unzip看情况,如果你解压完再上传到服务器,也行……

  2. 不知道是bug还是神马情况,按照文档的步骤再一次装在测试的服务器上,程序正常运行,没有报Error: Unable to access jarfile /root/.arthas/lib/3.0.4/arthas/arthas-core.jar的错误,4个jar包都在预期的路径。简单来说,有的机器运行./as.sh是会因少jar包报错的,有的是会正常运行的,具体情况具体分析。后期继续关注arthas的GitHub动态,看项目的最新进展。

就酱。睡觉……

初识阿里开源诊断工具Arthas的更多相关文章

  1. 【Java】15分钟快速体验阿里Java诊断工具Arthas

    [墙裂推荐]15分钟快速体验阿里Java诊断工具Arthas : https://alibaba.github.io/arthas/arthas-tutorials?language=cn&i ...

  2. 阿里JAVA诊断工具Arthas的初步使用

    Arthas 是Alibaba开源的Java诊断工具,主要解决以下问题: 这个类从哪个 jar 包加载的?为什么会报各种类相关的 Exception? 我改的代码为什么没有执行到?难道是我没 comm ...

  3. Java开源诊断工具 Arthas 发布v3.1.0

    Arthas 自2018年9月份上线以来「传送门」,已收获近万个star,感谢开发者们的认可.此次Arthas 3.1.0版本的发布,不仅带来大家投票出来的新LOGO,还带来强大的新功能和更好的易用性 ...

  4. 开源在线分析诊断工具Arthas(阿尔萨斯)--总结

    阿里重磅开源在线分析诊断工具Arthas(阿尔萨斯) arthas用法 启动demo java -jar arthas-demo.jar 启动 java -jar arthas-boot.jar at ...

  5. Java诊断工具Arthas

    Java诊断工具Arthas 1. Arthas简介 Arthas是阿里开源的一个线上java诊断工具,发现阿里还是挺喜欢开源一些技术的,造福人类.昨天试用了一下,发现真是强大,解决了我工作两年的很多 ...

  6. java 诊断工具——Arthas

    该说不说!小编做的这些功能,最讨厌的就是优化!某些前辈大佬写的代码小辈我实在不敢恭维!那逻辑!那sql! 接下来!今天的主角就登场了,阿里巴巴最近开源出来的一个针对 java 的工具,主要是针对 ja ...

  7. Alibaba Java诊断工具Arthas之快速安装和简单使用

    Alibaba Java诊断工具Arthas简单介绍 : 当你遇到以下类似问题而束手无策时,Arthas可以帮助你解决: 1.这个类从哪个 jar 包加载的?为什么会报各种类相关的 Exception ...

  8. 阿里重磅开源在线分析诊断工具Arthas(阿尔萨斯)

    github地址: Arthas English version goes here. Arthas 是Alibaba开源的Java诊断工具,深受开发者喜爱. 当你遇到以下类似问题而束手无策时,Art ...

  9. 款阿里开源的 Java 诊断工具Arthas

    Arthas是什么鬼? Arthas是一款阿里巴巴开源的 Java 线上诊断工具,功能非常强大,可以解决很多线上不方便解决的问题. Arthas诊断使用的是命令行交互模式,支持JDK6+,Linux. ...

随机推荐

  1. sublime text3最新版本注册码(build 3143)

    —– BEGIN LICENSE —– TwitterInc 200 User License EA7E-890007 1D77F72E 390CDD93 4DCBA022 FAF60790 61AA ...

  2. gridview发布后,编辑改为edit 原因是未安装 dotNetFx40LP_Full_x86_x64zh-Hans中文语言包

    https://www.microsoft.com/zh-cn/download/details.aspx?id=3324

  3. 群里一个高手写的url?传参执行php函数的小程序, 收藏下

    <?php // +---------------------------------------------------------------------- // | Copyright ( ...

  4. open()打开文件失败对应的各种错误码

    open()打开文件失败错误码: 获取错误信息实例: HANDLE hFile = ; hFile = open(“c:\test.txt”, O_RDWR, S_IRWXU|S_IRWXG|S_IR ...

  5. tomcat加固

    tomcat安全加固和规范 tomcat是一个开源Web服务器,基于Tomcat的Web运行效率高,可以在一般的硬件平台上流畅运行,因此,颇受Web站长的青睐.不过,在默认配置下其存在一定的安全隐患, ...

  6. codeforces:Michael and Charging Stations分析和实现

    题目大意 迈克尔接下来n天里分别需要支付C[1], C[2], ... , C[n]费用,但是每次支付费用可以选择使用优惠或不使用优惠,每次使用价值X的优惠那么迈克尔所能使用的优惠余量将减少X并且当天 ...

  7. 【bzoj1087】互不侵犯King 状态压缩dp

    AC通道:http://www.lydsy.com/JudgeOnline/problem.php?id=1087 [题解] 用f[i][j][k]表示前i行放了j个棋子且第i行的状态为k的方案数. ...

  8. oracle 知识点

    1.条件运算2.关联运算,子查询3.集合运算4.函数运算5.分组运算[group by](凑维度,条件,过滤,分组函数)6.行转列7.PL/SQL

  9. 完全使用ASP.NET实现的省市区级联效果

    本功能特点:下级的显示和数据的加载都是由上一级下拉框的SelectedIndexChanged触发的,在上级下拉框没有选择之前,下级不会出现,用户体验比较好.无刷新方面,采用AJAX技术,在数据选择的 ...

  10. FTP上传下载--python

    import socket import struct import json import subprocess import os class MYTCPServer: address_famil ...