The tools described above must configure relevant monitoring parameters in the server project process, and then the tools connect to the project process remotely to obtain relevant data. This will bring some inconvenience. For example, the network of the online environment is isolated, and the local monitoring tools are not connected to the online environment at all. And business tools like Jprofiler need to be paid. Is there a tool that does not require remote connection, does not need to configure monitoring parameters, and also provides rich performance monitoring data?
Alibaba's open source performance analysis artifact Arthas came into being.
Arthas is an open source Java diagnostic tool of Alibaba, which is deeply loved by developers. Online troubleshooting without restart; Dynamic tracking of Java code; Monitor JVM status in real time. Arthas supports JDK 6 +, Linux / Mac / Windows, adopts command-line interaction mode, and provides rich Tab automatic completion function to further facilitate problem location and diagnosis. When you encounter the following similar problems and are helpless, Arthas can help you solve them:
- Which jar package is this class loaded from? Why are all kinds of related exceptions reported?
- Why didn't the code I changed execute? Am I not commit ted? Wrong branch?
- You can't debug online when you encounter a problem. Can you only republish it by adding a log?
- There is a problem with the data processing of a user online, but it is also impossible to debug online and reproduce offline!
- 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 hotspots and generate flame diagrams?
Arthas official address: Quick start - Arthas 3.5.4 documentation
Arthas installation method: if the speed is slow, you can try the domestic code cloud Gitee download. Installation documentation:
//Under linux wget https://io/arthas/arthas-boot.jar wget https://arthas/gitee/io/arthas-boot.jar
Arthas is just a java program, so it can be run directly with java -jar. arthas-boot.jar download address: https://arthas.aliyun.com/download/latest_version?mirror=aliyun
In addition to viewing on the command line, Arthas currently supports the Web Console. After successfully starting the connection process, it has been automatically started and can be accessed directly http://127.0.0.1:8563/ The operation mode on the page is exactly the same as that on the console.
2, Arthas basic instruction
- quit/exit: exit the current Arthas client, and other Arthas clients will not be affected;
- stop/shutdown: close the Arthas server, and all Arthas clients exit;
- Help: View command help information;
C:\Users\WSH\Desktop\arthas-packaging-3.5.4-bin>jps 11572 Launcher 12596 4228 RemoteMavenServer 16652 Jps 17836 GCTest [arthas@17836]$ help NAME DESCRIPTION help Display Arthas Help auth Authenticates the current session keymap Display all the available keymap for the specified connection. sc Search all the classes loaded by JVM sm Search the method of classes loaded by JVM classloader Show classloader info jad Decompile class getstatic Show the static field of a class monitor Monitor method execution statistics, e.g. total/success/failure count, average rt, fail rate, etc. stack Display the stack trace for the specified class and method thread Display thread info, thread stack trace Trace the execution time of specified method invocation. watch Display the input/output parameter, return object, and thrown exception of specified method invocation tt Time Tunnel jvm Display the target JVM information perfcounter Display the perf counter information. ognl Execute ognl expression. mc Memory compiler, compiles java files into bytecode and class files in memory. redefine Redefine classes. @see Instrumentation#redefineClasses(ClassDefinition...) retransform Retransform classes. @see Instrumentation#retransformClasses(Class...) dashboard Overview of target jvm's thread, memory, gc, vm, tomcat info. dump Dump class byte array from JVM heapdump Heap dump options View and change various Arthas options cls Clear the screen reset Reset all the enhanced classes version Display Arthas version session Display current session information sysprop Display, and change the system properties. sysenv Display the system env. vmoption Display, and update the vm diagnostic options. logger Print logger info, and update the logger level history Display command history cat Concatenate and print files base64 Encode and decode using Base64 representation echo write arguments to the standard output pwd Return working directory name mbean Display the mbean information grep grep command for pipes. tee tee command for pipes. profiler Async Profiler. https://github.com/jvm-profiling-tools/async-profiler vmtool jvm tool stop Stop/Shutdown Arthas server and exit the console.
- Cat: print file content, similar to cat command in linux;
- Echo: print parameters, similar to echo command in linux
- grep: match lookup, similar to the gep command in linux;
- base64 : Base64 encoding conversion, similar to the base64 command in linux;
//base64 encoding of files [arthas@70070]$ echo 'abc' > /tmp/test.txt [arthas@70070]$ cat /tmp/test.txt abc [arthas@70070]$ base64 /tmp/test.txt YWJjCg== //base64 encode the file and save the results to the file base64 --input /tmp/test.txt --output /tmp/result.txt //Decoding files with base64 $ base64 -d /tmp/result.txt abc //Decode the file with base64 and save the results to the file $ base64 -d /tmp/result.txt --output /tmp/bbb.txt
- pwd: returns the current working directory, similar to the linux command
- cls: clear the current screen area;
- Session: view the information of the current session;
[arthas@17836]$ session Name Value -------------------------------------------------- JAVA_PID 17836 SESSION_ID 3d5b3e8e-6ba0-4f0d-8514-c2e62648e8b6
- Reset: reset the enhanced classes and restore all the classes enhanced by Arthas. When the Arthas server is closed, all the enhanced classes will be reset;
- Version: output the Arthas version number loaded by the current target Java process;
[arthas@17836]$ version 3.5.4
- History: print the command history. The history command will be persisted through a file called history, so the history command can view all the historical commands of the current arthas server, not just the commands used in the current session.
[arthas@17836]$ history 1 dashboard 2 help 3 session 4 version 5 history //#View 3 recently executed instructions [arthas@16288]$ history 3 3 session 4 version 5 history //Clear command [arthas@16288]$ history -c [arthas@16288]$ history 1 history
- keymap: Arthas shortcut key list and user-defined shortcut keys
[arthas@16288]$ keymap Shortcut Description Name ----------------------------------------------------------------------------------------------------------------------- "\C-a" Ctrl + a beginning-of-line "\C-e" Ctrl + e end-of-line "\C-f" Ctrl + f forward-word "\C-b" Ctrl + b backward-word "\e[D" Left arrow backward-char "\e[C" Right arrow forward-char "\e[A" Up arrow history-search-backward "\e[B" Down arrow history-search-forward "\C-h" Ctrl + h backward-delete-char "\C-?" Ctrl + ? backward-delete-char "\C-u" Ctrl + u undo "\C-d" Ctrl + d delete-char "\C-k" Ctrl + k kill-line "\C-i" Ctrl + i complete "\C-j" Ctrl + j accept-line "\C-m" Ctrl + m accept-line "\C-w" Ctrl + w backward-delete-word "\C-x\e[3~" "\C-x\e[3~" backward-kill-line "\e\C-?" "\e\C-?" backward-kill-word "\e[1~" "\e[1~" beginning-of-line "\e[4~" "\e[4~" end-of-line "\e[5~" "\e[5~" beginning-of-history "\e[6~" "\e[6~" end-of-history "\e[3~" "\e[3~" delete-char "\e[2~" "\e[2~" quoted-insert "\e[7~" "\e[7~" beginning-of-line "\e[8~" "\e[8~" end-of-line "\eOH" "\eOH" beginning-of-line "\eOF" "\eOF" end-of-line "\e[H" "\e[H" beginning-of-line "\e[F" "\e[F" end-of-line