jstat介绍
Monitors Java Virtual Machine (JVM) statistics.
官网文档: https://docs.oracle.com/javase/8/docs/technotes/tools/unix/jstat.html
jstat 用法
# 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.
统计gc情况
jstat -gc java进程ID
# jstat -gc 19567
S0C S1C S0U S1U EC EU OC OU MC MU CCSC CCSU YGC YGCT FGC FGCT GCT
5120.0 5120.0 3734.0 0.0 338944.0 149348.4 699392.0 87674.3 105624.0 99251.1 11952.0 10845.5 1180 17.213 5 1.359 18.572
参数介绍:
S0C:第一个幸存区的大小
S1C:第二个幸存区的大小
S0U:第一个幸存区的使用大小
S1U:第二个幸存区的使用大小
EC:伊甸园区的大小
EU:伊甸园区的使用大小
OC:老年代大小
OU:老年代使用大小
MC:方法区大小
MU:方法区使用大小
CCSC:压缩类空间大小
CCSU:压缩类空间使用大小
YGC:年轻代垃圾回收次数
YGCT:年轻代垃圾回收消耗时间
FGC:老年代垃圾回收次数
FGCT:老年代垃圾回收消耗时间
GCT:垃圾回收消耗总时间
计算GC频率
- 查看java进程运行时间(系统运行时间与进程启动之间之差)
ps -eo pid,tty,user,comm,lstart,etime | grep java进程ID
# ps -eo pid,tty,user,comm,lstart,etime | grep 19567
19567 ? root java Fri Mar 12 17:48:21 2021 16-17:28:47
代表已启动16天17小时28份47秒
- 计算频率
16-17:28:47 换算成分钟除以YGC或者FGC 就可以得出频率了
当前gc情况
jstat -gcutil pid time
示例,每秒钟查看当前gc情况
# jstat -gcutil 13798 1000
S0 S1 E O M CCS YGC YGCT FGC FGCT GCT
0.00 96.98 20.00 10.46 94.03 90.71 27 0.312 4 0.712 1.024
0.00 96.98 20.00 10.46 94.03 90.71 27 0.312 4 0.712 1.024
0.00 96.98 20.00 10.46 94.03 90.71 27 0.312 4 0.712 1.024
0.00 96.98 20.00 10.46 94.03 90.71 27 0.312 4 0.712 1.024
0.00 96.98 20.01 10.46 94.03 90.71 27 0.312 4 0.712 1.024
0.00 96.98 20.01 10.46 94.03 90.71 27 0.312 4 0.712 1.024
参数介绍
-gcutil option
Summary of garbage collection statistics.
S0: Survivor space 0 utilization as a percentage of the space’s current capacity.
S1: Survivor space 1 utilization as a percentage of the space’s current capacity.
E: Eden space utilization as a percentage of the space’s current capacity.
O: Old space utilization as a percentage of the space’s current capacity.
M: Metaspace utilization as a percentage of the space’s current capacity.
CCS: Compressed class space utilization as a percentage.
YGC: Number of young generation GC events.
YGCT: Young generation garbage collection time.
FGC: Number of full GC events.
FGCT: Full garbage collection time.
GCT: Total garbage collection time.
还有其他用法,可在文档中查找