初识阿里开源的本地Java进程监控调试工具arthas(阿尔萨斯)
转载自:https://www.cnblogs.com/linhui0705/p/9795417.html
上个月,阿里开源了一个名为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
2
3
|
[root@bogon arthas]# ./as.sh Arthas script version: 3.0.4illegal 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
2
3
|
export JAVA_HOME=/usr/java/jdk1.8.0_181export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar:$JAVA_HOME/jre/lib/rt.jarexport PATH=$PATH:$JAVA_HOME/bin |
:wq保存退出,再执行命令使配置的变量生效
|
1
|
source /etc/profile |
回到刚才的目录,启动arthas
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
[root@bogon ~]# cd /usr/local/arthas/[root@bogon arthas]# ./as.sh Arthas script version: 3.0.4Error: no available java process to attach.Usage: ./as.sh [-b [-f SCRIPT_FILE]] [debug] [--use-version VERSION] [--attach-only] <PID>[@IP:TELNET_PORT:HTTP_PORT] [debug] : start the agent in debug mode <PID> : the target Java Process ID [IP] : the target's IP [TELNET_PORT] : the target's PORT for telnet [HTTP_PORT] : the target's PORT for http [-b] : batch mode, which will disable interactive process selection. [-f] : specify the path to batch script file. [--attach-only] : only attach the arthas agent to target jvm. [--use-version] : use the specified arthas version to attach.Example: ./as.sh <PID> ./as.sh <PID>@[IP] ./as.sh <PID>@[IP:PORT] ./as.sh debug <PID> ./as.sh -b <PID> ./as.sh -b -f /path/to/script ./as.sh --attach-only <PID> ./as.sh --use-version 2.0.20161221142407 <PID>Here is the list of possible java process(es) to attatch: |
结果发现,无可用Java进程。那就启动一个咯(挖鼻屎),继续……
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
[root@bogon arthas]# ./as.sh Arthas script version: 3.0.4Found existing java process, please choose one and hit RETURN.* [1]: 1244 test.jarupdating version 3.0.4 ...######################################################################## 100.0%./as.sh: line 182: unzip: command not foundmv: cannot stat ‘/tmp/temp_3.0.4_1265’: No such file or directoryupdate fail, ignore this update.Calculating attach execution time...Attaching to 1244 using version 3.0.4...Error: Unable to access jarfile /root/.arthas/lib/3.0.4/arthas/arthas-core.jarattach 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
2
3
4
|
[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......[root@bogon 3.0.4]# unzip arthas-packaging-3.0.4-bin.zip -bash: unzip: command not found |
好吧,我装,我解压……
|
1
2
|
[root@bogon 3.0.4]# yum -y install unzip[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
2
3
|
[root@bogon 3.0.4]# mkdir arthas[root@bogon 3.0.4]# mv *.jar arthas/[root@bogon arthas]# ./as.sh |
大功告……你以为这样就结束了?还有问题呢……
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
Arthas script version: 3.0.4Found existing java process, please choose one and hit RETURN.* [1]: 1244 test.jarCalculating attach execution time...Attaching to 1244 using version 3.0.4...real 0m0.620suser 0m0.148ssys 0m0.043sAttach success.Connecting to arthas server... current timestamp is 1539615611./as.sh: line 423: type: telnet: not found'telnet' is required. |
还要装telnet-client……
|
1
|
[root@bogon 3.0.4]yum -y install telnet.x86_64 |
最后再启动,回车,大功告成!
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
[root@bogon arthas]# ./as.sh Arthas script version: 3.0.4Found existing java process, please choose one and hit RETURN.* [1]: 1244 test.jarCalculating attach execution time...Attaching to 1244 using version 3.0.4...real 0m0.132suser 0m0.050ssys 0m0.113sAttach success.Connecting to arthas server... current timestamp is 1539615853Trying 127.0.0.1...Connected to 127.0.0.1.Escape character is '^]'. ,---. ,------. ,--------.,--. ,--. ,---. ,---. / O \ | .--. ''--. .--'| '--' | / O \ ' .-' | .-. || '--'.' | | | .--. || .-. |`. `-. | | | || |\ \ | | | | | || | | |.-' | `--' `--'`--' '--' `--' `--' `--'`--' `--'`-----' wiki: https://alibaba.github.io/arthasversion: 3.0.4pid: 1244timestamp: 1539615854095$ |
接下来就可以各种命令各种姿势各种把弄了……
总结:
安装arthas前需要装JDK,配置好JAVA_HOME等环境变量,以及telnet。unzip看情况,如果你解压完再上传到服务器,也行……
不知道是bug还是神马情况,按照文档的步骤再一次装在测试的服务器上,程序正常运行,没有报Error: Unable to access jarfile /root/.arthas/lib/3.0.4/arthas/arthas-core.jar的错误,4个jar包都在预期的路径。简单来说,有的机器运行./as.sh是会因少jar包报错的,有的是会正常运行的,具体情况具体分析。后期继续关注arthas的GitHub动态,看项目的最新进展。
就酱。睡觉……
初识阿里开源的本地Java进程监控调试工具arthas(阿尔萨斯)的更多相关文章
- 轻量级监控平台之java进程监控脚本
轻量级监控平台之java进程监控脚本 #!/bin/bash #进程监控脚本 #功能需求: 上报机器Java进程的进程ID,对应的端口号service tcp端口号,tomcat http 端口号,以 ...
- JVisualVM监控本地Java进程
一.基于JVisualVM的可视化监控 1.打开C:\Program Files\Java\jdk1.8.0_131\bin下的jvisualvm.exe 2.打开后,会列出本机所有的Java进程 3 ...
- 初识阿里开源诊断工具Arthas
上个月,阿里开源了一个名为Arthas的监控工具.恰逢近期自己在写多线程处理业务,由此想到了一个问题. 如果在本机开发调试,IDE可以看到当前的活动线程,例如IntelliJ IDEA,线程是运行还是 ...
- Java进程监控
目录 1.引言 2. 程序启停, 为进程自定义项目名称 3. 操作系统判断 4. 获取进程信息 5. 内存,CPU信息 6. 堆内存信息 7. 端口信息 8. 线程信息 9. MXBean使用样例 9 ...
- 关于visualvm无法监控本地java进程
https://blog.csdn.net/weixin_43827693/article/details/105990675?spm=1001.2101.3001.6661.1&utm_me ...
- 阿里云ECS主机自定义进程监控
由于业务的关系我们用的是阿里云的ECS主机,需要对业务进程需要监控,查看后发现阿里云提供自定义监控SDK,这有助于我们定制化的根据自身业务来做监控,下面我就根据业务需求来介绍一个简单的自定义监控配置 ...
- 关于 Java 性能监控您不知道的 5 件事,第 1 部分
责怪糟糕的代码(或不良代码对象)并不能帮助您发现瓶颈,提高 Java? 应用程序速度,猜测也不能帮您解决.Ted Neward 引导您关注 Java 性能监控工具,从5 个技巧开始,使用Java 5 ...
- 利用jdk中工具完成Java程序监控方法记录
转载加自己整理的部分内容,转载自:http://jiajun.iteye.com/blog/810150 记录下JConsole使用方法 一.JConsole是什么 从Java 5开始 引入了 ...
- Arthas在线java进程诊断工具 在线调试神器
tag: java 诊断 堆栈 在线调试 耗时 死锁 arthas 阿里巴巴 Arthas (阿尔萨斯) Arthas 是 Alibaba 开源的Java诊断工具,深受开发者喜爱. 官网文档:http ...
随机推荐
- 细说Unicode(一) Unicode初认识
https://segmentfault.com/a/1190000007992346 细说Unicode(一) Unicode初认识 网站开发中经常会被乱码问题困扰.知道文件编码错误会导致乱码,但对 ...
- 笨方法学python3
阅读<笨方法学python3>,归纳的知识点 相关代码详见github地址:https://github.com/BMDACMER/Learn-Python 习题1:安装环境+练习 pr ...
- Linux安装pycharm并添加图标到桌面
安装: 1.到pycharm官网下载Linux版本的pycharm包. 2.打开中端 cd到下载的文件夹,默认为 ~/Downloads/ 文件夹下 3.执行命令 tar -xvzf pycharm- ...
- LeetCode 934. Shortest Bridge
原题链接在这里:https://leetcode.com/problems/shortest-bridge/ 题目: In a given 2D binary array A, there are t ...
- MongoDB 聚合函数
概念 聚合函数是对一组值执行计算并返回单一的值 主要的聚合函数 count distinct Group MapReduce 1.count db.users.count() db.users.cou ...
- ent 基本使用 一 schema 迁移
ent 是 facebook 开源的golang orm 框架,简单强大,以下是一个简单使用 环境准备 安装ent 工具 go get github.com/facebookincubator/ent ...
- C++后端工程师需要看的书籍
C++基础书籍<C++ primer><深度探索C++对象模型><Effective C++><more effective C++><STL源码 ...
- 04-树5 Root of AVL Tree (25 分)
An AVL tree is a self-balancing binary search tree. In an AVL tree, the heights of the two child sub ...
- javaScript 判断为false
JavaScript把null.undefined.0.NaN和空字符串''视为false,其他值一概视为true
- 拦截RestTemplate的请求
RestTemplate一般用于方法内部请求调用,请求报错时难以调试,所以可以为RestTemplate加拦截器进行调试,具体操作如下: 拦截器LoggingClientHttpRequestInte ...