preface

Welcome to our GitHub repository Star: github.com/bin39232820… The best time to plant a tree was ten years ago, followed by now

omg

Let’s talk about the origin of this article. I was studying at home on Saturday night, and I had to download something on my phone, so I went out to check the signal in the hallway. As soon as MY front foot went out, the wind closed the back foot door.

It was 8 o ‘clock, and the landlord didn’t come back until 10 o ‘clock. How a bad word get. I’ll use the time to prepare for this article.

preface

Before Arthas, when you had Java online problems like CPU spikes, load spikes, memory overruns, you looked up commands, looked up networks, and then JPS, jStack, Jmap, Jhat, jstat, hprof, etc. You end up in a mess, and you don’t always know what the problem is. Today, Arthas can be used to locate most common problems, solve them quickly, stop your losses, and leave work on time.

introduce

Arthas is a Java diagnostic tool that Alibaba opened source in September 2018. Support JDK6+, using command line interaction mode, Tab automatic incomplete, you can easily locate and diagnose online program running problems. Arthas official documentation is very detailed, and this article has also referred to the Arthas official documentation, as well as the Github project Issues section, which provides feedback and a large number of use cases for reference.

  • Open source: github.com/alibaba/art…

  • Official documentation: Baba.github. IO /arthas

case

In fact, these things are specific online cases provided by Ali. For me, I also is carrying, popular science science for everyone, but it really works, such as online we have a problem, when writing the code have no dozen logs, don’t know in the process of running, the trace of the current thread to the current method, but can help us solve Arthas, for we have to add a log to restart this is too much trouble

According to the online documentation, to introduce you to a few practical commands oh.

Download and Installation

Wget https://alibaba.github.io/arthas/arthas-boot.jar Java jar arthas - boot. The jar - target - IP 0.0.0.0Copy the code

Arthas-boot is the arthas launcher. Once arthas is started, all Java processes are listed and the user can select the target process to diagnose.

Note: (important) Arthas cannot be connected remotely directly. The IP and port entered when arthAS is started is the IP and port exposed to the outside world. Target-ip: If you want to use the Web Console on another machine, enter the IP address of the local machine (for example, 192.168.33.44). In this case, you can visit http://ip:8563

The red line is where Arthas can listen to our Java program

And then we choose 1

This is the interface to access the monitoring.

Common commands

The command role
dashboard Real-time data panel for the current system
thread View thread stack information for the current JVM
watch Method to perform data observations
trace Method internally calls the path and prints the time spent on each node on the method path
stack Prints the call path to which the current method is called
tt A space-time tunnel of method execution data, recording the input and return information of each call to the specified method, and observing these different time calls
monitor Method Execution monitoring
jvm View current JVM information
vmoption View and update parameters related to JVM diagnostics
sc View information about classes loaded by the JVM
sm View method information for loaded classes
jad Decompile the source code that specifies the loaded class
classloader View the classloader inheritance tree, urls, class loading information
heapdump The heap dump function is similar to the jmap command

Global Monitoring Dashboard

All of these parameters are nice, but this kind of monitoring is certainly not new, as Java comes with a lot of tools, but it’s just icing on the cake.

Why did the CPU take off Thread

Using it to troubleshoot CPU problems is not a good batch

Use thread to view information about all threads, and the CPU usage of each thread is listed.

Using the command Thread 12, you can see that the CPU uses higher methods and lines (this may differ from the number of lines in the code above, which was reprinted at the time I wrote this article).

This is done by looking at thread information in general and then looking at specific thread performance. If you’re just looking for threads with high CPU usage, you can simply use the command thread-n [number of threads displayed] to list the threads with the highest CPU usage.

At the end

Ha ha specific a lot of things, I think we follow the documentation, there are online examples, but the online example is very annoying point is often disconnected, infuriated me, we walk several times, write a few demo, what thread problem, just like the test line break point, are the same, there is nothing difficult is not.

Reference documents are above, this article is a popular science.

The following article is also very good

  • example

Daily for praise

Ok, everybody, that’s all for this article, you can see people here, they are real fans.

Creation is not easy, your support and recognition, is the biggest motivation for my creation, we will see in the next article

Six pulse excalibur | article “original” if there are any errors in this blog, please give criticisms, be obliged!