## Arthas 是什么
`Arthas` 是 Alibaba 开源的 Java 诊断工具,深受开发者喜爱。[Arthas 官方文档](https://arthas.aliyun.com/doc/)
## 安装
### shell 版
执行以下命令:
```shell
curl -L https://arthas.aliyun.com/install.sh | sh
```
### jar 版(推荐)
```shell
curl -O https://arthas.aliyun.com/arthas-boot.jar
```
## 启动
执行以下命令启动 Arthas:
```shell
java -jar arthas-boot.jar
```
启动后会让我们选择连接哪个应用程序,输入1 或 2 再输入回车。
```shell
[root@localhost arthas]# java -jar arthas-boot.jar
[INFO] arthas-boot version: 3.5.0
[INFO] Found existing java process, please choose one and input the serial number of the process, eg : 1. Then hit ENTER.
* [1]: 32690 /root/zysite//springboot-test-1.0.0-SNAPSHOT.jar
[2]: 3306 org.apache.catalina.startup.Bootstrap
1 #此处选择并回车
[INFO] arthas home: /root/.arthas/lib/3.5.0/arthas
[INFO] Try to attach process 32690
[INFO] Attach process 32690 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.5.0
main_class
pid 32690
time 2021-04-29 09:40:23
[arthas@32690]$
```
之后就可以输入 Arthas 命令了。
最常用的是 观测方法的执行命令,可以很方便的查看方法运行情况:
```shell
watch com.zysite.springboot.test.HelloController hello '{params,returnObj,throwExp}' -n 5 -x 3 '1==1'
```
'{params,returnObj,throwExp}' 表示观测对象,这里选择了入参、出参和异常,-n 5 表示观测到5次后停止,-x 3 表示打印观测对象的时候只打印3层嵌套结构,'1==1' 为条件表达式,满足该条件的才会被观测到,这里相当于没有条件。
## 插件
Arthas 在 IDEA 上有一个插件:`arthas idea`,进入插件市场可以安装,之后可以直接在类或方法上右键,选择`Arthas Command`,再选择对应命令,可以自动成功 Arthas 命令,非常高效便捷。

实用工具Arthas的简单使用