Common monitoring jvm commands

Keywords: Java jvm

Common monitoring jvm commands

A pure smile

The command involved in this article is jps jstat jmap jstack jinfo

jps

Command format

jps [options] [hostid]
[] optional

options parameter list

  • -l: output the full name of the main class or jar path
  • -q: only LVMID(local virtual machine id) is output, that is, the unique id of the local virtual machine
  • -m: output the parameters passed to main() when the JVM starts
  • -v: the specified JVM parameters are displayed when the output JVM starts

Common jps / jps -l / jps -lmv

jinfo

This command is used to view and adjust the running parameters of the virtual machine in real time. The previous jps -v password can only view and display the specified parameters. If you want to view the values of the specified parameters that are not displayed, you need to use the jinfo password
Command format

jinfo [options] [args] LVMID

options parameter list

  • -flag: outputs the value of the specified args parameter
  • -flags: the args parameter is not required, and the values of all JVM parameters are output
  • -sysprops: output system properties, equivalent to System.getProperties()
[root@VM-0-17-centos ~]# jinfo -flags 14878
JVM version is 25.281-b09
Non-default VM flags: -XX:CICompilerCount=3 -XX:InitialHeapSize=262144000 -XX:MaxHeapSize=4164943872 -XX:MaxNewSize=1388314624 -XX:MinHeapDeltaBytes=524288 -XX:NewSize=87031808 -XX:OldSize=175112192 -XX:+UseCompressedClassPointers -XX:+UseCompressedOops -XX:+UseParallelGC 

jinfo 14878
 Output without any parameters jvm All parameters and attributes

Common jinfo /jinfo -flags / jinfo -sysprops

jstat

Command format

jstat [option] LVMID [interval] [count]
[] optional

[option] : Operating parameters,By command: jstat -options Get operation parameter list
LVMID : Local virtual machine process ID
[interval] : Time interval of continuous output
[count] : Number of consecutive outputs
Operating parametersdescribe
classBehavior statistics of class loader. Statistics on the behavior of the class loader.
compilerHotspot JIT compiler behavior statistics. Statistics of the behavior of the HotSpot Just-in-Time compiler.
gcBehavior statistics of garbage collection heap. Statistics of the behavior of the garbage collected heap.
gccapacityThe capacity of each garbage collection generation (young,old,perm) and their corresponding spatial statistics. Statistics of the capacities of the generations and their corresponding spaces.
gcutilOverview of garbage collection statistics. Summary of garbage collection statistics.
gccauseOverview of garbage collection statistics (the same as -gcutil), with reasons for the last two garbage collection events attached. Summary of garbage collection statistics (same as -gcutil), with the cause of the last and
gcnewNew generation behavior statistics. Statistics of the behavior of the new generation.
gcnewcapacityStatistics of Cenozoic and its corresponding memory space. Statistics of the sizes of the new generations and its corresponding spaces.
gcoldBehavioral statistics of the elderly and immortals. Statistics of the behavior of the old and permanent generations.
gcoldcapacityBehavioral statistics of the elderly. Statistics of the sizes of the old generation.
gcpermcapacity/gcmetacapacityImmortality / meta spatial behavior statistics. Statistics of the sizes of the permanent generation.
printcompilationHotspot compilation method statistics. HotSpot compilation method statistics.

Practical application analysis

class

Monitor class loading, unloading quantity, total space and time spent

[root@VM-0-17-centos ~]# jstat -class 14878
Loaded  Bytes  Unloaded  Bytes     Time   
 18014 32382.1      518   779.2      21.80

Loaded : load class Number of
Bytes : class Byte size
Unloaded : Not loaded class Number of
Bytes : Not loaded class Byte size of
Time : Loading time

compiler

Output the number of JIT compiled methods, time-consuming, etc

[root@VM-0-17-centos ~]# jstat -compiler 14878
Compiled Failed Invalid   Time   FailedType FailedMethod
   22598      3       0    94.82          1 org/springframework/boot/loader/jar/Handler openConnection

Compiled : Number of compilations
Failed : Number of compilation failures
Invalid : Invalid quantity
Time : Compilation time
FailedType : Failure type
FailedMethod : The fully qualified name of the failed method

gc (*)

Garbage collection heap behavior statistics, common commands

[root@VM-0-17-centos ~]# jstat -gc 14878
 S0C    S1C    S0U    S1U      EC       EU        OC         OU       MC     MU      CCSC    CCSU      YGC     YGCT    FGC    FGCT     GCT   
