命令环境:ubuntu1~16.04.5
JDK :java version “1.8.0_152”
一、序言
jstat 命令是JDK自带的一个轻量级小工具。全称“Java Virtual Machine statistics monitoring tool”,位于java的bin目录下,主要利用JVM内建的指令对Java应用程序的资源和性能进行实时命令行的监控,可以查看堆内存各部分的使用量,以及加载类的数量,包括了对Heap size和垃圾回收状况的监控。
二、命令介绍
jstat的主要命令是:
jstat -<option> [-t] [-h<lines>] <vmid> [<interval> [<count>]]
我们查看这些命令选项的英文解释:
bingsanlang@ubuntu:~$ jstat -help
Usage: jstat -help|-options
jstat -<option> [-t] [-h<lines>] <vmid> [<interval> [<count>]]
Definitions:
<option> An option reported by the -options option
<vmid> Virtual Machine Identifier. A vmid takes the following form:
<lvmid>[@<hostname>[:<port>]]
Where <lvmid> is the local vm identifier for the target
Java virtual machine, typically a process id; <hostname> is
the name of the host running the target Java virtual machine;
and <port> is the port number for the rmiregistry on the
target host. See the jvmstat documentation for a more complete
description of the Virtual Machine Identifier.
<lines> Number of samples between header lines.
<interval> Sampling interval. The following forms are allowed:
<n>["ms"|"s"]
Where <n> is an integer and the suffix specifies the units as
milliseconds("ms") or seconds("s"). The default units are "ms".
<count> Number of samples to take before terminating.
-J<flag> Pass <flag> directly to the runtime system.
一项项来看各项参数
2.1 -<option>
jstat -<option> [-t] [-h<lines>] <vmid> [<interval> [<count>]]
options 有如下选项:
bingsanlang@ubuntu:~$ jstat -options
-class //Displays statistics about the behavior of the class loader.
-compiler //Displays statistics about the behavior of the Java HotSpot VM Just-in-Time compiler.
-gc //Displays statistics about the behavior of the garbage collected heap.
-gccapacity //Displays statistics about the capacities of the generations and their corresponding spaces.
-gccause //Displays a summary about garbage collection statistics (same as -gcutil), with the cause of the last and current (when applicable) garbage collection events.
-gcmetacapacity //Displays statistics about the sizes of the metaspace.
-gcnew //Displays statistics of the behavior of the new generation.
-gcnewcapacity //Displays statistics about the sizes of the new generations and its corresponding spaces.
-gcold //Displays statistics about the behavior of the old generation and metaspace statistics.
-gcoldcapacity //Displays statistics about the sizes of the old generation.
-gcutil //Displays a summary about garbage collection statistics.
-printcompilation //Displays Java HotSpot VM compilation method statistics.
2.1.1 -class 是显示ClassLoad的相关信息,查看类的加载情况。
bingsanlang@ubuntu:~$ jstat -class 16723
Loaded Bytes Unloaded Bytes Time
7698 15838.2 19 23.3 12.13
指标名称 | 解释 | 英文解释 |
---|---|---|
Loaded | 加载的class类个数 | Number of classes loaded. |
Bytes | 加载的类占用的空间 | Number of Kbytes loaded. |
Unloaded | 卸载的class类个数 | Number of classes unloaded. |
Bytes | 卸载的类占用的空间 | Number of Kbytes unloaded. |
Time | 加载和卸载class类花费的时间 | Time spent performing class load and unload operations. |
2.1.2 -compiler 是显示JIT编译器的编译行为
bingsanlang@ubuntu:~$ jstat -compiler 16723
Compiled Failed Invalid Time FailedType FailedMethod
5130 0 0 47.31
指标名称 | 解释 | 英文解释 |
---|---|---|
Compiled | 执行的编译任务数。 | Number of compilation tasks performed. |
Failed | 执行的编译任务失败数。 | Number of compilations tasks failed. |
Invalid | 执行的编译任务不合法数 | Number of compilation tasks that were invalidated. |
Time | 编译任务花费的时间 | Time spent performing compilation tasks. |
FailedType | 最近失败的编译类型 | Compile type of the last failed compilation. |
FailedMethod | 最近失败的类名称和方法名称 | Class name and method of the last failed compilation. |
2.1.3 -gc 垃圾收集器的堆统计
bingsanlang@ubuntu:~$ jstat -gc 16723
S0C S1C S0U S1U EC EU OC OU MC MU CCSC CCSU YGC YGCT FGC FGCT GCT
2368.0 2368.0 0.0 50.7 19392.0 10961.6 48124.0 31522.2 48512.0 47661.6 5760.0 5499.1 327 9.003 4 1.545 10.547
指标名称 | 解释 | 英文解释 |
---|---|---|
S0C | 幸存区1的容量大小 | Current survivor space 0 capacity (kB). |
S1C | 幸存区2的容量大小 | Current survivor space 1 capacity (kB). |
S0U | 幸存区1的使用大小 | Survivor space 0 utilization (kB). |
S1U | 幸存区2的使用大小 | Survivor space 1 utilization (kB). |
EC | 伊甸园区的容量大小 | Current eden space capacity (kB). |
EU | 伊甸园区的使用大小 | Eden space utilization (kB). |
OC | 老年代的容量大小 | Current old space capacity (kB). |
OU | 老年代的使用大小 | Old space utilization (kB). |
MC | 元数据区的容量大小 | Metaspace capacity (kB). |
MU | 元数据区的使用大小 | Metacspace utilization (kB). |
CCSC | 指针压缩的容量大小 | Compressed class space capacity (kB). |
CCSU 指针压缩的使用大小 | Compressed class space used (kB). | |
YGC | 年轻代垃圾回收次数 | Number of young generation garbage collection events. |
YGCT | 年轻代垃圾回收时间 | Young generation garbage collection time. |
FGC | 老年代的垃圾回收次数 | Number of full GC events. |
FGCT | 老年代的回收消费时间 | Full garbage collection time. |
GCT | 垃圾回收消费的总时间 | Total garbage collection time. |
2.1.4 -gccapacity 内存分代情况和空间容量
Memory pool generation and space capacities.
bingsanlang@ubuntu:~$ jstat -gccapacity 16723
NGCMN NGCMX NGC S0C S1C EC OGCMN OGCMX OGC OC MCMN MCMX MC CCSMN CCSMX CCSC YGC FGC
6144.0 96256.0 24128.0 2368.0 2368.0 19392.0 12288.0 192512.0 48124.0 48124.0 0.0 1091584.0 48512.0 0.0 1048576.0 5760.0 327 4
指标名称 | 解释 | 英文解释 |
---|---|---|
NGCMN | 新生代的最小容量 | Minimum new generation capacity (kB). |
NGCMX | 新生代的最大容量 | Maximum new generation capacity (kB). |
NGC | 当前新生代的容量 | Current new generation capacity (kB). |
S0C | 幸存区1的当前容量 | Current survivor space 0 capacity (kB). |
S1C | 幸存区2的当前容量 | Current survivor space 1 capacity (kB). |
EC | 伊甸园区的当前容量 | Current eden space capacity (kB). |
OGCMN | 老年代的最小容量 | Minimum old generation capacity (kB). |
OGCMX | 老年代的最大容量 | Maximum old generation capacity (kB). |
OGC | 老年代的容量 | Current old generation capacity (kB). |
OC | 当前老年代的容量 | Current old space capacity (kB). |
MCMN | 元空间的最小容量 | Minimum metaspace capacity (kB). |
MCMX | 元空间的最大容量 | Maximum metaspace capacity (kB). |
MC | 当前元空间的容量 | Metaspace capacity (kB). |
CCSMN | 压缩类的最小容量 | Compressed class space minimum capacity (kB). |
CCSMX | 压缩类的最大容量 | Compressed class space maximum capacity (kB). |
CCSC | 当前压缩类的容量 | Compressed class space capacity (kB). |
YGC | 年轻代的GC次数 | Number of young generation GC events. |
FGC | 老年代的GC次数 | Number of full GC events. |
2.1.5 -gccause 垃圾回收的统计情况
This option displays the same summary of garbage collection statistics as the -gcutil option, but includes the causes of the last garbage collection event and (when applicable) the current garbage collection event. In addition to the columns listed for -gcutil, this option adds the following columns.
bingsanlang@ubuntu:~$ jstat -gccause 16723
S0 S1 E O M CCS YGC YGCT FGC FGCT GCT LGCC GCC
0.00 2.14 82.26 65.50 98.25 95.47 327 9.003 4 1.545 10.547 Allocation Failure No GC
指标名称 | 解释 | 英文解释 |
---|---|---|
S0 | 幸存区1的大小 | |
S1 | 幸存区2的大小 | |
E | 伊甸园区的大小 | |
O | 老年代的大小 | |
M | 元空间的大小 | |
CCS | 压缩类的大小 | |
YGC | 新生代的GC次数 | |
YGCT新生代的GC时间 | ||
FGC | 老年代的GC次数 | |
FGCT | 老年的GC时间 | |
GCT | GC的总耗时 | |
LGCC | 最近一次GC的原因 | Cause of last garbage collection |
GCC | 当前GC的原因 | Cause of current garbage collection |
2.1.6 -gcmetacapacity 元数据的空间统计情况
Metaspace size statistics.
bingsanlang@ubuntu:~$ jstat -gcmetacapacity 16723
MCMN MCMX MC CCSMN CCSMX CCSC YGC FGC FGCT GCT
0.0 1091584.0 48512.0 0.0 1048576.0 5760.0 327 4 1.545 10.547
指标名称 | 解释 | 英文解释 |
---|---|---|
MCMN | 元空间的最小空间 | Minimum metaspace capacity (kB). |
MCMX | 元空间的最大空间 | Maximum metaspace capacity (kB). |
MC | 元空间的容量 | Metaspace capacity (kB). |
CCSMN | 压缩空间的最小空间 | Compressed class space minimum capacity (kB). |
CCSMX | 压缩空间的最大容量 | Compressed class space maximum capacity (kB). |
YGC | 新生代的GC次数 | Number of young generation GC events. |
FGC | 老年代的GC次数 | Number of full GC events. |
FGCT | 新生代的GC时间 | Full garbage collection time. |
GCT | 老年代的GC时间 | Total garbage collection time. |
2.1.7 -gcnew 新生代的情况
New generation statistics.
bingsanlang@ubuntu:~$ jstat -gcnew 16723
S0C S1C S0U S1U TT MTT DSS EC EU YGC YGCT
2368.0 2368.0 0.0 50.7 15 15 1184.0 19392.0 19113.4 327 9.003
指标名称 | 解释 | 英文解释 |
---|---|---|
S0C | 当前幸存区1的容量大小 | Current survivor space 0 capacity (kB). |
S1C | 当前幸存区2的容量大小 | Current survivor space 1 capacity (kB). |
S0U | 当前幸存区1的使用大小 | Survivor space 0 utilization (kB). |
S1U | 当前幸存区2的使用大小 | Survivor space 1 utilization (kB). |
TT | 对象转换到老年代的生存阈值 | Tenuring threshold. |
MTT | 对象转换到老年代的最大生存阈值 | Maximum tenuring threshold. |
DSS | 需要的幸存区大小 | Desired survivor size (kB). |
EC | 伊甸园的容量大小 | Current eden space capacity (kB). |
EU | 伊甸园的当前使用大小 | Eden space utilization (kB). |
YGC | 新生代的GC次数 | Number of young generation GC events. |
YGCT | 新生代的GC时间 | Young generation garbage collection time. |
2.1.8 -gcnewcapacity 新生代的空间大小统计情况
New generation space size statistics.
wanghanbing@ubuntu:~$ jstat -gcnewcapacity 16723
NGCMN NGCMX NGC S0CMX S0C S1CMX S1C ECMX EC YGC FGC
6144.0 96256.0 24128.0 9600.0 2368.0 9600.0 2368.0 77056.0 19392.0 328 4
指标名称 | 解释 | 英文解释 |
---|---|---|
NGCMN | 新生代的最小容量大小 | Minimum new generation capacity (kB). |
NGCMX | 新生代的最大容量大小 | Maximum new generation capacity (kB). |
NGC | 当前新生代的大小 | Current new generation capacity (kB). |
S0CMX | 幸存区1的最大容量 | Maximum survivor space 0 capacity (kB). |
S0C | 当前幸存区1的容量 | Current survivor space 0 capacity (kB). |
S1CMX | 幸存区2的最大容量 | Maximum survivor space 1 capacity (kB). |
S1C | 当前幸存区1的容量 | Current survivor space 1 capacity (kB). |
ECMX | 伊甸园的最大容量大小 | Maximum eden space capacity (kB). |
EC | 当前伊甸园的容量大小 | Current eden space capacity (kB). |
YGC | 新生代的GC次数 | Number of young generation GC events. |
FGC | 老年代的GC次数 | Number of full GC events. |
2.1.9 -gcold 老年代统计情况
Old generation and metaspace behavior statistics.
bingsanlang@ubuntu:~$ jstat -gcold 16723
MC MU CCSC CCSU OC OU YGC FGC FGCT GCT
48512.0 47661.6 5760.0 5499.1 48124.0 31522.2 328 4 1.545 10.550
指标名称 | 解释 | 英文解释 |
---|---|---|
MC | 元空间容量大小 | Metaspace capacity (kB). |
MU | 元空间使用的大小 | Metaspace utilization (kB). |
CCSC | 压缩空间的容量大小 | Compressed class space capacity (kB). |
CCSU | 压缩空间的使用大小 | Compressed class space used (kB). |
OC | 当前老年代的大小 | Current old space capacity (kB). |
OU | 老年代的使用大小 | Old space utilization (kB). |
YGC | 新生代的GC次数 | Number of young generation GC events. |
FGC | 老年代的GC次数 | Number of full GC events. |
FGCT | 老年代GC的时间 | Full garbage collection time. |
GCT | GC的总时间 | Total garbage collection time. |
2.1.10 -gcoldcapacity 老年代的空间统计情况
Old generation size statistics.
bingsanlang@ubuntu:~$ jstat -gcoldcapacity 16723
OGCMN OGCMX OGC OC YGC FGC FGCT GCT
12288.0 192512.0 48124.0 48124.0 328 4 1.545 10.550
指标名称 | 解释 | 英文解释 |
---|---|---|
OGCMN | 老年代的最小容量大小 | Minimum old generation capacity (kB). |
OGCMX | 老年代的最大容量大小 | Maximum old generation capacity (kB). |
OGC | 当前老年代的大小 | Current old generation capacity (kB). |
OC | 当前老年代的空间容量大小 | Current old space capacity (kB). |
YGC | 新生代的GC次数 | Number of young generation GC events. |
FGC | 老年代的GC次数 | Number of full GC events. |
FGCT | 老年代的GC时间 | Full garbage collection time. |
GCT | GC的总时间 | Total garbage collection time. |
2.1.11 -gcutil 垃圾回收的整体概况
Summary of garbage collection statistics.
bingsanlang@ubuntu:~$ jstat -gcutil 16723
S0 S1 E O M CCS YGC YGCT FGC FGCT GCT
1.59 0.00 48.46 65.50 98.25 95.47 328 9.005 4 1.545 10.550
指标名称 | 解释 | 英文解释 |
---|---|---|
S0 | 幸存区1的大小 | |
S1 | 幸存区2的大小 | |
E | 伊甸园区的大小 | |
O | 老年代的大小 | |
M | 元空间的大小 | |
CCS | 压缩类的大小 | |
YGC | 新生代的GC次数 | |
YGCT新生代的GC时间 | ||
FGC | 老年代的GC次数 | |
FGCT | 老年的GC时间 | |
GCT | GC的总耗时 |
2.1.12 -printcompilation 虚拟机编译方法统计
Java HotSpot VM compiler method statistics.
bingsanlang@ubuntu:~$ jstat -printcompilation 16723
Compiled Size Type Method
5130 105 1 java/util/Formatter$FormatSpecifier justify
指标名称 | 解释 | 英文解释 |
---|---|---|
Compiled | Number of compilation tasks performed by the most recently compiled method. | |
Size | Number of bytes of byte code of the most recently compiled method. | |
Type | Compilation type of the most recently compiled method. | |
Method | Class name and method name identifying the most recently compiled method. Class name uses slash (/) instead of dot (.) as a name space separator. Method name is the method within the specified class. The format for these two fields is consistent with the HotSpot -XX:+PrintCompilation option. |
2.2 [-t]
jstat -<option> [-t] [-h<lines>] <vmid> [<interval> [<count>]]
Displays a timestamp column as the first column of output. The time stamp is the time since the start time of the target JVM.
在输出的第一列增加一列时间戳,这个时间戳是自从JVM启动的时间开始计算的。
bingsanlang@ubuntu:~$ jstat -class -t 16723
Timestamp Loaded Bytes Unloaded Bytes Time
1219513.8 7698 15838.2 19 23.3 12.13
2.3 [-h]
jstat -<option> [-t] [-h<lines>] <vmid> [<interval> [<count>]]
Displays a column header every n samples (output rows), where n is a positive integer. Default value is 0, which displays the column header the first row of data.
bingsanlang@ubuntu:~$ jstat -printcompilation -h3 16723 2000
Compiled Size Type Method
5130 105 1 java/util/Formatter$FormatSpecifier justify
5130 105 1 java/util/Formatter$FormatSpecifier justify
5130 105 1 java/util/Formatter$FormatSpecifier justify
Compiled Size Type Method
5130 105 1 java/util/Formatter$FormatSpecifier justify
5130 105 1 java/util/Formatter$FormatSpecifier justify
这个参数是每输出多少行数据,就打印titile。
2.4 <vmid>
jstat -<option> [-t] [-h<lines>] <vmid> [<interval> [<count>]]
Virtual machine identifier, which is a string that indicates the target JVM. The general syntax is the following:
[protocol:][//]lvmid[@hostname[:port]/servername]
The syntax of the vmid string corresponds to the syntax of a URI. The vmid string can vary from a simple integer that represents a local JVM to a more complex construction that specifies a communications protocol, port number, and other implementation-specific values. See Virtual Machine Identifier.
2.5 interval [s|ms]
Sampling interval in the specified units, seconds (s) or milliseconds (ms). Default units are milliseconds. Must be a positive integer. When specified, the jstat command produces its output at each interval.
jstat -<option> [-t] [-h<lines>] <vmid> [<interval> [<count>]]
2.6 count
Number of samples to display. The default value is infinity which causes the jstat command to display statistics until the target JVM terminates or the jstat command is terminated. This value must be a positive integer.
jstat -<option> [-t] [-h<lines>] <vmid> [<interval> [<count>]]
参考:
https://docs.oracle.com/javase/8/docs/technotes/tools/unix/jstat.html#BEHHGFAE