Arthas-Java's ultimate tool for online problem location processing-quick start

1. Preface

Before using Arthas, when you encounter Java online problems, such as CPU soaring, sudden high load, memory overflow, etc., you need to check commands, check the network, and then perform one-stop operations such as jps, jstack, jmap, jhat, jstat, hprof, etc. . In the end, I was so devastated that I might not be able to find out the problem. Now, you can use Arthas to locate most common problems easily, solve them quickly, and stop the war in time.

2. Introduction to Arthas

Arthas is Alibaba's open source Java diagnostic tool in September 2018. It supports JDK6+, adopts the command line interactive mode, and provides automatic tab failure, which is deeply loved by developers. Online troubleshooting without restarting; dynamic tracking of Java code; real-time monitoring of JVM status.

3. Arthas usage scenarios

What Arthas helped programmers and operation and maintenance personnel solve

  • Which jar package is this class loaded from? Why are various types of related Exception reported?
  • Why is the code I changed not executed? Could it be that I didn't commit? Wrong branch?
  • I can’t debug online if I encounter a problem, can I only republish it by adding a log?
  • I encountered a user's data processing problem online, but the online debugging is also impossible, and the offline cannot be reproduced!
  • Is there a global perspective to view the health of the system?
  • Is there any way to monitor the real-time running status of the JVM?
  • How to quickly locate application hot spots and generate flame graphs?
4. How to use Arthas
  1. Quick Start
    Arthas is a command-line interactive Java diagnostic tool. Since it is written in Java, you can download the corresponding jar package and run it directly.
    Start the demo: arthas-demo is a simple program that generates a random number every second, performs prime factor decomposition, and prints out the decomposition result.
curl -O https://arthas.aliyun.com/arthas-demo.jar
java -jar arthas-demo.jar

The arthas-boot project can be downloaded on the official Github. If the speed is slow, you can try the domestic code cloud Gitee download.

# github下载
wget https://alibaba.github.io/arthas/arthas-boot.jar
# 或者 Gitee 下载
wget https://arthas.gitee.io/arthas-boot.jar
# 打印帮助信息
java -jar arthas-boot.jar -h
  1. Start arthas and select the application java process:
[root@localhost ~]# java  -jar  arthas-boot.jar --target-ip  0.0.0.0

Insert picture description here

  • The web console
    Arthas currently supports the Web Console. After successfully starting the connection process, it will automatically start. You can directly visit http://192.168.189.131:8563/ to access. The operation mode on the page is exactly the same as the console.
    [External link image transfer failed. The source site may have an anti-leech link mechanism. It is recommended to save the image and upload it directly (img-sMpzPZas-1616062462924)(http://10.152.160.36/server/index.php?s=/api/ attachment/visitFile/sign/dd6ae6236bac1f200ff33f50befeb388&showdoc=.jpg)]

  • Enter the dashboard, press Enter/Enter, the current process information will be displayed, and press ctrl+c to interrupt the execution.

[arthas@9419]$ dashboard
  • To obtain the Main Class
    thread 1 of the arthas-demo process through the thread command , the stack of thread ID 1 will be printed, which is usually the thread of the main function.
[arthas@9419]$ thread 1 | grep  main
"main" Id=1 TIMED_WAITING
    at demo.MathGame.main(MathGame.java:17)
[arthas@9419]$ 
  • Decompile Main Class through jad
[arthas@9419]$ jad demo.MathGame

[External link image transfer failed. The origin site may have an anti-leech link mechanism. It is recommended to save the image and upload it directly (img-EvpOVYz8-1616062462925)(http://10.152.160.36/server/index.php?s=/api/ attachment/visitFile/sign/10558fc9f726e87fbe5a19bdff3ef23c&showdoc=.jpg)]

  • Use the watch command to view the return value of the demo.MathGame#primeFactors function
[arthas@9419]$ watch demo.MathGame primeFactors returnObj

[External link image transfer failed. The origin site may have an anti-leech link mechanism. It is recommended to save the image and upload it directly (img-H6JjhWI8-1616062462926)(http://10.152.160.36/server/index.php?s=/api/ attachment/visitFile/sign/d3c2dd6c5e84d9e44f332e4986e1f4f6&showdoc=.jpg)]

  • To exit arthas,
    if you just exit the current connection, you can use the quit or exit command

Guess you like

Origin blog.csdn.net/qq_31555951/article/details/114987205