Usage of jvm monitoring tools jps,jstat,jstack,jmap

Keywords: Java Tomcat jvm Apache

Jps, jstat, jstack and jmap are commonly used tools to analyze problems encountered by tomcat when analyzing jvm in operation and maintenance.

The common problems of tomcat are:

  OOM, lock dead, lock contention, Java consumes too much CPU

  The above tools can be used for analysis.

Fast Entry of Common Analytical Methods in Production:

  # JPS --> View running java processes

  # jstat-gc process PID - > Check the memory usage of the process, the number and time of garbage collection in the younger generation and the older generation

  # jstat -gccause process PID - > View process garbage collection reasons

  # jmap -heap process PID - > View process heap memory usage

  # jstack-l process PID - > View Thread information for analysis of the situation of tomcat dummy death caused by deadlock

jps:java virtual machine process viewing tool

  jps [options] [hostid]

   - m: Output parameters of the incoming main method

   - l: Displays the complete class name of main

   -v: Displays the parameters specified for the jvm virtual machine

  Commonly used combinations:

   #jps -m -l

   #jps -m -l -v  

[gcct1@localhost bin]$ jps -m -l -v
5966 org.apache.catalina.startup.Bootstrap start -Djava.util.logging.config.file=/mnt/tomcat/conf/logging.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djava.endorsed.dirs=/mnt/tomcat/endorsed -Dcatalina.base=/mnt/tomcat -Dcatalina.home=/mnt/tomcat -Djava.io.tmpdir=/mnt/tomcat/temp
7006 sun.tools.jps.Jps -m -l -v -Denv.class.path=.:/usr/java/jdk1.7.0_79/lib/dt.jar:/usr/java/jdk1.7.0_79/lib/tools.jar -Dapplication.home=/usr/java/jdk1.7.0_79 -Xms8m

Jstat: Monitoring of memory usage and garbage collection at runtime of JVM virtual machine

  Jstat - < option > pid:(< Options > is a necessary option)

   - options: See which options are available

   - gc: When using this option, add the java process number after it; example jstat -gc 27564 [1s] (which can also be displayed as many times as possible)

     S0C,S1C: Represents the capacity of the first and second survivors
     S0U,S1U: Represents the used capacity of the first and second survival areas
     EC,EU: Indicates the capacity and usage of the eden region
     OC,OU: Indicates the capacity and usage of the geriatric area.
     PC,PU: Represents the memory capacity and usage of the persistent generation
     YGC,YGT: Represents the number and time-consuming occurrence of the Cenozoic GC
     FGCT,FGCT: Represents the frequency and time-consuming occurrence of Full GC in the elderly
     GCT: Represents the total GC time-consuming

   -gccause:
    LGCC: Reasons for Last GC
    GCC: Reasons for Current GC

[gcct1@localhost bin]$ jstat -gc 5966
 S0C    S1C    S0U    S1U      EC       EU        OC         OU       PC     PU    YGC     YGCT    FGC    FGCT     GCT   
40960.0 36864.0  0.0   36850.3 253952.0 161159.5  109056.0   74574.4   53248.0 45852.6     19    1.672   3      2.193    3.865
[gcct1@localhost bin]$ jstat -gccause 5966
  S0     S1     E      O      P     YGC     YGCT    FGC    FGCT     GCT    LGCC                 GCC                 
  0.00  99.96  63.76  68.38  86.11     19    1.672     3    2.193    3.865 Allocation Failure   No GC

jmap: View heap memory usage, similar to jstat

  - heap: Detailed output heap memory usage
  - histo[:live]: Detailed display of the number of objects in the entire java heap memory, size statistics;
  - histo: Displays all object information
  - histo:live: Shows only surviving object information
  - h: Getting Help Information
   Example: jmap-heap 5966 - > View heap memory usage in detail

[gcct1@localhost bin]$ jmap -heap 5966
Attaching to process ID 5966, please wait...
Debugger attached successfully.
Server compiler detected.
JVM version is 24.79-b02

using thread-local object allocation.
Parallel GC with 2 thread(s)

Heap Configuration:
   MinHeapFreeRatio = 0
   MaxHeapFreeRatio = 100
   MaxHeapSize      = 1019215872 (972.0MB)
   NewSize          = 1310720 (1.25MB)
   MaxNewSize       = 17592186044415 MB
   OldSize          = 5439488 (5.1875MB)
   NewRatio         = 2
   SurvivorRatio    = 8
   PermSize         = 21757952 (20.75MB)
   MaxPermSize      = 85983232 (82.0MB)
   G1HeapRegionSize = 0 (0.0MB)
......

jstack: View thread stack information in a java process

  jstack [options] pid
  - l: long listings (which output complete lock information); jstack -l process number
  -m: Hybrid mode, which outputs java stack and C/C++ stack information

  Thread contention, thread deadlock and other information can be viewed through jstack

Posted by bradleybebad on Tue, 25 Dec 2018 19:18:06 -0800