当前位置:网站首页>Virtual machine performance monitoring and fault handling tools

Virtual machine performance monitoring and fault handling tools

2022-04-23 19:20:00 Xuanguo Guo

Catalog

Virtual machine performance monitoring 、 Fault handling

One 、 Virtual machine related commands

1、jps: Virtual machine process health tool

2、jstat: Virtual machine statistics monitoring tool

3、jinfo:Java Configuration information tools

4、jmap:Java Memory imaging tools

5、jhat: Virtual machine heap dump snapshot analysis tool

6、jstack:Java Stack trace tool

Two 、 Visual fault handling tool

1、JConsole:Java Monitoring and management console

2、VisualVM: Fault handling collection tools


Virtual machine performance monitoring 、 Fault handling

 

One 、 Virtual machine related commands

1、jps: Virtual machine process health tool

Function and Linux Medium ps Command similar , Available lists the running virtual machine processes , And the only of the process ID
Command format :jps [options] [hostid]

Example :


 

2、jstat: Virtual machine statistics monitoring tool

It is a command tool used to monitor the running status information of virtual machines . Exhibition Java Class loading in process 、 Memory 、 garbage collection 、 Run time data such as instant compilation .
Command format :
jstat [option pid [interval[s|ms]] [count]] 
jstat [- Command options ] [pid] [ Time interval between / millisecond ] [ Query times ]

Common options :
-class: Monitoring class loading 、 Unloading quantity 、 Total space and time spent loading classes
-gc: monitor Java Pile condition , Include Eden District ,2 individual Survivor District , Old age , Permanent equivalent capacity , used space , Total garbage collection time, etc
-gcutil: Monitoring content and -gc Basically the same , Single output mainly focuses on Java The maximum and minimum space used by each area of the heap

Parameters, :
S0C: The first of the young generation survivor( Survival zone ) The capacity of ( byte )
S1C: The second of the younger generation survivor( Survival zone ) The capacity of ( byte )
S0U : The first of the young generation survivor( Survival zone ) Space has been used ( byte )
S1U : The second of the younger generation survivor( Survival zone ) Space has been used ( byte )
EC : Young generation Eden( The garden of Eden ) The capacity of ( byte )
EU : Young generation Eden( The garden of Eden ) Space has been used ( byte )
OC :Old Generation capacity ( byte )
OU :Old Generation has used space at present ( byte )
MC:metaspace( Meta space ) The capacity of ( byte )
MU:metaspace( Meta space ) Space has been used ( byte )
YGC : From application startup to sampling in the younger generation gc frequency
YGCT : From application startup to sampling in the younger generation gc Time spent (s)
FGC : From application startup to sampling old generation ( whole gc)gc frequency
FGCT : From application startup to sampling old generation ( whole gc)gc Time spent (s)
GCT: From application startup to sampling gc The total time spent (s)

Example :

Printing process id yes 6132 Information about , Every time 1000ms Print once , Print 10 Time .

3、jinfo:Java Configuration information tools

It is to view and call various parameters of the virtual machine in real time .
Command format :
jinfo [option] pid

Example :

I am here JpsTest The program added -XX:CMSInitiatingOccupancyFraction=85 Launch parameters

4、jmap:Java Memory imaging tools

Used to generate a heap dump snapshot (dump file ). If not jmap command , It can also be done through -XX:+HeapDumpOnOutMemoryError Parameter to enable the virtual machine to automatically generate a heap dump snapshot file after the memory overflow exception occurs .
Command format :jmap [option] pid

Common options :
-dump: Generate Java Heap dump snapshot . The format is -dump:[live,]format=b,file=<filename>, among live The sub parameter indicates whether only dump Out of the living . example :jmap -dump:format=b,file=dumpFile.bin <pid>
-heap: Show Java Heap details . notes : Only in linux、Solaris Effective under platform .
-histo: Show statistics for objects in the heap , Including class 、 Number of instances 、 Aggregate capacity

Example :

5、jhat: Virtual machine heap dump snapshot analysis tool

