mirror of
https://github.com/alibaba/arthas.git
synced 2026-10-21 05:51:38 +00:00
@@ -1,6 +1,8 @@
|
||||
options
|
||||
===
|
||||
|
||||
[`options` online tutorial](https://alibaba.github.io/arthas/arthas-tutorials?language=en&id=command-options)
|
||||
|
||||
> Global options
|
||||
|
||||
|Name| Default Value | Description |
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
options
|
||||
===
|
||||
|
||||
[`options`在线教程](https://alibaba.github.io/arthas/arthas-tutorials?language=cn&id=command-options)
|
||||
|
||||
> 全局开关
|
||||
|
||||
| 名称 | 默认值 | 描述 |
|
||||
|
||||
@@ -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}} 可以获取到更多的帮助信息。
|
||||
|
||||

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

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

|
||||
|
||||
`Arthas` 是Alibaba开源的Java诊断工具,深受开发者喜爱。在线排查问题,无需重启;动态跟踪Java代码;实时监控JVM状态。
|
||||
|
||||
`Arthas` 支持JDK 6+,支持Linux/Mac/Windows,采用命令行交互模式,同时提供丰富的 `Tab` 自动补全功能,进一步方便进行问题的定位和诊断。
|
||||
|
||||
当你遇到以下类似问题而束手无策时,Arthas可以帮助你解决:
|
||||
|
||||
- 这个类从哪个 jar 包加载的?为什么会报各种类相关的 Exception?
|
||||
- 我改的代码为什么没有执行到?难道是我没 commit?分支搞错了?
|
||||
- 遇到问题无法在线上 debug,难道只能通过加日志再重新发布吗?
|
||||
- 线上遇到某个用户的数据处理有问题,但线上同样无法 debug,线下无法重现!
|
||||
- 是否有一个全局视角来查看系统的运行状况?
|
||||
- 有什么办法可以监控到JVM的实时运行状态?
|
||||
- 怎么快速定位应用的热点,生成火焰图?
|
||||
|
||||
本教程会以一个简单的应用为例,演示options命令。
|
||||
|
||||
* Github: https://github.com/alibaba/arthas
|
||||
* 文档: https://alibaba.github.io/arthas/
|
||||
@@ -0,0 +1,96 @@
|
||||
|
||||
> 全局开关
|
||||
|
||||
| 名称 | 默认值 | 描述 |
|
||||
| ------------------ | ----- | ---------------------------------------- |
|
||||
| unsafe | false | 是否支持对系统级别的类进行增强,打开该开关可能导致把JVM搞挂,请慎重选择! |
|
||||
| dump | false | 是否支持被增强了的类dump到外部文件中,如果打开开关,class文件会被dump到`/${application working dir}/arthas-class-dump/`目录下,具体位置详见控制台输出 |
|
||||
| batch-re-transform | true | 是否支持批量对匹配到的类执行retransform操作 |
|
||||
| json-format | false | 是否支持json化的输出 |
|
||||
| disable-sub-class | false | 是否禁用子类匹配,默认在匹配目标类的时候会默认匹配到其子类,如果想精确匹配,可以关闭此开关 |
|
||||
| support-default-method | true | 是否支持匹配到default method,默认会查找interface,匹配里面的default method。参考 [#1105](https://github.com/alibaba/arthas/issues/1105) |
|
||||
| save-result | false | 是否打开执行结果存日志功能,打开之后所有命令的运行结果都将保存到`~/logs/arthas-cache/result.log`中 |
|
||||
| job-timeout | 1d | 异步后台任务的默认超时时间,超过这个时间,任务自动停止;比如设置 1d, 2h, 3m, 25s,分别代表天、小时、分、秒 |
|
||||
| print-parent-fields | true | 是否打印在parent class里的filed |
|
||||
|
||||
### 查看所有的options
|
||||
|
||||
`options`{{execute T2}}
|
||||
|
||||
```bash
|
||||
$ options
|
||||
LEVEL TYPE NAME VALUE SUMMARY DESCRIPTION
|
||||
--------------------------------------------------------------------------------------------
|
||||
0 bool unsafe false Option to support This option enables to proxy function
|
||||
ean system-level class ality of JVM classes. Due to serious
|
||||
security risk a JVM crash is possibly
|
||||
be introduced. Do not activate it un
|
||||
less you are able to manage.
|
||||
1 bool dump false Option to dump the This option enables the enhanced clas
|
||||
ean enhanced classes ses to be dumped to external file for
|
||||
further de-compilation and analysis.
|
||||
1 bool batch-re-tr true Option to support This options enables to reTransform c
|
||||
ean ansform batch reTransform lasses with batch mode.
|
||||
Class
|
||||
2 bool json-format false Option to support This option enables to format object
|
||||
ean JSON format of obj output with JSON when -x option selec
|
||||
ect output ted.
|
||||
1 bool disable-sub false Option to control This option disable to include sub cl
|
||||
ean -class include sub class ass when matching class.
|
||||
when class matchin
|
||||
g
|
||||
1 bool save-result false Option to print co This option enables to save each comm
|
||||
ean mmand's result to and's result to log file, which path
|
||||
log file is ${user.home}/logs/arthas-cache/res
|
||||
ult.log.
|
||||
2 Stri job-timeout 1d Option to job time This option setting job timeout,The u
|
||||
ng out nit can be d, h, m, s for day, hour,
|
||||
minute, second. 1d is one day in defa
|
||||
ult
|
||||
1 bool print-paren true Option to print al This option enables print files in pa
|
||||
ean t-fields l fileds in parent rent class, default value true.
|
||||
class
|
||||
```
|
||||
|
||||
|
||||
### 获取option的值
|
||||
|
||||
`options json-format`{{execute T2}}
|
||||
|
||||
```
|
||||
$ options json-format
|
||||
LEVEL TYPE NAME VALUE SUMMARY DESCRIPTION
|
||||
--------------------------------------------------------------------------------------------
|
||||
2 bool json-format false Option to support This option enables to format object
|
||||
ean JSON format of obj output with JSON when -x option selec
|
||||
ect output ted.
|
||||
```
|
||||
|
||||
> 默认情况下`json-format`为false,如果希望`watch`/`tt`等命令结果以json格式输出,则可以设置`json-format`为true。
|
||||
|
||||
### 设置指定的option
|
||||
|
||||
例如,想打开执行结果存日志功能首先查看日志,发现无记录:
|
||||
|
||||
`cat /root/logs/arthas-cache/result.log`{{execute T2}}
|
||||
|
||||
输入如下命令即可激活记录日志功能:
|
||||
|
||||
`options save-result true`{{execute T2}}
|
||||
|
||||
```
|
||||
$ options save-result true
|
||||
NAME BEFORE-VALUE AFTER-VALUE
|
||||
----------------------------------------
|
||||
save-result false true
|
||||
```
|
||||
|
||||
稍候片刻,再次查看,发现出现记录:
|
||||
|
||||
`cat /root/logs/arthas-cache/result.log`{{execute T2}}
|
||||
|
||||
```bash
|
||||
$ cat /root/logs/arthas-cache/result.log
|
||||
2020-07-26 04:27:08 [arthas-command-execute] INFO result -
|
||||
2020-07-26 04:27:08 [arthas-command-execute] INFO result -
|
||||
```
|
||||
@@ -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.
|
||||
|
||||

|
||||
@@ -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 `options Tutorial` demonstrates the usage of options. 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 options Command",
|
||||
"description": "Arthas options 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": "options Command",
|
||||
"text": "options.md"
|
||||
}
|
||||
],
|
||||
"intro": {
|
||||
"text": "intro.md"
|
||||
},
|
||||
"finish": {
|
||||
"text": "finish.md"
|
||||
}
|
||||
},
|
||||
"environment": {
|
||||
"uilayout": "terminal"
|
||||
},
|
||||
"backend": {
|
||||
"imageid": "java",
|
||||
"environmentsprotocol": "http"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
|
||||
|
||||
|
||||

|
||||
|
||||
`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. What’s 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 you’re 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 options.
|
||||
|
||||
* Github: https://github.com/alibaba/arthas
|
||||
* Docs: https://alibaba.github.io/arthas/
|
||||
|
||||
@@ -0,0 +1,101 @@
|
||||
|
||||
> Global options
|
||||
|
||||
|Name| Default Value | Description |
|
||||
| ------------------------- | ----- | ---------------------------------------- |
|
||||
| unsafe | false | whether to enhance to system-level class. Use it with caution since JVM may hang|
|
||||
| dump | false | whether to dump enhanced class to the external files. If it's on, enhanced class will be dumped into `/${application dir}/arthas-class-dump/`, the specific output path will be output in the console |
|
||||
| batch-re-transform | true | whether to re-transform matched classes in batch|
|
||||
| json-format | false | whether to output in JSON format|
|
||||
| disable-sub-class | false | whether to enable matching child classes. The default value is `true`. If exact match is desire, turn off this flag|
|
||||
| support-default-method | true | whether to enable matching default method in interface. The default value is `true`. Refer to [#1105](https://github.com/alibaba/arthas/issues/1105) |
|
||||
| save-result | false | whether to save execution result. All execution results will be saved to `~/logs/arthas-cache/result.log` when it's turned on|
|
||||
| job-timeout | 1d | default timeout for background jobs. Background job will be terminated once it's timed out (i.e. 1d, 2h, 3m, 25s)| print-parent-fields | true | This option enables print files in parent class, default value true.|
|
||||
|
||||
|
||||
|
||||
### View all options
|
||||
|
||||
`options`{{execute T2}}
|
||||
|
||||
```bash
|
||||
$ options
|
||||
LEVEL TYPE NAME VALUE SUMMARY DESCRIPTION
|
||||
--------------------------------------------------------------------------------------------
|
||||
0 bool unsafe false Option to support This option enables to proxy function
|
||||
ean system-level class ality of JVM classes. Due to serious
|
||||
security risk a JVM crash is possibly
|
||||
be introduced. Do not activate it un
|
||||
less you are able to manage.
|
||||
1 bool dump false Option to dump the This option enables the enhanced clas
|
||||
ean enhanced classes ses to be dumped to external file for
|
||||
further de-compilation and analysis.
|
||||
1 bool batch-re-tr true Option to support This options enables to reTransform c
|
||||
ean ansform batch reTransform lasses with batch mode.
|
||||
Class
|
||||
2 bool json-format false Option to support This option enables to format object
|
||||
ean JSON format of obj output with JSON when -x option selec
|
||||
ect output ted.
|
||||
1 bool disable-sub false Option to control This option disable to include sub cl
|
||||
ean -class include sub class ass when matching class.
|
||||
when class matchin
|
||||
g
|
||||
1 bool debug-for-a false Option to print DE This option enables to print DEBUG me
|
||||
ean sm BUG message if ASM ssage of ASM for each method invocati
|
||||
is involved on.
|
||||
1 bool save-result false Option to print co This option enables to save each comm
|
||||
ean mmand's result to and's result to log file, which path
|
||||
log file is ${user.home}/logs/arthas-cache/res
|
||||
ult.log.
|
||||
2 Stri job-timeout 1d Option to job time This option setting job timeout,The u
|
||||
ng out nit can be d, h, m, s for day, hour,
|
||||
minute, second. 1d is one day in defa
|
||||
ult
|
||||
1 bool print-paren true Option to print al This option enables print files in pa
|
||||
ean t-fields l fileds in parent rent class, default value true.
|
||||
class
|
||||
```
|
||||
|
||||
|
||||
### Get special option value
|
||||
|
||||
`options json-format`{{execute T2}}
|
||||
|
||||
```
|
||||
$ options json-format
|
||||
LEVEL TYPE NAME VALUE SUMMARY DESCRIPTION
|
||||
--------------------------------------------------------------------------------------------
|
||||
2 bool json-format false Option to support This option enables to format object
|
||||
ean JSON format of obj output with JSON when -x option selec
|
||||
ect output ted.
|
||||
```
|
||||
|
||||
> By default, `json-format` is false. When set `json-format` to true, commands like `wathc`/`tt` will print result with `json` format.
|
||||
|
||||
### Set special option value
|
||||
|
||||
For example, to enable saving command execution result, first check the log, and you can see there's no result:
|
||||
|
||||
`cat /root/logs/arthas-cache/result.log`{{execute T2}}
|
||||
|
||||
To enable saving command execution result, input the command below:
|
||||
|
||||
`options save-result true`{{execute T2}}
|
||||
|
||||
```
|
||||
$ options save-result true
|
||||
NAME BEFORE-VALUE AFTER-VALUE
|
||||
----------------------------------------
|
||||
save-result false true
|
||||
```
|
||||
|
||||
Wait for a second, and you will see there exist some results:
|
||||
|
||||
|
||||
`cat /root/logs/arthas-cache/result.log`{{execute T2}}
|
||||
|
||||
```bash
|
||||
$ cat /root/logs/arthas-cache/result.log
|
||||
2020-07-26 04:27:08 [arthas-command-execute] INFO result -
|
||||
2020-07-26 04:27:08 [arthas-command-execute] INFO result -
|
||||
```
|
||||
Reference in New Issue
Block a user