当前位置:网站首页>Arthas tutorial

Arthas tutorial

2022-07-28 10:09:00 Young--

1. Official website tutorial

 Insert picture description here
2.arthas-idea/ognl To configure
need idea Installing a plug-in arthas-idea

3. Use ognl Call method complex parameters ( You need to configure )
arthas-idea help
 Insert picture description here
1 thread
thread -n 3/ Support one click display of the busiest previous 3 Thread and print stack
thread/ The default in accordance with the CPU Incremental time descending order , Display only the first page of data
thread –all/ Show all matching threads
thread -b/ Find out which threads are currently blocking other threads
thread -i 1000/ Count the recent 1000ms Threads inside CPU Time .
thread -n 3 -i 1000/ List 1000ms The busiest in the world 3 A thread stack
thread –state WAITING/ View threads in the specified state (WAITING/ wait for )

2 memory see JVM Memory information
memory/ see JVM Memory information

3 sysprop View the current JVM System properties of
sysprop/ See all the properties
sysprop java.version/ View individual properties ( Supported by TAB Key auto completion )
sysprop user.country CN/ Modify individual properties ( take user.country Modified into CN)

4 sysenv View the current JVM Environmental attributes of
sysenv/ View all environment variables
sysenv USER/ Look at a single environment variable

5-6 (vmtool,ognl) Complex parameter processing .

@[email protected]("{\"username\":\"y1y1\",\"password\":\"y1\"}",@[email protected])

5 vmtool vmtool utilize JVMTI Interface , Implementation call interface , Query memory objects , mandatory GC And so on
 Insert picture description here
You can get spring Any object of

//vmtool -x 3 --action getInstances --className com.yjx.cloud.user.controller.api.ApiAppUserLoginController  --express 'instances[0].appLogin(@[email protected]("{\"username\":\"y1y1\",\"password\":\"y1\"}",@[email protected]))'  -c 9e89d68

6 ognl perform ognl expression
 Insert picture description here

ognl -x 3 '#[email protected][email protected],#springContext.getBean("apiAppUserLoginController").appLogin(@[email protected]("{\"username\":\"y1y1\",\"password\":\"y1\"}",@[email protected]))' -c 9e89d68

7 watch You can easily observe the call of the specified function . The range that can be observed is : Return value 、 Throw an exception 、 Enter the reference , By writing OGNL Expression to view the corresponding variable . watch See adding some default parameters , such as -x 3 an 3 The layer data

 Insert picture description here

8 trace Method internal call path , And output the time consumption of each node on the method path  Insert picture description here
9 stack Output the call path of the current method to be called
 Insert picture description here

10 monitor Method execution monitoring
 Insert picture description here

Monitoring item explain
timestamp Time stamp
class Java class
method Method ( Construction method 、 Common method )
total Call the number
success Number of successes
fail Number of failures
rt Average RT
fail-rate Failure rate

11 jad Decompile class become java file
 Insert picture description here
12 arthas Hot deployment processing
 Insert picture description here
Save the data copied above to xxx.sh, Then go to the server to execute , Will automatically enter arthas Selection service process , Select the corresponding to class Thermal deployment

Other useful commands
•jad: Decompile a function , Generally, when there is a problem with the online code , See if it is when the code is released , Wrong version selected ; jad Class full name wildcard Function name ( Optional ) --lineNumber( According to the line Numbers )
•sc: View the loaded class information , This command is used when the bytecode is modified by a third party , Particularly useful sc Class full name wildcard Function name wildcard -d( details ) -f( Output class member variable information ) -E( Turn on regular matching )
•dashboard: Real time data panel of current system , Press ctrl+c sign out
•monitor: Method execution monitoring , Like every other 5 Count the execution times of a method in seconds , You can also execute input filter conditions monitor -c 5 -E( Turn on regular matching ) Class full name wildcard Function name wildcard “params[0] <= 2”
•thread: View the current thread information , Look at the stack of threads , Such as thread -n 3
•jvm: View the current JVM Information
•sysprop: View the current JVM System properties of (System Property)
•sysenv: View the current JVM Environmental attributes of (System Environment Variables)
•vmoption: see , to update VM Diagnosis related parameters , Such as vmoption PrintGCDetails
•perfcounter: View the current JVM Of Perf Counter Information
•logger: see logger Information , to update logger level
•mbean: see Mbean Information about , This command can easily view or monitor Mbean Attribute information .
•getstatic: Direct use is recommended ognl command , More flexible . adopt getstatic Command can easily view the static properties of a class .
•ognl: perform ognl expression , Such as calling static functions :ognl ‘@[email protected](“hello”)’
, Get static fields :ognl ‘@[email protected]
•sm: View method information for loaded classes , This command can search out all loaded Class Information method information .
•dump:dump The... Of the class has already been loaded bytecode Go to a specific directory , Such as dump -d /tmp/output java.lang.String
•heapdump:dump java heap, similar jmap Ordered heap dump function .
•classloader: see classloader Inheritance tree of ,urls, Class loading information ,classloader The order will JVM All of the classloader Statistics of the information , And you can show the inheritance tree ,urls etc. .
•mc:Memory Compiler/ Memory compiler , compile .java File generation .class.
•retransform: Load external .class file ,retransform jvm Loaded classes .retransform /tmp/Test.class
, adopt -d Parameter delete external class , adopt –deleteAll Delete all external classes
•redefine: Recommended retransform command ,redefine Command and jad/watch/trace/monitor/tt Waiting for orders to conflict . After execution redefine after , If you execute the above command again , It will put redefine Bytecode reset for . as a result of jdk In itself redefine and Retransform It's a different mechanism , Use both mechanisms to update bytecode , Only the last changes will take effect .
•trace: Method internal call path , And output the time consumption of each node on the method path ,trace Command can actively search class-pattern/method-pattern The corresponding method call path , Render and count all performance overhead and trace call links on the entire call link .
•stack: Output the call path of the current method to be called , A lot of times we know that a method is executed , But this method has a lot of paths to execute , Or you don't even know where this method was implemented , What you need at this time is stack command .
•profiler: Use async-profiler Generate flame chart ,profiler The command supports the generation of flame diagrams of application hotspots . Essentially through continuous sampling , Then the collected sampling results are generated into a flame diagram .
•cat: Print file contents , and linux Inside cat Command similar .
•base64:base64 Encoding conversion , and linux Inside base64 Command similar .
•tee: Similar to traditional tee command , Used to read standard input data , And output its content to a file .tee Instruction data from the standard input device , Output its contents to the standard output device , At the same time save it as a file . Such as :sysprop | tee -a /path/to/logfile | grep java
•auth: Verify the current session , stay attach when , You can specify a password on the command line .

13 Application startup time analysis

 Insert picture description here
 Insert picture description here

start-up arthas Then select the corresponding service

Start by interrupting
 Insert picture description here

profiler start --event cpu --interval 10000000

 Insert picture description here
Let go of idea The breakpoint execution of spring Execute after startup

profiler stop --format html

 Insert picture description here
Will generate a html file , Open it with a browser Analyze
The results are as follows , This diagram is commonly known as flame diagram , It mainly depends on the horizontal axis length of each method , The longer the abscissa is occupied , What it occupies cpu It's the longest , It's very intuitive
 Insert picture description here

14 idea View the current Dump You can see the current occupation cup The long way
 Insert picture description here

原网站

版权声明
本文为[Young--]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/209/202207280942569937.html