And jamp Use it with , It's used to analyze jmap Generated heap dump snapshot .jhat Built in a small server , After generating the analysis results of the heap dump snapshot , It can be viewed directly in the browser .
Command format :jhat <filename>
Screen display "Server is ready." Then enter... In the browser ,http://localhost:7000/ You can see the analysis results .
notes : There is one saying. , The result is not very intuitive . I usually use more jamp Medium -histo, It looks more intuitive .

Example :

6、jstack:Java Stack trace tool

Used to generate the current Java Thread snapshot of the current time of the process . Thread snapshot is a collection of method stacks being executed by all threads in the current virtual machine . It is often used to check thread deadlock , Dead cycle , Thread blocking for a long time .
Command format :
jstack [option] pid

Common options :
-l: In addition to stack information , Additional information about the lock is also displayed . You can also output to the corresponding file , example :jstack -l <pid> > stack.log
-F: When the normal output request is not reflected , This option can force the output of thread stack information .

Because of me linux The server is not running Java Program , So the examples are all in window Upper .
In addition to some of the above , There are many other tools .
Such as :jar( Create and manage jar file ),java(Java Run the tool ),javac(Java compiler ),javap( Bytecode analysis tool ) wait .
Interested partners can have an in-depth understanding of a wave of , By the way, share a wave with me .

Example :

stack.log In file , Related thread information can also be printed

 

Two 、 Visual fault handling tool

1、JConsole:Java Monitoring and management console

Is based on JMX Visual monitoring of 、 Management tools . The main function is through JMX Of MBean Collect information and adjust parameters dynamically .
The tool is installed before we jdk Of bin Under the table of contents , You can see that there is a jconsole.exe file .
Open the tool , When we have Java Program runtime , He will automatically detect this machine Java process , Then we choose the corresponding process , You can enter the visual interface to view the corresponding information .
Mainly memory 、 Threads 、 Number of class loads 、VM Summary 、MBean A few chunks of information . If you are interested, you can run one on your computer Java Program , Then order a little by yourself , Have a look .
Memory monitoring : Equivalent to what we introduced before jstat The command is visualized . Used to monitor the change trend of virtual machine memory managed by the collector .
Thread monitoring : Equivalent to what we introduced before jstack The command is visualized . For monitoring Java Process thread running status . It's also very considerate to have a special button to detect deadlock .

2、VisualVM: Fault handling collection tools

It is one of the powerful operation monitoring and fault handling programs . In addition to regular operation monitoring 、 Troubleshooting , There are also tools such as performance analysis .
function :
 1) Show Java Process and related configuration environment information of the process , amount to jps,jinfo.
 2) Monitor the application's processor , garbage collection , Pile up , Thread and other information , amount to jstas,jstack
 3)dump And analyze heap dump snapshot , amount to jmap,jhat
 4) Analysis of program performance
 5) You can install plug-ins , More functions can be expanded


  Offline official plug-in address :https://visualvm.github.io/pluginscenters.html
  On-line java visualvm Installing a plug-in . Pictured :

stay Profiler Page , You can view method level processor execution time analysis and memory analysis during runtime .

Btrace Dynamic log tracking , This is a VisualVM Plug in for , It's very powerful . You can do this without interrupting the target program , adopt HotSpot The virtual machine allows you to follow the code function of newly loaded classes without downtime , Dynamically add debugging code that does not exist .
When the program has abnormal problems , You can use this plug-in , To add some debugging log code , And it's different to stop the service .

JMC(Java Mission Control): Sustainable online monitoring tools

Used for remote monitoring and management JVM The virtual machine .
You need to add the following parameters when the service process at the remote end starts :
-Dcom.sun.management.jmxremote.port=9999 
-Dcom.sun.management.jmxremote.ssl=false 
-Dcom.sun.management.jmxremote.authenticate=false 
-Djava.rmi.server.hostname=192.168.31.31

-XX:+UnlockCommercialFeatures -XX:+FlightRecorder

And then in VisualVM In the tools , choice " file "->" Add remote host ", Fill in the address and port we configured, and connect to the interface . Subsequent operations are consistent locally .

 

In our usual development process ,Linux Servers are used more , Therefore, compared with the visual interface , Personally, I think the relevant virtual machine commands should be used more .

 

版权声明
本文为[Xuanguo Guo]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204210558503349.html