Advanced Usage

Basic

  • help - display Arthas help

  • cls - clear the screen

  • cat - Concatenate and print files

  • echo - write arguments to the standard output

  • grep - Pattern searcher

  • base64 - Encode and decode using Base64 representation.

  • tee - Copies standard input to standard output, making a copy in zero or more files.

  • pwd - Return working directory name

  • session - display current session information

  • reset - reset all the enhanced classes. All enhanced classes will also be reset when Arthas server is closed by stop

  • version - print the version for the Arthas attached to the current Java process

  • history - view command history

  • quit/exit - exit the current Arthas session, without effecting other sessions

  • stop - terminate the Arthas server, all Arthas sessions will be destroyed

  • keymap - keymap for Arthas keyboard shortcut

JVM

  • dashboard - dashboard for the system’s real-time data

  • thread - show java thread information

  • jvm - show JVM information

  • sysprop - view/modify system properties

  • sysenv — view system environment variables

  • vmoption - view/modify the vm diagnostic options.

  • perfcounter - show JVM Perf Counter information

  • logger - print the logger information, update the logger level

  • getstatic - examine class’s static properties

  • ognl - execute ognl expression

  • mbean - show Mbean information

  • heapdump - dump java heap in hprof binary format, like jmap

  • vmtool - jvm tool, getInstances in jvm, forceGc

class/classloader

  • sc - check the info for the classes loaded by JVM

  • sm - check methods info for the loaded classes

  • jad - decompile the specified loaded classes

  • mc - Memory compiler, compiles .java files into .class files in memory

  • retransform - load external *.class files and retransform it into JVM

  • redefine - load external *.class files and re-define it into JVM

  • dump - dump the loaded classes in byte code to the specified location

  • classloader - 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

authentication

  • auth - authentication

options

  • options - check/set Arthas global options

profiler/flame graph

pipe

Arthas provides pipe to process the result returned from commands further, e.g. sm java.lang.String * | grep 'index'. Commands supported in pipe:

  • grep - filter the result with the given keyword

  • plaintext - remove the ANSI color

  • wc - count lines

async jobs

async 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.

  • 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)

  • jobs - list all jobs

  • kill - forcibly terminate the job

  • 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.

Arthas Properties

Start as a Java Agent

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 math-game.jar already started, use the jps command to see.

$ jps
58883 math-game.jar
58884 Jps

The select option allows you to specify a process name, which is very convenient.

$ ./as.sh --select math-game
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  \ '   .-'
|  .-.  ||  '--'.'   |  |   |  .--.  ||  .-.  |`.  `-.
|  | |  ||  |\  \    |  |   |  |  |  ||  | |  |.-'    |
`--' `--'`--' '--'   `--'   `--'  `--'`--' `--'`-----'

wiki      https://arthas.aliyun.com/doc
tutorials https://arthas.aliyun.com/doc/arthas-tutorials.html
version   3.3.6
pid       58883

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'

There is a sample data report in the tunnel server that users can implement on their own.

StatController.java