2048.0 2048.0  0.0   1200.4 47616.0  41616.0   300544.0   125257.1  103680.0 96331.0 12800.0 11627.1   2183   16.327   5      0.995   17.322

C Namely Capacity Total capacity, U Namely Used Used capacity,Company: KB
S0C : survivor0 Total capacity of area
S1C : survivor1 Total capacity of area
S0U : survivor0 Used capacity of zone
S1C : survivor1 Used capacity of zone
EC : Eden Total capacity of area
EU : Eden Used capacity of zone
OC : Old Total capacity of area
OU : Old Used capacity of zone
MC :  Method area size
MU :  Method area usage size
CCSC : Compressed class space size
CCSU : Compressed class space usage size
YGC : New generation garbage collection times
YGCT : New generation garbage collection time
FGC : Garbage collection times in old age
FGCT : Old age garbage collection time
GCT : Total waste collection time

gccapacity

The same as - gc, but it also outputs the maximum and minimum space used by each region of the Java heap

[root@VM-0-17-centos ~]# jstat -gccapacity  14878
 NGCMN    NGCMX     NGC     S0C   S1C       EC      OGCMN      OGCMX       OGC         OC          MCMN     MCMX      MC     CCSMN    CCSMX     CCSC    YGC    FGC 
 84992.0 1355776.0  51712.0 2048.0 2048.0  47616.0   171008.0  2711552.0   300544.0   300544.0      0.0 1140736.0 103680.0      0.0 1048576.0  12800.0   2184     5

NGCMN: Cenozoic minimum capacity
NGCMX: Cenozoic maximum capacity
NGC: Current Cenozoic capacity
S0C: Size of the first surviving area
S1C: The size of the second surviving area
EC: The size of Eden Park
OGCMN: Minimum capacity in old age
OGCMX: Old age maximum capacity
OGC: Current generation size
OC:Current generation size
MCMN:Minimum metadata capacity
MCMX: Maximum metadata capacity
MC: Current metadata space size
CCSMN: Minimum compressed class space size
CCSMX: Maximum compressed class space size
CCSC: Current compressed class space size
YGC: Young generation gc frequency
FGC: Old age GC frequency

gcutil

Same as - gc, but the output is the percentage of used space in the total space

[root@VM-0-17-centos ~]# jstat -gcutil  14878
  S0     S1     E      O      M     CCS    YGC     YGCT    FGC    FGCT     GCT   
 76.59   0.00  56.40  41.68  92.91  90.84   2184   16.332     5    0.995   17.327


S0: Current usage ratio of zone 1
S1: Current usage ratio of zone 2
E: Proportion of Eden Park
O: Use proportion in old age
M: Usage ratio of metadata area
CCS: Compression usage ratio
YGC: Garbage collection times of young generation
FGC: Garbage collection times in old age
FGCT: Waste collection in the old age takes time
GCT: Total waste collection time

gcnew

New generation garbage collection statistics

[root@VM-0-17-centos ~]# jstat -gcnew  14878
 S0C    S1C    S0U    S1U   TT MTT  DSS      EC       EU     YGC     YGCT  
2048.0 2048.0    0.0 1648.6 15  15 2048.0  47616.0   3043.1   2185   16.337

S0C: Size of the first surviving area
S1C: The size of the second surviving area
S0U: Use size of the first surviving area
S1U: Use size of the second surviving area
TT:The number of times the object survived in the Cenozoic
MTT:The maximum number of times the object survived in the Cenozoic
DSS:Expected survival area size
EC: The size of Eden Park
EU: Use size of Eden Park
YGC: Garbage collection times of young generation
YGCT: Waste collection time of young generation

gcnewcapacity

New generation memory space statistics

[root@VM-0-17-centos ~]# jstat -gcnewcapacity  14878
  NGCMN      NGCMX       NGC      S0CMX     S0C     S1CMX     S1C       ECMX        EC      YGC   FGC 
   84992.0  1355776.0    51712.0 451584.0   2048.0 451584.0   2048.0  1354752.0    47616.0  2185     5

NGCMN: Cenozoic minimum capacity
NGCMX: Cenozoic maximum capacity
NGC: Current Cenozoic capacity
S0CMX: Maximum 1 zone size
S0C: Current 1 area size
S1CMX: Maximum 2 zone size
S1C: Current 2 area size
ECMX: Maximum Eden Park size
EC: Current Eden Park size
YGC: Garbage collection times of young generation
FGC: Recovery times of old generation

