You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
arthas/en/_sources/advanced-use.md.txt

155 lines
6.2 KiB
Plaintext

7 years ago
Advanced Usage
==============
## Basic
6 years ago
* help - display Arthas help
* cls - clear the screen
6 years ago
* [cat](cat.md) - Concatenate and print files
5 years ago
* [echo](echo.md) - write arguments to the standard output
5 years ago
* [grep](grep.md) - Pattern searcher
5 years ago
* [tee](tee.md) - Copies standard input to standard output, making a copy in zero or more files.
6 years ago
* [pwd](pwd.md) - Return working directory name
6 years ago
* session - display current session information
5 years ago
* [reset](reset.md) - reset all the enhanced classes. All enhanced classes will also be reset when Arthas server is closed by `stop`
6 years ago
* version - print the version for the Arthas attached to the current Java process
* history - view command history
6 years ago
* quit/exit - exit the current Arthas session, without effecting other sessions
5 years ago
* stop - terminate the Arthas server, all Arthas sessions will be destroyed
6 years ago
* [keymap](keymap.md) - keymap for Arthas keyboard shortcut
7 years ago
7 years ago
## JVM
7 years ago
6 years ago
* [dashboard](dashboard.md) - dashboard for the system's real-time data
* [thread](thread.md) - show java thread information
* [jvm](jvm.md) - show JVM information
* [sysprop](sysprop.md) - view/modify system properties
6 years ago
* [sysenv](sysenv.md) — view system environment variables
6 years ago
* [vmoption](vmoption.md) - view/modify the vm diagnostic options.
5 years ago
* [perfcounter](perfcounter.md) - show JVM Perf Counter information
6 years ago
* [logger](logger.md) - print the logger information, update the logger level
6 years ago
* [getstatic](getstatic.md) - examine class's static properties
6 years ago
* [ognl](ognl.md) - execute ongl expression
* [mbean](mbean.md) - show Mbean information
* [heapdump](heapdump.md) - dump java heap in hprof binary format, like `jmap`
7 years ago
7 years ago
## class/classloader
7 years ago
6 years ago
* [sc](sc.md) - check the info for the classes loaded by JVM
* [sm](sm.md) - check methods info for the loaded classes
6 years ago
* [jad](jad.md) - decompile the specified loaded classes
6 years ago
* [mc](mc.md) - Memory compiler, compiles `.java` files into `.class` files in memory
* [redefine](redefine.md) - load external `*.class` files and re-define it into JVM
* [dump](dump.md) - dump the loaded classes in byte code to the specified location
6 years ago
* [classloader](classloader.md) - check the inheritance structure, urls, class loading info for the specified class; using classloader to get the url of the resource e.g. `java/lang/String.class`
7 years ago
## monitor/watch/trace - related
5 years ago
> **Attention**: commands here are taking advantage of byte-code-injection, which means we are injecting some [aspects](https://en.wikipedia.org/wiki/Aspect-oriented_programming) into the current classes for monitoring and statistics purpose. Therefore, when using it for online troubleshooting in your production environment, you'd better **explicitly specify** classes/methods/criteria, and remember to remove the injected code by `stop` or `reset`.
7 years ago
6 years ago
* [monitor](monitor.md) - monitor method execution statistics
* [watch](watch.md) - display the input/output parameter, return object, and thrown exception of specified method invocation
* [trace](trace.md) - trace the execution time of specified method invocation
* [stack](stack.md) - display the stack trace for the specified class and method
* [tt](tt.md) - time tunnel, record the arguments and returned value for the methods and replay
7 years ago
## options
6 years ago
* [options](options.md) - check/set Arthas global options
7 years ago
5 years ago
## profiler/flame graph
5 years ago
5 years ago
* [profiler](profiler.md) - use [async-profiler](https://github.com/jvm-profiling-tools/async-profiler) to generate flame graph
5 years ago
7 years ago
## pipe
6 years ago
Arthas provides `pipe` to process the result returned from commands further, e.g. `sm java.lang.String * | grep 'index'`. Commands supported in `pipe`:
7 years ago
6 years ago
* grep - filter the result with the given keyword
6 years ago
* plaintext - remove the ANSI color
6 years ago
* wc - count lines
7 years ago
5 years ago
## async jobs
7 years ago
6 years ago
[async](async.md) can be handy when a problem is hardly to reproduce in the production environment, e.g. one `watch` condition may happen only once in one single day.
7 years ago
6 years ago
* job control - use `>` to redirect result into the log file, use `&` to put the job to the background. Job keeps running even if the session is disconnected (the session lifecycle is 1 day by default)
7 years ago
* jobs - list all jobs
* kill - forcibly terminate the job
6 years ago
* fg - bring the suspend job to the foreground
* bg - put the job to run in the background
## Web Console
Arthas supports living inside a browser. The communication between arthas and browser is via websocket.
* [Web Console](web-console.md)
7 years ago
5 years ago
## Start as a Java Agent
* [Start as a Java Agent](agent.md)
5 years ago
## as.sh and arthas-boot tips
* Select the process to be attached via the `select` option.
Normally, `as.sh`/`arthas-boot.jar` needs to a pid, bacause the pid will change.
For example, with `arthas-demo.jar` already started, use the `jps` command to see.
```bash
$ jps
58883 arthas-demo.jar
58884 Jps
```
The `select` option allows you to specify a process name, which is very convenient.
```bash
$ ./as.sh --select arthas-demo
Arthas script version: 3.3.6
[INFO] JAVA_HOME: /tmp/java/8.0.222-zulu
Arthas home: /Users/admin/.arthas/lib/3.3.6/arthas
Calculating attach execution time...
Attaching to 59161 using version /Users/admin/.arthas/lib/3.3.6/arthas...
real 0m0.572s
user 0m0.281s
sys 0m0.039s
Attach success.
telnet connecting to arthas server... current timestamp is 1594280799
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
,---. ,------. ,--------.,--. ,--. ,---. ,---.
/ O \ | .--. ''--. .--'| '--' | / O \ ' .-'
| .-. || '--'.' | | | .--. || .-. |`. `-.
| | | || |\ \ | | | | | || | | |.-' |
`--' `--'`--' '--' `--' `--' `--'`--' `--'`-----'
5 years ago
wiki https://arthas.aliyun.com/doc
tutorials https://arthas.aliyun.com/doc/arthas-tutorials.html
5 years ago
version 3.3.6
pid 58883
```
5 years ago
## User data report
After the `3.1.4` version, arthas support user data report.
At startup, use the `stat-url` option, such as: `./as.sh --stat-url 'http://192.168.10.11:8080/api/stat'`
5 years ago
There is a sample data report in the tunnel server that users can implement on their own.
5 years ago
5 years ago
[StatController.java](https://github.com/alibaba/arthas/blob/master/tunnel-server/src/main/java/com/alibaba/arthas/tunnel/server/app/web/StatController.java)
5 years ago
6 years ago
## Other features
7 years ago
6 years ago
* [Async support](async.md)
7 years ago
* [log the output](save-log.md)
* [batch](batch-support.md)
* [how to use ognl](https://github.com/alibaba/arthas/issues/11)