1. What is Arthas?
From Arthas’s Github introduction:
Arthas is a Java Diagnostic tool open sourced by Alibaba.
Arthas allows developers to troubleshoot production issues for Java applications without modifying code or restarting servers.
Arthas is an open-source Java diagnostic tool that helps developers quickly locate online problems without modifying code or restarting the server.
Sounds like a real boon for our programmers. For example, we encounter a situation where the Spring Boot application has a scheduled CRon task that starts at 1 am every day, but it is very inconvenient to test. Can’t you change the CRon time every time to let QC test it? Although this is convenient for testing sister, but it increases our development time and iteration times!! Does Arthas meet our needs? Go on…
2. Start Arthas
2.1 installation Arthas
- Method 1: Download arthas-boot.jar
wget https://alibaba.github.io/arthas/arthas-boot.jar
Copy the code
There will be an arthas-boot.jar package in your current directory.
Try arthas:
#Starting arthas brings you into command line interaction
java -jar arthas-boot.jar
#Check out the arthas command manual
java -jar arthas-boot.jar -h
Copy the code
- Option 2: Install Arthas via as.sh (highly recommended)
#This command will download as.sh to the current directory
curl -L https://alibaba.github.io/arthas/install.sh | sh
Copy the code
Try arthas:
#Starting arthas brings you into command line interaction
./as.sh
#Check out the arthas command manual
./as.sh -h
Copy the code
2.2 Starting use
For the following demonstration, we will use as.sh as the main.
First we launch arthas and see that the application deployed on our current server has been detected. Currently there is only one application on my server and I can interact with it by typing the number 1:
2.2.1 Basic Commands
- through
dashboard
Command to view application monitoring data in real time
- through
thread
Command to view the status of all threads in the application
-
Run the thread threadId command to view the status of a specified thread
- For example, we want to check the status of the thread whose ID is 506:
- Of course, since it is command-line interaction, it also supports piped streaming operations:
-
Use the watch command to view method parameters, return values, and exception information
-
Run the sc command to view the class information
- through
sc yourFullClassName
- through
sc -d yourFullClassName*
To view information about classes loaded by the JVM
- through
sc *yourClassName*
To view information about classes loaded by the JVM
- through
-
View the method information of the class using the sm command
- case 1:
sm java.math.RoundingMode
- case 2:
sm -d java.math.RoundingMode
- case 3:
sm java.math.RoundingMode <init>
- case 1:
2.2.2 Highlight command
-
Use JAD yourFullClassName to see the full decompiled code
-
Export the decomcompiled code to a temporary directory using jad –source-only yourFullClassName > / TMP/yourclassname.java
-
Edit the code via vim/TMP/yourclassname.java
-
Through the sc – d * yourClassName | grep classLoaderHash get loaded yourClassName class loader
-
Java -d/TMP to re-compile the modified class with the same classloader (MC: Memory Compiler)
-
By redefine/TMP/yourFullClassName. Class to load the new compiled class files
2.2.3 More Operation cases
Please refer to the official manual for more operation cases and usage.
The resources
- Arthas
- Arthas user manual