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 > Servers >
Share
Shulou(Shulou.com)06/01 Report--
It is believed that many inexperienced people have no idea about how to use the watch command in Arthas. Therefore, this article summarizes the causes and solutions of the problem. Through this article, I hope you can solve this problem.
What is Arthas?
The official website of Arthas introduces itself as follows:
Arthas is Alibaba's open source Java diagnostic tool, which is loved by developers. 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?
Install and start Arthas with one click
Method 1: one-click remote diagnosis of Arthas through Cloud Toolkit
Cloud Toolkit is a free native IDE plug-in released by Aliyun to help developers develop, test, diagnose and deploy applications more efficiently. Through plug-ins, local applications can be deployed to any server with one click, even in the cloud (ECS, EDAS, ACK, ACR, Mini programs Cloud, etc.). There are also built-in tools such as Arthas diagnostics, Dubbo tools, Terminal terminals, file uploads, function calculations and MySQL executors. There are not only mainstream versions of IntelliJ IDEA, but also Eclipse, Pycharm, Maven and other versions.
It is recommended to use the IDEA plug-in to download Cloud Toolkit to use Arthas: http://t.tb.cn/2A5CbHWveOXzI7sFakaCw8
Method 2: download directly
Address: https://github.com/alibaba/arthas.
Curl-O https://alibaba.github.io/arthas/arthas-boot.jar & & java-Dfile.encoding=UTF-8-jar arthas-boot.jar copy the code
Explain the above shell command a little bit. The command is divided into two parts, the first part is to download Arthas, and the second part is to start Arthas.
You may wonder why download files using curl instead of wget? This is because some servers do not have wget pre-installed, but almost all of them are pre-installed with curl. If your server is pre-installed with wget, you can change 'curl' to wget.
If you use wget, the command can be changed to:
# wget command wget https://alibaba.github.io/arthas/arthas-boot.jar & & java-Dfile.encoding=UTF-8-jar arthas-boot.jar to copy the code
Another point that needs to be explained is-Dfile.encoding=UTF-8, this Java setting is to make Arthas output Chinese will not garbled, this can take a look at my previous article caused by Arthas Chinese garbled Java default coding thinking.
Arthas watch command
Watch allows you to easily observe the call to a specified method. The scope of observation is: return values, throw exceptions, input parameters (you can also observe the object itself that executes the function, I don't know why the official introduction didn't say this ", look at the corresponding variables by writing OGNL expressions.
# watch-h # USAGEwatch [- b] [- e] [- x] [- f] [- h] [- n] [- E] [- M] [- s] class-pattern method-pattern express [condition-express] copy code 1. The observation method returns the result returnObj
The way to use it looks complicated, but it's actually very simple. Let's take the simplest example: suppose we look at the contains method of the string in the following code.
Public class App {public static void main (String [] args) throws IOException {String hello = "Hello Arthas"; while (true) {boolean contains = StringUtils.contains (hello, "Arthas"); System.out.println (contains);}} copy the code
You can use the following statement:
# # observe the result returned by contains [arthas@11939] $watch org.apache.commons.lang3.StringUtils contains returnObj-n immediate Press Q or Ctrl+C to abort.# Affect (class-cnt:1, method-cnt:2) cost in 68 ms.# ts=2020-05-02 1614 ts=2020 04; [cost=2.424254ms] result=@Boolean [true] # ts=2020-05-02 16 46 ts=2020 05; [cost=0.21033ms] result=@Boolean [true] # ts=2020-05-02 16:46:06 [cost=0.165514ms] result=@Boolean [true] copy code
-n 3 means only three times, this parameter is very common, otherwise it is easy to be output to scan the screen.
two。 Filter unconcerned calls to condition-express
Obviously, the real case is certainly not as simple as the example above. In the real service code, there must be more than one place where String's contains method is called. We need to filter out extraneous calls.
# # observe the result returned by contains and filter out extraneous calls [arthas@11939] $watch org.apache.commons.lang3.StringUtils contains returnObj 'params [1] = = "Arthas"' # Press Q or Ctrl+C to abort.# Affect (class-cnt:1, method-cnt:2) cost in 29 ms.# ts=2020-05-02 16 result=@Boolean 48 result=@Boolean 50; [cost=0.331109ms] result=@Boolean [true] # ts=2020-05-02 16:48:51 [cost=0.175224ms] result=@Boolean [true] # ts=2020-05-02 16pur48 ts=2020 52; [cost=0.138984ms] result=@Boolean [true] copy code
The input parameter is a method that can easily distinguish between different calls. With the condition-express of params [1] = = "Arthas", we can keep only the function call whose second input parameter is Arthas.
3. At the same time, observe the input parameter and the result [arthas@11939] $watch org.apache.commons.lang3.StringUtils contains {params,returnObj} 'params [1] = "Arthas"' # Press Q or Ctrl+C to abort.# Affect (class-cnt:1, method-cnt:2) cost in 33 ms.# ts=2020-05-02 16 purl 51 result=@ArrayList 27; [cost=0.507486ms] result=@ArrayList [# @ Object [] [isEmpty=false;size=2], # @ Boolean [true], #] copy code
By wrapping the fields, you can observe the fields you want to observe at the same time. You can notice that params is an array, but the details are not printed when printing params, so you can use-x 2 to specify the property traversal depth of the printed object.
Arthas@11939] $watch org.apache.commons.lang3.StringUtils contains {params,returnObj} 'params [1] = "Arthas"'-x cargo Press Q or Ctrl+C to abort.# Affect (class-cnt:1, method-cnt:2) cost in 35 ms.# ts=2020-05-02 16:51:33 [cost=0.391218ms] result=@ArrayList [# @ Object [] [# @ string [Hello Arthas], # @ string [Hello as], #], # @ Boolean [true], #] copy code 4. Let me give you some examples that I actually use.
When Momo is doing dynamic recommendation development, it is often encountered in testing to see whether a user has turned on the corresponding business switch, and it is often necessary to check whether an experimental switch is enabled.
# # check whether user 1234567 of Momo turns on the ElasticSearch switch watch com.momo.Experiment enableElasticSearch returnObj 'target.momoId== "1234567" # ts=2020-05-02 20 target.momoId== 09target.momoId== 46; [cost=24.443527ms] result=@Boolean [true] copy code
I often judge based on the id of the Momo user who entered the parameter, and check the returned result or exception:
# # View the result returned by the process method of MorecControlFlow # # the momoId attribute value of the first parameter of the process method is "123454567" before it takes effect # # the class path and stranger are not real data watch com.momo.MorecControlFlow process returnObj 'params [0] .momoId = "123454567" # ts=2019-03-18 21:09:46 [cost=264.434972ms] result=@Boolean [true] # # View the exception thrown by shuffle of class IMorecShuffler # # the momoId attribute value of the first parameter of the process method is "123454567" before the watch com.momo.plugins.shuffler.IMorecShuffler shuffle throwExp 'params [0] .morecRequest.momoId== "123454567" # ts=2019-03-27 20:54:29 [cost=46.642339ms] result=java.lang.IndexOutOfBoundsException: Index: 12, Size: 11 at java.util.ArrayList.rangeCheckForAdd (ArrayList.java:665) at java.util.ArrayList.add (ArrayList.java:477) at com.momo.plugin.shuffler.RoomShuffler.shuffle (RoomShuffler:45) after reading the above, have you mastered how to use the watch command in Arthas? If you want to learn more skills or want to know more about it, you are welcome to follow the industry information channel, thank you for reading!
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: 242
*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.