add monitor command scenario. #847 (#1377)

pull/1406/head
Hollow Man 5 years ago committed by GitHub
parent c4c782e7e8
commit 6b5a8f0ec9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -1,6 +1,8 @@
monitor
=======
[`monitor` online tutorial](https://alibaba.github.io/arthas/arthas-tutorials?language=en&id=command-monitor)
> Monitor method invocation.
Monitor invocation for the method matched with `class-pattern` and `method-pattern`.

@ -1,6 +1,8 @@
monitor
=======
[`monitor`在线教程](https://alibaba.github.io/arthas/arthas-tutorials?language=cn&id=command-monitor)
> 方法执行监控
对匹配 `class-pattern``method-pattern`的类、方法的调用进行监控。

@ -0,0 +1,16 @@
在新的`Terminal 2`里,下载`arthas-boot.jar`,再用`java -jar`命令启动:
`wget https://alibaba.github.io/arthas/arthas-boot.jar
java -jar arthas-boot.jar`{{execute T2}}
`arthas-boot`是`Arthas`的启动程序它启动后会列出所有的Java进程用户可以选择需要诊断的目标进程。
选择第一个进程,输入 `1`{{execute T2}} ,再`Enter/回车`
Attach成功之后会打印Arthas LOGO。输入 `help`{{execute T2}} 可以获取到更多的帮助信息。
![Arthas Boot](/arthas/scenarios/common-resources/assets/arthas-boot.png)

@ -0,0 +1,10 @@
下载`arthas-demo.jar`,再用`java -jar`命令启动:
`wget https://alibaba.github.io/arthas/arthas-demo.jar
java -jar arthas-demo.jar`{{execute T1}}
`arthas-demo`是一个很简单的程序,它随机生成整数,再执行因式分解,把结果打印出来。如果生成的随机数是负数,则会打印提示信息。

@ -0,0 +1,12 @@
在“monitor”中我们演示了了Arthas的monitor命令。如果有更多的技巧或者使用疑问欢迎在Issue里提出。
* Issues: https://github.com/alibaba/arthas/issues
* 文档: https://alibaba.github.io/arthas
如果您在使用Arthas请让我们知道您的使用对我们非常重要[查看](https://github.com/alibaba/arthas/issues/111)
欢迎关注公众号获取Arthas项目的信息源码分析案例实践。
![Arthas公众号](/arthas/scenarios/common-resources/assets/qrcode_gongzhonghao.jpg)

@ -0,0 +1,35 @@
{
"title": "Arthas monitor命令",
"description": "Arthas monitor命令",
"difficulty": "精通者",
"time": "10-20 分钟",
"details": {
"steps": [
{
"title": "启动arthas demo",
"text": "arthas-demo.md"
},
{
"title": "启动arthas-boot",
"text": "arthas-boot.md"
},
{
"title": "monitor命令",
"text": "monitor.md"
}
],
"intro": {
"text": "intro.md"
},
"finish": {
"text": "finish.md"
}
},
"environment": {
"uilayout": "terminal"
},
"backend": {
"imageid": "java",
"environmentsprotocol": "http"
}
}

@ -0,0 +1,23 @@
![Arthas](https://alibaba.github.io/arthas/_images/arthas.png)
`Arthas` 是Alibaba开源的Java诊断工具深受开发者喜爱。在线排查问题无需重启动态跟踪Java代码实时监控JVM状态。
`Arthas` 支持JDK 6+支持Linux/Mac/Windows采用命令行交互模式同时提供丰富的 `Tab` 自动补全功能,进一步方便进行问题的定位和诊断。
当你遇到以下类似问题而束手无策时Arthas可以帮助你解决
- 这个类从哪个 jar 包加载的?为什么会报各种类相关的 Exception
- 我改的代码为什么没有执行到?难道是我没 commit分支搞错了
- 遇到问题无法在线上 debug难道只能通过加日志再重新发布吗
- 线上遇到某个用户的数据处理有问题,但线上同样无法 debug线下无法重现
- 是否有一个全局视角来查看系统的运行状况?
- 有什么办法可以监控到JVM的实时运行状态
- 怎么快速定位应用的热点,生成火焰图?
本教程会以一个简单的应用为例演示monitor命令。
* Github: https://github.com/alibaba/arthas
* 文档: https://alibaba.github.io/arthas/

@ -0,0 +1,67 @@
> 方法执行监控
对匹配 `class-pattern``method-pattern`的类、方法的调用进行监控。
`monitor` 命令是一个非实时返回命令.
实时返回命令是输入之后立即返回,而非实时返回的命令,则是不断的等待目标 Java 进程返回信息,直到用户输入 `Ctrl+C` 为止。
服务端是以任务的形式在后台跑任务植入的代码随着任务的中止而不会被执行所以任务关闭后不会对原有性能产生太大影响而且原则上任何Arthas命令不会引起原有业务逻辑的改变。
### 监控的维度说明
|监控项|说明|
|---:|:---|
|timestamp|时间戳|
|class|Java类|
|method|方法(构造方法、普通方法)|
|total|调用次数|
|success|成功次数|
|fail|失败次数|
|rt|平均RT|
|fail-rate|失败率|
### 参数说明
方法拥有一个命名参数 `[c:]`意思是统计周期cycle of output拥有一个整型的参数值
|参数名称|参数说明|
|---:|:---|
|*class-pattern*|类名表达式匹配|
|*method-pattern*|方法名表达式匹配|
|[E]|开启正则表达式匹配,默认为通配符匹配|
|`[c:]`|统计周期默认值为120秒|
### 使用参考
`monitor -c 5 demo.MathGame primeFactors`{{execute T2}}
```bash
$ monitor -c 5 demo.MathGame primeFactors
Press Ctrl+C to abort.
Affect(class-cnt:1 , method-cnt:1) cost in 94 ms.
timestamp class method total success fail avg-rt(ms) fail-rate
-----------------------------------------------------------------------------------------------
2018-12-03 19:06:38 demo.MathGame primeFactors 5 1 4 1.15 80.00%
timestamp class method total success fail avg-rt(ms) fail-rate
-----------------------------------------------------------------------------------------------
2018-12-03 19:06:43 demo.MathGame primeFactors 5 3 2 42.29 40.00%
timestamp class method total success fail avg-rt(ms) fail-rate
-----------------------------------------------------------------------------------------------
2018-12-03 19:06:48 demo.MathGame primeFactors 5 3 2 67.92 40.00%
timestamp class method total success fail avg-rt(ms) fail-rate
-----------------------------------------------------------------------------------------------
2018-12-03 19:06:53 demo.MathGame primeFactors 5 2 3 0.25 60.00%
timestamp class method total success fail avg-rt(ms) fail-rate
-----------------------------------------------------------------------------------------------
2018-12-03 19:06:58 demo.MathGame primeFactors 1 1 0 0.45 0.00%
timestamp class method total success fail avg-rt(ms) fail-rate
-----------------------------------------------------------------------------------------------
2018-12-03 19:07:03 demo.MathGame primeFactors 2 2 0 3182.72 0.00%
```

@ -0,0 +1,16 @@
In the new `Terminal 2`, download `arthas-boot.jar` and start with the `java -jar` command:
`wget https://alibaba.github.io/arthas/arthas-boot.jar
java -jar arthas-boot.jar`{{execute T2}}
`arthas-boot` is the launcher for `Arthas`. It lists all the Java processes, and the user can select the target process to be diagnosed.
Select the first process, type `1`{{execute T2}} then type `Enter`
After the Attach is successful, Arthas LOGO is printed. Enter `help`{{execute T2}} for more help.
![Arthas Boot](/arthas/scenarios/common-resources/assets/arthas-boot.png)

@ -0,0 +1,11 @@
Download `arthas-demo.jar` and start with the `java -jar` command:
`wget https://alibaba.github.io/arthas/arthas-demo.jar
java -jar arthas-demo.jar`{{execute T1}}
`arthas-demo` is a very simple program that randomly generates integers, performs factorization, and prints the results.
If the generated random number is negative, a error message will be printed.

@ -0,0 +1,8 @@
The `monitor Tutorial` demonstrates the usage of monitor. If you have more tips or questions, please feel free to ask in Issue.
* Issues: https://github.com/alibaba/arthas/issues
* Documentation: https://alibaba.github.io/arthas
If you are using Arthas, please let us know. Your use is very important to us: [View](https://github.com/alibaba/arthas/issues/111)

@ -0,0 +1,35 @@
{
"title": "Arthas monitor Command",
"description": "Arthas monitor Command",
"difficulty": "master",
"time": "10-20 minutes",
"details": {
"steps": [
{
"title": "Arthas demo",
"text": "arthas-demo.md"
},
{
"title": "Start arthas-boot",
"text": "arthas-boot.md"
},
{
"title": "monitor Command",
"text": "monitor.md"
}
],
"intro": {
"text": "intro.md"
},
"finish": {
"text": "finish.md"
}
},
"environment": {
"uilayout": "terminal"
},
"backend": {
"imageid": "java",
"environmentsprotocol": "http"
}
}

@ -0,0 +1,40 @@
![Arthas](https://alibaba.github.io/arthas/_images/arthas.png)
`Arthas` is a Java diagnostic tool open-sourced by Alibaba middleware team. Arthas helps developers in trouble-shooting issues in production environment for Java based applications without modifying code or restarting servers.
`Arthas` supports JDK 6+, supports Linux/Mac/Windows.
## Background
Oftentimes the production system network is inaccessible from local development environment. If issues are encountered in production systems, it is impossible to use IDE to debug the application remotely. Whats even worse, debugging in production environment is unacceptable, as it will suspend all the threads, leading to services downtime.
Developers could always try to reproduce the same issue on the test/staging environment. However, this is tricky as some issues cannot be reproduced easily in a different environment, or even disappear once restarted.
And if youre thinking of adding some logs to your code to help trouble-shoot the issue, you will have to go through the following lifecycle: test, staging, and then to production. Time is money! This approach is inefficient! Worse still, the issue may not be fixed since it might be irreproducible once the JVM is restarted, as described above.
Arthas is built to solve these issues. A developer can troubleshoot production issues on the fly. No JVM restart, no additional code changes. Arthas works as an observer, that is, it will never suspend your running threads.
## Key features
- Check whether a class is loaded? Or where the class is loaded from? (Useful for trouble-shooting jar file conflicts)
- Decompile a class to ensure the code is running as expected.
- Check classloader statistics, e.g. the number of classloaders, the number of classes loaded per classloader, the classloader hierarchy, possible classloader leaks, etc.
- Check the method invocation details, e.g. method parameter, returned values, exceptions and etc.
- Check the stack trace of specified method invocation. This is useful when a developer wants to know the caller of the method.
- Trace the method invocation to find slow sub-invocations.
- Monitor method invocation statistics, e.g. QPS (Query Per Second), RT (Return Time), success rate and etc.
- Monitor system metrics, thread states and CPU usage, GC statistics and etc.
- Supports command line interactive mode, with auto-complete feature enabled.
- Supports telnet and WebSocket, which enables both local and remote diagnostics with command line and browsers.
- Supports profiler/Flame Graph
- Supports JDK 6+
- Supports Linux/Mac/Windows
This tutorial takes a simple application as an example to demonstrate the the usage of monitor.
* Github: https://github.com/alibaba/arthas
* Docs: https://alibaba.github.io/arthas/

@ -0,0 +1,69 @@
monitor
=======
> Monitor method invocation.
Monitor invocation for the method matched with `class-pattern` and `method-pattern`.
`monitor` is not a command returning immediately.
A command returning immediately is a command immediately returns with the result after the command is input, while a non-immediate returning command will keep outputting the information from the target JVM process until user presses `Ctrl+C`.
On Arthas's server side, the command is running as a background job, but the weaved code will not take further effect once the job is terminated, therefore, it will not impact the performance after the job quits. Furthermore, Arthas is designed to have no side effect to the business logic.
### Items to monitor
|Item|Specification|
|---:|:---|
|timestamp|timestamp|
|class|Java class|
|method|method (constructor and regular methods)|
|total|calling times|
|success|success count|
|fail|failure count|
|rt|average RT|
|fail-rate|failure ratio|
### Parameters
Parameter `[c:]` stands for cycles of statistics. Its value is an integer value in seconds.
|Name|Specification|
|---:|:---|
|*class-pattern*|pattern for the class name|
|*method-pattern*|pattern for the method name|
|`[E]`|turn on regex matching while the default is wildcard matching|
|`[c:]`|cycle of statistics, the default value: `120`s|
### Usage
`monitor -c 5 demo.MathGame primeFactors`{{execute T2}}
```bash
$ monitor -c 5 demo.MathGame primeFactors
Press Ctrl+C to abort.
Affect(class-cnt:1 , method-cnt:1) cost in 94 ms.
timestamp class method total success fail avg-rt(ms) fail-rate
-----------------------------------------------------------------------------------------------
2018-12-03 19:06:38 demo.MathGame primeFactors 5 1 4 1.15 80.00%
timestamp class method total success fail avg-rt(ms) fail-rate
-----------------------------------------------------------------------------------------------
2018-12-03 19:06:43 demo.MathGame primeFactors 5 3 2 42.29 40.00%
timestamp class method total success fail avg-rt(ms) fail-rate
-----------------------------------------------------------------------------------------------
2018-12-03 19:06:48 demo.MathGame primeFactors 5 3 2 67.92 40.00%
timestamp class method total success fail avg-rt(ms) fail-rate
-----------------------------------------------------------------------------------------------
2018-12-03 19:06:53 demo.MathGame primeFactors 5 2 3 0.25 60.00%
timestamp class method total success fail avg-rt(ms) fail-rate
-----------------------------------------------------------------------------------------------
2018-12-03 19:06:58 demo.MathGame primeFactors 1 1 0 0.45 0.00%
timestamp class method total success fail avg-rt(ms) fail-rate
-----------------------------------------------------------------------------------------------
2018-12-03 19:07:03 demo.MathGame primeFactors 2 2 0 3182.72 0.00%
```
Loading…
Cancel
Save