gcold

Old age garbage collection statistics

[root@VM-0-17-centos ~]# jstat -gcold  14878
   MC       MU      CCSC     CCSU       OC          OU       YGC    FGC    FGCT     GCT   
103680.0  96331.0  12800.0  11627.1    300544.0    125257.1   2185     5    0.995   17.332



MC: Current metadata space size
MC: Used metadata space size
CCSC: Current compressed class space size
CCSC: Compressed class space size used
OC: Total space for the elderly generation
OU: Space used by older generation
YGC: Garbage collection times of young generation
FGC: Garbage collection times in old age
FGCT: Waste collection in the old age takes time
GCT: Total waste collection time

gcoldcapacity

Old memory space statistics

[root@VM-0-17-centos ~]# jstat -gcoldcapacity  14878
   OGCMN       OGCMX        OGC         OC       YGC   FGC    FGCT     GCT   
   171008.0   2711552.0    300544.0    300544.0  2185     5    0.995   17.332

OGCMN: Minimum capacity in old age
OGCMX: Old age maximum capacity
OGC: Current generation size
OC: Old age size
YGC: Garbage collection times of young generation
FGC: Garbage collection times in old age
FGCT: Waste collection in the old age takes time
GCT: Total waste collection time

gcpermcapacity/gcmetacapacity

Meta space / immortality space statistics jdk1.8 and later unified into meta space

[root@VM-0-17-centos ~]# jstat -gcmetacapacity  14878
   MCMN       MCMX        MC       CCSMN      CCSMX       CCSC     YGC   FGC    FGCT     GCT   
   0.0  1140736.0   103680.0        0.0  1048576.0    12800.0      2186     5    0.995   17.337

MCMN:Minimum metadata capacity
MCMX: Maximum metadata capacity
MC: Current metadata space size
CCSMN: Minimum compressed class space size
CCSMX: Maximum compressed class space size
CCSC: Current compressed class space size

printcompilation

Statistics of hotspot compilation methods

[root@VM-0-17-centos ~]# jstat -printcompilation  14878
Compiled  Size  Type Method
   22598      5    1 java/util/ResourceBundle$CacheKey getCause

Compiled: Number of compilation tasks executed
Size: The number of bytes of the method bytecode
Type: Compile type
Method: Compile the class name and method name of the method. Class name usage"/" replace "." As space separator. The method name is the method name of the given class. The format is consistent with HotSpot - XX:+PrintComplation option

jmap

It can generate dump files of java programs, view statistics of object samples in the heap, view ClassLoader information, and finalize queues.

usage

[root@VM-0-17-centos ~]# jmap --help
Usage:
    jmap [option] <pid>
        (to connect to running process)
    jmap [option] <executable <core>
        (to connect to a core file)
    jmap [option] [server_id@]<remote server IP or hostname>
        (to connect to remote debug server)

where <option> is one of:
    <none>               to print same info as Solaris pmap
    -heap                to print java heap summary
    -histo[:live]        to print histogram of java object heap; if the "live"
                         suboption is specified, only count live objects
    -clstats             to print class loader statistics
    -finalizerinfo       to print information on objects awaiting finalization
    -dump:<dump-options> to dump java heap in hprof binary format
                         dump-options:
                           live         dump only live objects; if not specified,
                                        all objects in the heap are dumped.
                           format=b     binary format
                           file=<file>  dump heap to <file>
                         Example: jmap -dump:live,format=b,file=heap.bin <pid>
    -F                   force. Use with -dump:<dump-options> <pid> or -histo
                         to force a heap dump or histogram when <pid> does not
                         respond. The "live" suboption is not supported
                         in this mode.
    -h | -help           to print this help message
    -J<flag>             to pass <flag> directly to the runtime system

explain:
empty : View the memory image information of the process,similar Solaris pmap command
clstats: Print class loader information
dump : Generate heap dump snapshot
finalizerinfo : Show in F-Queue Queue waiting Finalizer Thread execution finalizer Object of method
heap : display Java Heap details
histo : Displays statistics for objects in the heap,If you bring it:live modification(jmap -histo:live),Only the currently surviving object information is displayed
permstat : to print permanent generation statistics
F : When-dump Force generation when there is no response dump snapshot

histro

Print the object statistics of the heap, including the number of objects, memory size, etc. (if you bring live, only live objects will be counted)

[root@VM-0-17-centos ~]# jmap -histo:live 14878 | more

 num     #instances         #bytes  class name
