Alibaba Arthas-- online problem analysis tool


This blog reprinted from Ali diagnostic tools open-source Java


What is 1. Arthas

Arthas is an open-source Java Alibaba online diagnostic tools, very powerful, can solve a lot of problems to solve online is not convenient.

Arthas diagnosis using a command line interactive mode, support JDK6 +, Linux, Mac, Windows operating system, use the tab key command also supports auto-completion of all kinds of information, the diagnosis is very convenient.

This is its official website:

https://alibaba.github.io/arthas/index.html

Github Address:

https://github.com/alibaba/arthas

2. Arthas can solve any problem

Look Arthas official explanation

When you encounter the following problems similar helpless, Arthas can help you solve:
1, the class from which jar package loaded? Why would report a variety of categories associated Exception?
2, Why did not I change the code to execute? Could it be I did not commit? Branch made a mistake?
3, a problem can not be online debug, only re-released by adding the log it?
4, online encounter a user's data processing problems, but the same can not be online debug, the line can not reproduce!
5. Is there a global perspective to view the health of the system?
6. Is there any way to run real-time status monitoring of the JVM?

Reading is not that too Niubi? In particular, it can compile the anti-online classes, you can not add a log line debugging tracking code.

3. Quick Installation

The official recommended arthas-bootto install, very easy, the following is a Linux-based environment for presentation, general problem solving online is also based on Linux environment.

Step One: Download

In any directory download arthas-bootthis package.

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 java -jarthe command execution arthas-bootpackage.

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

Run arthas-boot, the console displays all Java processes, you need to select a diagnostic process.

As shown in the second step, there is only a Java process, enter a number, the transport, Arthas be attached to the target process, and outputs the log:

[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, installation, startup is complete.

See more other installation: https: //alibaba.github.io/arthas/install-detail.html

4. actual use

After startup, the cursor will enter arthas console, a variety of operation commands.

Here, the stack length will do several presentations commonly used commands, so that we have a basic understanding of it and the ability to quickly get started.

1, dashboard
display real-time data panel the current system, press ctrl + c to exit.

$ dashboard

dashboard

2. thread
view the current JVM thread stack information.

thread id, display the specified thread running stack:

$ thread 20

Showing the top before the N threads and prints the current stack:

$ thread -n 3

3. sc
View Class Details JVM loaded.

$ sc -d *Test

4. sm
view method information has been loaded class.

$ sm -d cn.javastack.springbootbestpractice.SpringBootBestPracticeApplication main

5. jad
decompile the specified source code has been loaded classes.

$ Jad cn.javastack.springbootbestpractice.SpringBootBestPracticeApplication

6. trace
display method of an internal call path, to return the non-real-time command and outputs the total time on the path method, and the detailed time-consuming on each node.

$ Trace j cn.javastack.springbootbestpractice.web.JsonTest getUserInfo

7. monitor
to call a method of timing monitors.

$ Monitor cn.javastack.springbootbestpractice.web.JsonTest getUserInfo -c 5

-c 5: Statistics once every 5 seconds represents, period, the default value is 120 seconds.

Description monitor dimensions:

8. watch
observation method for performing data calls can be easily observed in the case of the specified method, such as: the return value, an exception is thrown, the parameters and the like.

$ watch cn.javastack.springbootbestpractice.web.JsonTest getUserInfo '{params, returnObj}' -x 2 -b

Monitoring the above parameters into the case of a method, performed in front monitor method: -b, traversal depth: -x 2.

9. quit / exit
to exit the current Arthas.

This command exits only client currently connected, Arthas attached to the target process continues to run, it does not close the port can be directly connected using the next time you connect.

10. shutdown
shut down the server Arthas, Arthas quit all clients.

Above illustrates the basic use 10 command, using the details with various commands can be found at --help command.

More other commands, refer to:

https://alibaba.github.io/arthas/commands.html

5. Summary

To conclude, it is easy to use diagnostic Arthas a Java application, such as: the panel system data, real-time operating state of the JVM, the class is loaded, the performance monitoring method, a display method execution path and the like.

Arthas these useful features can really help us solve some common questions online, but also independent of the application code, but only within a limited JVM process, if it is a distributed system, Arthas bit harder.

Guess you like

Origin www.cnblogs.com/54chensongxia/p/11452740.html