Arthas Java fell in love with the diagnostic tool

1. Arthas What is that?

Excerpt from Arthas's Github description:

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.

The effect that: Arthas Ali is an open-source Java diagnostic tool that can help developers to modify the code without restarting the server or online to quickly locate the problem.

It sounds really is a great benefit to our programmers. For example, we encountered a situation, Spring Boot applications have a cron cron job every day for the 1:00 start the execution, but very easy to test, we can not always make time to modify cron QC test, right? Although this is a convenient test sister, but inviting our development time and the number of iterations ah! ! ! Arthas in the end that is able to meet our needs? Go on ...

2. Turn on Arthas tour

2.1 Installation Arthas

  • Embodiment 1: Download arthas-boot.jar packet mode
wget https://alibaba.github.io/arthas/arthas-boot.jar
复制代码

At this point in your current directory will have a arthas-boot.jarpackage.

Try the next arthas:

# 启动arthas,会进入命令行交互状态
java -jar arthas-boot.jar

# 查看arthas命令手册
java -jar arthas-boot.jar -h
复制代码

  • Option 2: (by as.sh installation Arthas strongly recommended )
# 该命令会下载 as.sh 到当前目录下
curl -L https://alibaba.github.io/arthas/install.sh | sh
复制代码

Try the next arthas:

# 启动arthas,会进入命令行交互状态
./as.sh

# 查看arthas命令手册
./as.sh -h
复制代码

2.2 started

The following shows our as.shmain.

First, we start arthas, we will see to the application currently deployed on the server has been detected, on my current server only one application, simply enter the number 1, and the application can interact with:

2.2.1 basic commands

  • By dashboardcan view real-time application monitoring data command

  • By threadviewing application threads in all cases command

Wherein as a first thread ID.

  • By thread threadIdviewing the specified thread status information command

    • For example, we want to see the thread ID for the thread state 506 information:

    • Of course, because it is a command line interaction, also supports streaming pipeline operations:

  • By watchcommand to view the method parameters, return values, and exception information

  • By sccommand to view the type of information

    • bysc yourFullClassName

    • By sc -d yourFullClassName*going to see loads of JVM class information

    • By sc *yourClassName*going to see loads of JVM class information

  • By smviewing the class information command method

    • case 1: sm java.math.RoundingMode

    • case 2: sm -d java.math.RoundingMode

    • case 3: sm java.math.RoundingMode <init>

2.2.2 highlight command

  • By jad yourFullClassNamegoing to see the complete code information decompiling

  • By jad --source-only yourFullClassName > /tmp/yourClassName.javaexporting decompile the code to a temporary directory

  • By vim /tmp/yourClassName.javaediting modify the code

  • By sc -d *yourClassName | grep classLoaderHashacquiring loading yourClassName class loader

  • By mc -c classLoaderHash /tmp/yourClassName.java -d /tmpre-using the same class loader class (mc: Memory Compiler) recompile the modified

  • By redefine /tmp/yourFullClassName.classreload the new compiled class files

2.2.3 More Actions Case

Please refer to the official manual for more operational cases and usage.

Reference material

Guess you like

Origin juejin.im/post/5cf93512f265da1b6b1cc71f