Arthas is an open source Java diagnostic tool for Alibaba that developers love. Arthas can help you when you are stuck with a problem like the following:

  • From which JAR is this class loaded? Why are all kinds of class-related exceptions reported?
  • Why didn’t the code I changed execute? Did I not commit? Got the branch wrong?
  • If you encounter a problem, you cannot debug it online. Can you only re-publish it by logging?
  • There is a problem with a user’s data processing online, but it cannot be debugged online, and it cannot be reproduced offline!
  • Is there a global view of the health of the system?
  • Is there any way to monitor the real-time health of the JVM?
  • How to quickly locate application hot spots, generate flame map?

Arthas supports JDK 6+, Linux/Mac/Windows, command line interaction, and rich Tab auto-completion to further locate and diagnose problems.

Arthas commands and functions are described in detail in its official documentation. I will publish a full series of articles about how we use Arthas to locate and troubleshoot problems on a daily basis.

Extensions: Java Instrumentation refers to the ability to monitor and assist applications running on the JVM with agents that are independent of the application. This monitoring and assistance includes, but is not limited to, capturing JVM runtime status, replacing and modifying class definitions, and so on. Arthas’s overall logic is also based on Java Instrumentation.

Arthas Operating Process (Simple)

Arthas-boot. jar or as.sh is available as a direct installation. The former is shown here.

Arthas-boot.jar download arthas-boot.jar

Note: personal environment is Mac environment, other environment can be used for reference

The target file is downloaded to the current directory.

Arthas-boot.jar

You can see that after executing java-jar arthas-boot.jar, it lists the current Java processes for you to choose from, and then you can monitor that process. (You can also add pid monitoring directly, for example, java-jar arthas-boot.jar pid). After selecting the PID, it first downloads the JAR related files arthas needs and then does some initialization.

Note: the last line ‘[arthas@1640]$’ indicates that the monitoring client is opened, and relevant commands can be executed here to check. You can use quit (exit the current client), stop\shutdown (close the arthas server and exit all clients). In addition to viewing it from the command line, you can also view it from your browser by visiting http://127.0.0.1:8563/. The diagram below:

After we execute quit on the shell side and re-run the java-jar arthas-boot.jar 1640 current process. This article will not talk about the relevant content of attach mechanism for the moment, interested friends can first consult the information, the next chapter will be explained slowly.

Here is good after download file list, which is executed directly the second installation ‘curl – L alibaba. Making. IO/arthas/inst… | sh ‘installation files.

Simple arthas operation

By typing help, you can see that it provides a lot of functions, TAB can auto-complete function,

For note 1 in the list below, these commands are implemented using ASM bytecode enhancement, which inserts facets into the specified methods to perform statistics and observations. Therefore, it is necessary to make clear the classes, methods and conditions that need to be observed when using online and pre-release environments. After diagnosis, shutdown or run the reset command.

Here are a few common commands:

  • Dashboard: Check JVM thread env info

  • Thread: Views the running status of a thread

  • Jad: Decomcompile the class file.

– SC: view information about classes that have been loaded in the JVM. – Stack: view information about the call stack. – Track: observe which child calls are slow when a method executes

3.1 dashboard

It mainly shows three parts: threads, JVM, and Java-env. It refreshes automatically every few seconds

3.2 the Thread

Can be used to display some basic information about a thread, using the following syntax

For example, -n displays information about several threads, sorted by CPU usage

3.3 jad

Can be used to check if the published code online is up to date. You can locate a concrete class, or a concrete method. It’s very convenient.

3.4 mc redefine

Compile the class and load it externally.

You can view

  • alibaba.github.io/arthas/mc
  • Alibaba. Making. IO/arthas/rede…

3.5 sc

View information about classes loaded in the JVM

For example, view the java.util.Stack class information

I will soon publish a full series of articles on how we use Arthas to locate and troubleshoot problems on a daily basis! Working on a case… Stay tuned!

The author | wisdom elder brother

The original link

This article is the original content of the code farm architecture, shall not be reproduced without permission.