In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article introduces the relevant knowledge of "what are the Arthas commands of java". In the operation of actual cases, many people will encounter such a dilemma. Next, let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
1. What is Arthas?
Arthas is Alibaba's open source Java diagnostic tool, which is loved by developers (23K as of 2020.9.19 github star). Through Arthas, we can troubleshoot problems online without restarting; dynamically track Java code; and monitor JVM status in real time.
2. What are the characteristics of Arthas
Check the health of the system in real time
View the parameters, return values and exceptions of the function call
Online hot update of code
Solve the class conflict problem in seconds and locate the class loading path
Quickly locate the hot spots of the application and generate the flame diagram
On-line diagnosis, click on web page to diagnose online application
3. What problems can Arthas help us solve
Arthas can help you solve problems like the following when you are at a loss as to what to do:
From which jar package was this class loaded? Why are all kinds of related Exception reported?
Why didn't the code I changed be executed? Is it because I don't have commit? Is the branch wrong?
If you can't debug online if you encounter a problem, can you only republish it by adding a log?
Online encounter a user's data processing problems, but online also can not debug, offline can not be reproduced!
Is there a global perspective to view the health of the system?
Is there any way to monitor the real-time running status of JVM?
How to quickly locate the hot spots of the application and generate a flame map?
4. Installation
Download arthas-boot.jar and start it with java-jar:
Curl-O https://arthas.aliyun.com/arthas-boot.jarjava-jar arthas-boot.jar
The example project in this article runs on docker, so it takes a different approach.
Docker exec-it ${containerId} / bin/bash-c "wget https://arthas.aliyun.com/arthas-boot.jar & & java-jar arthas-boot.jar"
However, in the process of execution, there may be
/ bin/bash: wget: command not found
The solution is as follows
Interpretation of the / bin/bashdocker exec-it ${containerId} / bin/bashapt-get updateapt-get install wget command entering the container 1. Help command related
Help (view command help information)
Will list this order, out of personal habit. Whenever you learn something new, you will get used to looking at the help. Read through when you want to know the detailed usage of specific commands. Take thread as an example, type
Help thread
There will be detailed thread parameters and examples. It feels like this is the essence of this article. After all, you want other orders, directly.
Help command
But for the sake of hydrology, let's introduce a few more types of commands.
2. Jvm correlation
Dashboard (panel that displays current system information such as threads, memory usage, GC, etc., and refreshes the panel every 5 seconds by default)
Note: press ctrl+c to exit the panel
Jvm (view current JVM information such as gc recycling times and time consuming, etc.)
Thread (view current thread information, view thread stack)
A. View the current busiest N threads and print the stack
Thread-n 3
The effect of the above command is the same as what we have entered in the past.
Top-H-p pidprintf'% x\ n'pidjstack pid | grep 'nid'-C5-color
Similar
B, thread-b to find out which threads are currently blocking other threads
Note: currently, only threads blocked by the synchronized keyword can be found. If it is java.util.concurrent.Lock, it is not supported yet.
C, thread-- state, to view the thread in the specified state
3. Log correlation
Logger (view logger information, update logger level)
3.1View logger information 3.2and update logger level dynamically
To modify the log level
Find the classloader hashcode of the current class
Sc-d com.example.springdemo.user.service.impl.UserServiceImpl | grep classLoaderHash
B. Use OGNL to get logger
Ognl-c 31cefde0'@ com.example.springdemo.user.service.impl.UserServiceImpl@log'
You can see from the figure above that com.example.springdemo.user.service.impl.UserServiceImpl@log is actually using logback. If you can see the level=null, it shows that the actual final level comes from root logger.
C. Set the logger level of UserServiceImpl separately to change the log level to warn
Ognl-c 31cefde0'@ com.example.springdemo.user.service.impl.UserServiceImpl@log.setLevel (@ ch.qos.logback.classic.Level@WARN)'
You can see that the log level has been changed to warn
4. Class/classloader related
Jad (decompilation specifies the source code of the loaded class)
Sc (view JVM loaded class information)
Mc (memory compiler, compiling .java files to generate .class)
Redefine (load external .class files, redefine jvm loaded classes)
Why to introduce these, because these can be combined to achieve dynamic online update code. The steps are as follows
A, jad decompiles the code to be updated
Jad-- source-only com.example.springdemo.user.service.impl.UserServiceImpl > / tmp/UserServiceImpl.java
B. Sc finds the ClassLoader that loads the code to be updated
Sc-d com.example.springdemo.user.service.impl.UserServiceImpl | grep classLoaderHash
C. After saving / tmp/UserServiceImpl.java, use the mc (Memory Compiler) command to compile and specify ClassLoader with the-- classLoaderClass parameter
Mc-- classLoaderClass org.springframework.boot.loader.LaunchedURLClassLoader / tmp/UserServiceImpl.java-d / tmp
Use the redefine command to reload the newly compiled UserServiceImpl.class
Redefine / tmp/com/example/springdemo/user/service/impl/UserServiceImpl.class5, monitoring related
Monitor (method execution monitoring, which can monitor the number of calls, successes, failures, average response time, failure rate of the method)
Note: this is a non-real-time return command. The statistical period is 120 seconds by default.
Monitor-c 5 com.example.springdemo.user.service.impl.UserServiceImpl getUserById
Watch (observe the call to the specified method. The observed range is: return value, throw exception, input parameter)
Watch com.example.springdemo.user.service.impl.UserServiceImpl getUserById "{params,returnObj}"-x 2
Watch parameter description
Trace (call path within the method and output time on each node on the method path)
Note: trace can easily help you locate and find performance defects caused by high RT, but it can only track the call link of the first-level method at a time.
Trace com.example.springdemo.user.service.impl.UserServiceImpl getUserById
Stack (outputs the calling path where the current method is called)
Stack com.example.springdemo.user.service.impl.UserServiceImpl getUserById
Tt (the method executes the time-space tunnel of the data, records the input parameters and return information of each call of the specified method, and can observe these different time calls)
The power of this command is that it records the scene of each call to the current method and can be replayed.
Tt-t com.example.springdemo.user.service.impl.UserServiceImpl getUserById
B. Select an index for playback
Tt-I 1000-p
Note: these monitoring commands are implemented through bytecode enhancement technology, and some aspects are inserted into the methods of specified classes to achieve data statistics and observation, so when online and pre-sent, please try to specify the classes, methods and conditions that need to be observed, and execute stop or enhanced classes to execute reset commands at the end of diagnosis.
This is the end of the content of "what are the Arthas commands of java". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.