1 Introduction
Arthas is Alibaba open source Java diagnostic tools, loved by developers
When you encounter the following problems similar helpless, Arthas can help you solve:
- The class from which jar package loaded? Why would report a variety of categories associated Exception?
- I changed the code to execute Why not? Could it be I did not commit? Branch made a mistake?
- Get stuck online debug, it only re-released by adding the log it?
- Online encounter a user's data processing problems, but the same can not be online debug, the line can not reproduce!
- Is there a global perspective to view the health of the system?
- Is there any way to run real-time status monitoring of the JVM?
Arthas support JDK 6+, support Linux / Mac / Winodws, a command-line interactive mode, while providing a wealth of Tab Completion features to further facilitate problem diagnosis and localization
2 Key Features
Arthas provides functionality can be divided into the following three aspects:
- (1) Information Monitoring
- Basic information of running processes: memory, CPU usage, thread information, thread stack, the number of threads statistics, the environment variable information
- Object information: static property class object, Mbean attribute information, class information has been loaded, the class loader, class method information
- (2) method call
- Method calls into the parameters, return values View
- Method is called the call path, calling time-consuming method the number of calls, the number of successes, failures and other statistics
- Recording and redo method calls
- (3) Class File
- dump loaded class bytecode, the bytecode decompile, compile the class, the class loading reheated
3 Installation and use
3.1 Installation
Download arthas-boot.jar, then start with java -jar way:
wget https://alibaba.github.io/arthas/arthas-boot.jar
java -jar arthas-boot.jar
复制代码
Then enter the number corresponding to the process into Arthas's command interface can be used:
Print help information:
java -jar arthas-boot.jar -h
复制代码
3.2
Here are some commonly used commands and usage and principles of Arthas, and see how we actually solve problems in the command details can refer to the official documents of Arthas
(1) the entire dashboard data
In arthas command line interface, enter the dashboard command, will immediately show the current state of multithreading tomcat, the information JVM regional, GC and other circumstances
(2) View thread monitor
Enter the thread command displays the status of all threads of information input thread -n 3 shows the current busiest three threads, the thread can be used to troubleshoot CPU consumption input thread -b will show threads currently BLOCKED state, you can troubleshoot a thread lock The problem
(3) JVM monitoring
Enter the command jvm, jvm to view detailed performance data
(4) observation method parameters, return values
Sometimes we need to see the troubleshooting parameters, return values, the usual need to add log printing, more complicated, based on the watch command we can easily do it all
$ watch demo.MathGame primeFactors "{params,returnObj}" -x 2
Press Ctrl+C to abort.
Affect(class-cnt:1 , method-cnt:1) cost in 44 ms.
ts=2018-12-03 19:16:51; [cost=1.280502ms] result=@ArrayList[
@Object[][
@Integer[535629513],
],
@ArrayList[
@Integer[3],
@Integer[19],
@Integer[191],
@Integer[49199],
],
]
复制代码
(5) observation method call path, time-consuming details
Sometimes encounter service Caton, which is time-consuming steps in the end want to troubleshoot relatively long, the usual practice is to add a log, use the command trace can easily solve this problem:
$ trace demo.MathGame run
Press Ctrl+C to abort.
Affect(class-cnt:1 , method-cnt:1) cost in 42 ms.
`---ts=2018-12-04 00:44:17;thread_name=main;id=1;is_daemon=false;priority=5;TCCL=sun.misc.Launcher$AppClassLoader@3d4eac69
`---[10.611029ms] demo.MathGame:run()
+---[0.05638ms] java.util.Random:nextInt()
+---[10.036885ms] demo.MathGame:primeFactors()
`---[0.170316ms] demo.MathGame:print()
复制代码
4 The principle
The overall macro-block call is as follows:
Space reasons, the following comparison of its two core principles involved are simple introduction:
(1) monitoring information, class File
JMX JDK provided (Java Management Extensions Java Management Extensions, is an application framework for the implantation of management functions), JMX MBean Management a series of objects, Arthas is based on these MBean objects implement memory, GC, class loading information, JVM information monitoring
(2) method call
After the JDK5, introduced java.lang.Instrument, programmers implementing dynamic modification class code via bytecode modification method. In the process parameters in the proxy class, there are instances Instrumentation inst. With this example, we can call a variety of interfaces Instrumentation provides. For example, calling inst.getAllLoadedClasses () to get all the classes have been loaded. Call inst.addTransformer (new SdlTransformer (), true) new converter. Call inst.retransformClasses (Class cls), re-launched the conversion request to the JVM
Arthas bytecode class after generating an enhanced ASM, enhancements include a method call into parameters, return value to see, methods called method calls record and redo, and then increase the conversion based method Instrumentation interface provided by the JDK
5 real case
Arthas official document provides a number of user cases, here are some of the more interesting case:
(1) investigation and application log sources Strange Case Details
Services applications that run sometimes there will be some strange log, these logs to troubleshoot locate the source of much trouble to print by modifying the code that implements the StringBuilder call stack information in the log, the compiler generates StringBuilder.clss, then modify applications based redefine commands Arthas provided the actual bytecode StringBuilder
(2) to troubleshoot problems SpringBoot application 401/404 Case Details
Page Views returned 401/404, when confronted with this problem, usually a headache, especially trace commands provided by Arthas when the online environment, print out a full page when the access request tree, locate specific Servlet which returns 404
$ trace javax.servlet.Servlet *
Press Ctrl+C to abort.
Affect(class-cnt:7 , method-cnt:185) cost in 1018 ms.
复制代码
By trace command, trace the object is positioned exactly which javax.servlet.Filter Filter intercept request targeting the source of the problem 401 return
$ trace javax.servlet.Filter *
Press Ctrl+C to abort.
Affect(class-cnt:13 , method-cnt:75) cost in 278 ms.
复制代码
(3) lines of code hot update case details
Sometimes in order to verify the steps to resolve quickly fix the problem online program, or for a quick test, we need to update the code Arthas heat are as follows
- Step 1 jad command codes decompile
- Step 2 text editor to modify the code
- Step 3 sc command to find where the ClassLoader class code
- Step 4 mc command specifies the compiled code ClassLoader
- Step 5 redefine hot update command Code
reference
6 to fly the Java diagnostic tools Arthas
Decryption Ali online problem diagnosis tools Arthas and jvm-sandbox
1 Introduction
Arthas is Alibaba open source Java diagnostic tools, loved by developers
When you encounter the following problems similar helpless, Arthas can help you solve:
- The class from which jar package loaded? Why would report a variety of categories associated Exception?
- I changed the code to execute Why not? Could it be I did not commit? Branch made a mistake?
- Get stuck online debug, it only re-released by adding the log it?
- Online encounter a user's data processing problems, but the same can not be online debug, the line can not reproduce!
- Is there a global perspective to view the health of the system?
- Is there any way to run real-time status monitoring of the JVM?
Arthas support JDK 6+, support Linux / Mac / Winodws, a command-line interactive mode, while providing a wealth of Tab Completion features to further facilitate problem diagnosis and localization
2 Key Features
Arthas provides functionality can be divided into the following three aspects:
- (1) Information Monitoring
- Basic information of running processes: memory, CPU usage, thread information, thread stack, the number of threads statistics, the environment variable information
- Object information: static property class object, Mbean attribute information, class information has been loaded, the class loader, class method information
- (2) method call
- Method calls into the parameters, return values View
- Method is called the call path, calling time-consuming method the number of calls, the number of successes, failures and other statistics
- Recording and redo method calls
- (3) Class File
- dump loaded class bytecode, the bytecode decompile, compile the class, the class loading reheated
3 Installation and use
3.1 Installation
Download arthas-boot.jar, then start with java -jar way:
wget https://alibaba.github.io/arthas/arthas-boot.jar
java -jar arthas-boot.jar
复制代码
Then enter the number corresponding to the process into Arthas's command interface can be used:
Print help information:
java -jar arthas-boot.jar -h
复制代码
3.2
Here are some commonly used commands and usage and principles of Arthas, and see how we actually solve problems in the command details can refer to the official documents of Arthas
(1) the entire dashboard data
In arthas command line interface, enter the dashboard command, will immediately show the current state of multithreading tomcat, the information JVM regional, GC and other circumstances
(2) View thread monitor
Enter the thread command displays the status of all threads of information input thread -n 3 shows the current busiest three threads, the thread can be used to troubleshoot CPU consumption input thread -b will show threads currently BLOCKED state, you can troubleshoot a thread lock The problem
(3) JVM monitoring
Enter the command jvm, jvm to view detailed performance data
(4) observation method parameters, return values
Sometimes we need to see the troubleshooting parameters, return values, the usual need to add log printing, more complicated, based on the watch command we can easily do it all
$ watch demo.MathGame primeFactors "{params,returnObj}" -x 2
Press Ctrl+C to abort.
Affect(class-cnt:1 , method-cnt:1) cost in 44 ms.
ts=2018-12-03 19:16:51; [cost=1.280502ms] result=@ArrayList[
@Object[][
@Integer[535629513],
],
@ArrayList[
@Integer[3],
@Integer[19],
@Integer[191],
@Integer[49199],
],
]
复制代码
(5) observation method call path, time-consuming details
Sometimes encounter service Caton, which is time-consuming steps in the end want to troubleshoot relatively long, the usual practice is to add a log, use the command trace can easily solve this problem:
$ trace demo.MathGame run
Press Ctrl+C to abort.
Affect(class-cnt:1 , method-cnt:1) cost in 42 ms.
`---ts=2018-12-04 00:44:17;thread_name=main;id=1;is_daemon=false;priority=5;TCCL=sun.misc.Launcher$AppClassLoader@3d4eac69
`---[10.611029ms] demo.MathGame:run()
+---[0.05638ms] java.util.Random:nextInt()
+---[10.036885ms] demo.MathGame:primeFactors()
`---[0.170316ms] demo.MathGame:print()
复制代码
4 The principle
The overall macro-block call is as follows:
Space reasons, the following comparison of its two core principles involved are simple introduction:
(1) monitoring information, class File
JMX JDK provided (Java Management Extensions Java Management Extensions, is an application framework for the implantation of management functions), JMX MBean Management a series of objects, Arthas is based on these MBean objects implement memory, GC, class loading information, JVM information monitoring
(2) method call
After the JDK5, introduced java.lang.Instrument, programmers implementing dynamic modification class code via bytecode modification method. In the process parameters in the proxy class, there are instances Instrumentation inst. With this example, we can call a variety of interfaces Instrumentation provides. For example, calling inst.getAllLoadedClasses () to get all the classes have been loaded. Call inst.addTransformer (new SdlTransformer (), true) new converter. Call inst.retransformClasses (Class cls), re-launched the conversion request to the JVM
Arthas bytecode class after generating an enhanced ASM, enhancements include a method call into parameters, return value to see, methods called method calls record and redo, and then increase the conversion based method Instrumentation interface provided by the JDK
5 real case
Arthas official document provides a number of user cases, here are some of the more interesting case:
(1) investigation and application log sources Strange Case Details
Services applications that run sometimes there will be some strange log, these logs to troubleshoot locate the source of much trouble to print by modifying the code that implements the StringBuilder call stack information in the log, the compiler generates StringBuilder.clss, then modify applications based redefine commands Arthas provided the actual bytecode StringBuilder
(2) to troubleshoot problems SpringBoot application 401/404 Case Details
Page Views returned 401/404, when confronted with this problem, usually a headache, especially trace commands provided by Arthas when the online environment, print out a full page when the access request tree, locate specific Servlet which returns 404
$ trace javax.servlet.Servlet *
Press Ctrl+C to abort.
Affect(class-cnt:7 , method-cnt:185) cost in 1018 ms.
复制代码
By trace command, trace the object is positioned exactly which javax.servlet.Filter Filter intercept request targeting the source of the problem 401 return
$ trace javax.servlet.Filter *
Press Ctrl+C to abort.
Affect(class-cnt:13 , method-cnt:75) cost in 278 ms.
复制代码
(3) lines of code hot update case details
Sometimes in order to verify the steps to resolve quickly fix the problem online program, or for a quick test, we need to update the code Arthas heat are as follows
- Step 1 jad command codes decompile
- Step 2 text editor to modify the code
- Step 3 sc command to find where the ClassLoader class code
- Step 4 mc command specifies the compiled code ClassLoader
- Step 5 redefine hot update command Code
reference
6 to fly the Java diagnostic tools Arthas
Decryption Ali online problem diagnosis tools Arthas and jvm-sandbox