
What is Arthas?
Arthas is an open-source Java online diagnostic tool developed by Alibaba. It is very powerful and can solve many issues that are inconvenient to address online.
Arthas operates in a command-line interactive mode, supports JDK6+, and is compatible with Linux, Mac, and Windows operating systems. The commands also support tab key auto-completion for various information, making diagnostics very efficient.
Here is its official website:
https://alibaba.github.io/arthas/index.html
GitHub repository:
https://github.com/alibaba/arthas
What Problems Can Arthas Solve?
Let’s take a look at the official explanation of Arthas.
When you encounter the following problems and feel helpless, Arthas can help you solve them: 1. From which jar file is this class loaded? Why does it report various class-related exceptions? 2. Why is the code I modified not executed? Did I forget to commit? Did I switch branches incorrectly? 3. When encountering issues, is it only possible to add logs and redeploy? 4. There is a problem with data processing for a specific user online, but it cannot be debugged online, and it cannot be reproduced offline! 5. Is there a global perspective to view the system’s operational status? 6. Is there a way to monitor the real-time running status of the JVM? Arthas Official Website
Isn’t it impressive after reading this?
Especially since it can decompile classes online, allowing for debugging and tracking of problematic code without adding logs.
Since it is so powerful, many companies must be using it. Below is the usage login sequence diagram provided by the official documentation.

Quick Installation
The official recommendation is to use arthas-boot for installation, which is very convenient. The following demonstration is based on a Linux system environment, which is generally used to solve online issues.
Step 1: Download
Download the arthas-boot package in any directory.
wget https://alibaba.github.io/arthas/arthas-boot.jar
[root@VM_0_7_centos ~]# wget https://alibaba.github.io/arthas/arthas-boot.jar
--2019-07-30 14:48:31-- https://alibaba.github.io/arthas/arthas-boot.jar
Resolving alibaba.github.io (alibaba.github.io)... 185.199.108.153, 185.199.109.153, 185.199.110.153, ...
Connecting to alibaba.github.io (alibaba.github.io)|185.199.108.153|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 98637 (96K) [application/java-archive]
Saving to: ‘arthas-boot.jar’
100%[==========================================================================================================>] 98,637 32.8KB/s in 2.9s
2019-07-30 14:48:36 (32.8 KB/s) - ‘arthas-boot.jar’ saved [98637/98637]
Step 2: Run
Use the java -jar command to execute the arthas-boot package.
java -jar arthas-boot.jar
[INFO] arthas-boot version: 3.1.1
[INFO] Found existing java process, please choose one and hit RETURN.
* [1]: 13062 spring-boot-best-practice-0.0.1-SNAPSHOT.jar
Step 3: Select Process
After running arthas-boot, the console will display all Java processes. Select the process you need to diagnose.
As shown in step two, there is only one Java process here. Enter the number 1 and press Enter, Arthas will attach to the target process and output logs:
[INFO] Start download arthas from remote server: https://maven.aliyun.com/repository/public/com/taobao/arthas/arthas-packaging/3.1.1/arthas-packaging-3.1.1-bin.zip
[INFO] Download arthas success.
[INFO] arthas home: /root/.arthas/lib/3.1.1/arthas
[INFO] Try to attach process 13062
[INFO] Attach process 13062 success.
[INFO] arthas-client connect 127.0.0.1 3658
,---. ,------. ,--------.,--. ,--. ,---. ,---.
/ O \ | .--. ''--. .--'| '--' | / O \ ' .-'
| .-. || '--'.' | | | .--. || .-. |`. `-.
| | | || |\ \ | | | | | || | | |.-' |
`--' `--'`--' '--' `--' `--' `--'`--' `--'`-----'
wiki https://alibaba.github.io/arthas
tutorials https://alibaba.github.io/arthas/arthas-tutorials
version 3.1.1
pid 13062
time 2019-07-30 14:49:34
At this point, the installation and startup are complete.
For more installation methods, see: https://alibaba.github.io/arthas/install-detail.html
Practical Usage
After startup, the current cursor will enter the arthas console, accepting various operational commands.
Next, I will demonstrate a few commonly used commands to give everyone a basic understanding and quick ability to get started.
1. dashboard
Displays the real-time data panel of the current system. Press ctrl+c to exit.
$ dashboard

2. thread
View the current JVM’s thread stack information.
To display the running stack of a specified thread:
$ thread 20

To display the top N busiest threads and print their stacks:
$ thread -n 3

3. sc
View detailed information about the classes loaded in the JVM.
$ sc -d *Test

4. sm
View method information of loaded classes.
$ sm -d cn.javastack.springbootbestpractice.SpringBootBestPracticeApplication main

5. jad
Decompile the source code of a specified loaded class.
$ jad cn.javastack.springbootbestpractice.SpringBootBestPracticeApplication

6. trace
Display the internal call path of a method, returning non-real-time commands and outputting the total time spent on the method path and detailed time spent at each node.
$ trace -j cn.javastack.springbootbestpractice.web.JsonTest getUserInfo

-j: indicates skipping the method path in the JDK.
7. monitor
Perform timed monitoring of a method’s calls.
$ monitor cn.javastack.springbootbestpractice.web.JsonTest getUserInfo -c 5

-c 5: indicates that statistics are collected every 5 seconds, with a default cycle of 120 seconds.
Monitoring Dimension Explanation:
| Monitoring Item | Description |
|---|---|
| timestamp | Timestamp |
| class | Class Name |
| method | Method Name |
| total | Call Count |
| success | Success Count |
| fail | Failure Count |
| rt | Average Response Time |
| fail-rate | Failure Rate |
8. watch
Observe method execution data, allowing easy observation of the call situation of a specified method, such as return values, exceptions thrown, parameters, etc.
$ watch cn.javastack.springbootbestpractice.web.JsonTest getUserInfo ‘{params, returnObj}’ -x 2 -b

The above monitors the input parameters of a method before execution: -b, traversal depth: -x 2.
9. quit/exit
Exit the current Arthas session.
This command only exits the current connected client; Arthas attached to the target process will continue running, and the port will not close. You can connect directly for the next session.
10. shutdown
Shut down the Arthas server and exit all Arthas clients.
The above demonstrated the basic usage of 10 commands. For detailed usage of various commands, you can refer to the command with --help.

For more commands, please refer to:
https://alibaba.github.io/arthas/commands.html
Conclusion
In summary, using Arthas makes it very convenient to diagnose a Java application, such as system data panels, real-time JVM running status, class loading status, monitoring method execution, displaying method execution paths, etc.
The practical features of Arthas can indeed help us solve some common online issues and can operate independently of application code, but it is limited to a single JVM process. If it is a distributed system, Arthas may face challenges.
That’s all for today’s article. Are you also using Arthas? Feel free to leave a comment to share your experiences. If you find the article helpful, you can also share it with your classmates and colleagues.
Follow our WeChat public account: Java Technology Stack, and reply “Tools” in the background to get a list of tools shared by the stack leader. In the future, if there are good Java development tools, the stack leader will share them on the public account as soon as possible.
Follow the Java Technology Stack WeChat public account and reply with the keyword:Java to get a collection of the latest Java technology materials organized by the stack leader.
Recent Material Sharing
10 Ways to Create Streams in Java 8
Don’t rush to run away after accidentally executing rm -f
10 Tips for IntelliJ IDEA Smart Completion!
Spring Boot Interview, one question can take you down
Sharing a set of learning materials for Java Architects

Good article, I’m reading