----------------------------------------------
   1:        195366       20329280  [C
   2:        194829        4675896  java.lang.String
   3:         17718        3790208  [I
   4:         39602        3484976  java.lang.reflect.Method
   5:         86797        3471880  java.util.LinkedHashMap$Entry
   6:         94630        3028160  java.util.concurrent.ConcurrentHashMap$Node
   7:         51774        2971952  [Ljava.lang.Object;
   8:         75934        2429888  java.util.HashMap$Node
   9:         27548        2334504  [Ljava.util.HashMap$Node;
  10:          9878        2234184  [B
  11:         18447        2038720  java.lang.Class

object type
B  byte
C  char
D  double
F  float
I  int
J  long
Z  boolean
[   Array, such as[I express int[]
[L+Class name other objects

permstat/clstats

Used to print classloader data & print intelligent statistics of classloader in the persistent storage area (meta space) of Java heap memory. For each class loader, its name, activity, address, parent class loader, and the number and size of classes it loads are printed. In addition, the number and size of strings contained are also printed.

[root@VM-0-17-centos ~]# jmap -clstats 14878
Attaching to process ID 14878, please wait...
Debugger attached successfully.
Server compiler detected.
JVM version is 25.281-b09
finding class loader instances ..done.
computing per loader stat ..done.
please wait.. computing liveness.liveness analysis may be inaccurate ...
class_loader	classes	bytes	parent_loader	alive?	type

<bootstrap>	3382	5936799	  null  	live	<internal>
0x00000006cbcb5bc8	1	1474	0x00000006c7d03660	dead	sun/reflect/DelegatingClassLoader@0x00000007c000a0a0
0x00000006caad82a8	1	880	0x00000006c7d03660	dead	sun/reflect/DelegatingClassLoader@0x00000007c000a0a0
0x00000006cbfeabf8	1	880	0x00000006c7d03660	dead	sun/reflect/DelegatingClassLoader@0x00000007c000a0a0
0x00000006cbe883e0	1	880	0x00000006c7d03660	dead	sun/reflect/DelegatingClassLoader@0x00000007c000a0a0
0x00000006cbc2abc8	1	880	0x00000006c7d03660	dead	sun/reflect/DelegatingClassLoader@0x00000007c000a0a0
0x00000006cbeaebe0	1	880	0x00000006c7d03660	dead	sun/reflect/DelegatingClassLoader@0x00000007c000a0a0
0x00000006c8bcd0b0	1	880	0x00000006c7d03660	dead	sun/reflect/DelegatingClassLoader@0x00000007c000a0a0

F

Force mode. If the specified pid does not respond, use the jmap -dump or jmap -histo options. The live sub option is not supported in this mode.

finalizerinfo

Print information about objects waiting to be recycled

[root@VM-0-17-centos ~]# jmap -finalizerinfo 14878
Attaching to process ID 14878, please wait...
Debugger attached successfully.
Server compiler detected.
JVM version is 25.281-b09
Number of objects pending for finalization: 0

You can see the current F-QUEUE There is no waiting in queue Finalizer Thread execution finalizer Method.

heap(*)

Print the summary information of heap, the algorithm used by GC, the configuration of heap and the usage of wise heap, which can be used to judge the current memory usage and garbage collection

[root@VM-0-17-centos ~]# jmap -heap 14878
Attaching to process ID 14878, please wait...
Debugger attached successfully.
Server compiler detected.
JVM version is 25.281-b09

using thread-local object allocation.
Parallel GC with 4 thread(s) # #gc type

Heap Configuration:
   MinHeapFreeRatio         = 0 # The minimum percentage of free heap space. The calculation formula is: HeapFreeRatio =(CurrentFreeHeapSize/CurrentTotalHeapSize) * 100. The range of values is 0 to 100, and the default value is 40. If heapfreeratio < minheapfreeratio, heap expansion is required. The expansion time should be after each garbage collection.
   MaxHeapFreeRatio         = 100 # The maximum percentage of free heap space. The calculation formula is HeapFreeRatio =(CurrentFreeHeapSize/CurrentTotalHeapSize) * 100. The range of values is 0 to 100, and the default value is 70. If heapfreeratio > maxheapfreeratio, it is necessary to shrink the heap. The shrinking time should be after each garbage collection.
   MaxHeapSize              = 4164943872 (3972.0MB) # Maximum heap space size
   NewSize                  = 87031808 (83.0MB) # Cenozoic size
   MaxNewSize               = 1388314624 (1324.0MB) # Maximum Cenozoic size
   OldSize                  = 175112192 (167.0MB) # Old age size
   NewRatio                 = 2 # Proportion of old age: newratio = 2 = > old age: Cenozoic = 2:1 / newratio = 4 > old age: Cenozoic = 4:1 
   SurvivorRatio            = 8 # Proportion of eden area in Cenozoic: default eden: S1: S0 = 8:1:1 survivorratio = 6 = > eden: S1: S0 = 6:1:1
   MetaspaceSize            = 21807104 (20.796875MB) # Meta space size
   CompressedClassSpaceSize = 1073741824 (1024.0MB) # The maximum allowable memory of Compressed Class Space in Metaspace is 1g by default. This part will apply for 1g virtual address mapping from the operating system when the JVM is started, but it does not really use 1G memory of the operating system.
   MaxMetaspaceSize         = 17592186044415 MB # The maximum allowable memory of the total space of the Metaspace is unlimited by default
   G1HeapRegionSize         = 0 (0.0MB) # G1 the size of the area in the garbage collector. The value is a power of 2, ranging from 1 MB to 32 MB; If the G1 collector is used, the java heap heap is divided into 2048 copies (java hopes to divide into 2048 copies, not only 2048 copies), and the size of each is g1heapregionsize (when not set, java will calculate automatically)

Heap Usage:
PS Young Generation
Eden Space:
   capacity = 47185920 (45.0MB)
   used     = 16805224 (16.026710510253906MB)
   free     = 30380696 (28.973289489746094MB)
   35.61491224500868% used
From Space:
   capacity = 2097152 (2.0MB)
   used     = 1245632 (1.18792724609375MB)
   free     = 851520 (0.81207275390625MB)
   59.3963623046875% used
To Space:
   capacity = 2621440 (2.5MB)
   used     = 0 (0.0MB)
   free     = 2621440 (2.5MB)
   0.0% used
PS Old Generation
   capacity = 234881024 (224.0MB)
   used     = 74456592 (71.00733947753906MB)
   free     = 160424432 (152.99266052246094MB)
   31.699705123901367% used

38016 interned Strings occupying 3954528 bytes.

dump

Generate heap dump snapshot

Command format: - dump:live,format=b,file= LVMID
Output dump to a file, format specifies the output format, live indicates that it is a living object, and file specifies the file name

jmap -dump:live,format=b,file=dump.hprof 14878 

xxx.hprof Format files can be used jdk Own tools jvisualvm.exe see,have access to jhat Command view,have access to eclipse of mat Tool View,You can also specify other file formats.

jstack

jstack is used to generate a thread snapshot of the java virtual machine at the current time.
Thread snapshot is a collection of method stacks being executed by each thread in the current java virtual machine. The main purpose of generating thread snapshot is to locate the causes of long-time pause of threads, such as deadlock between threads, dead loop, long wait caused by requesting external resources, etc.
When a thread pauses, you can view the call stack of each thread through jstack to know what the unresponsive thread is doing in the background or waiting for resources.
If a java program crashes and generates a core file, the jstack tool can be used to obtain the information of the java stack and native stack of the core file, so that you can easily know how the Java program crashes and where the problem occurs in the program.
In addition, the jstack tool can also be attached to the running java program to see the information of the java stack and native stack of the running java program at that time. Jstack is very useful if the running java program presents a hung state.

Usage: jstack [option] LVMID

[root@VM-0-17-centos ~]# jstack -help
Usage:
    jstack [-l] <pid>
        (to connect to running process)
    jstack -F [-m] [-l] <pid>
        (to connect to a hung process)
    jstack [-m] [-l] <executable> <core>
        (to connect to a core file)
    jstack [-m] [-l] [server_id@]<remote server IP or hostname>
        (to connect to a remote debug server)

Options:
    -F  to force a thread dump. Use when jstack <pid> does not respond (process is hung)
    -m  to print both java and native frames (mixed mode)
    -l  long listing. Prints additional information about locks
    -h or -help to print this help message

-F : Force the output thread stack when the normal output request is not responded
-l : Keep listening,In addition to the stack, additional information about the lock is displayed
-m : If you call a local method, you can display C/C++Stack of

[root@VM-0-17-centos ~]# jstack 14878 | more


Output result analysis - Reference

Posted by ShadowBlade72 on Wed, 10 Nov 2021 01:45:23 -0800