文章目录

  • 一、简介
  • 二、常用命令
  • 1、jstat -class pid : class loader行为统计
  • 2、jstat -compiler pid : JIT编译器行为统计
  • 3、jstat -gc pid 5000 20 : 垃圾回收堆行为统计
  • 4、jstat -gccapacity pid 5000 20 : 堆内存统计
  • 5、jstat -gcutil pid 5000 20 : 总结垃圾回收统计
  • 6、jstat -gccause pid 5000 20 : 垃圾收集统计概述
  • 7、jstat -gcnew pid 5000 20 : 新生代垃圾回收统计
  • 8、jstat -gcnewcapacity pid 5000 20 : 新生代内存统计
  • 9、jstat -gcold pid 5000 20 : 老年代垃圾回收统计
  • 10、jstat -gcoldcapacity pid 5000 20 : 老年代内存统计
  • 11、jstat -gcmetacapacity pid 5000 20 : 元数据空间统计
  • 12、jstat -printcompilation pid : 编译方法统计


一、简介

jstat(JVM statistics Monitoring)命令主要是 对java应用程序的资源和性能进行实时的命令行监控,包括了对 heap size垃圾回收状况

jstat

输出结果:

root@yzh-zabbix-server:bin #jstat
invalid argument count
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.

命令格式:

jstat [option] vmid [interval] [count]

参数说明:

参数

说明

option

操作参数,我们经常使用的选项有gc、gccapacity、gcnew、gcnewcapacity、gcold、gcoldcapacity、gcmetacapacity、gcutil等。

vmid

java进程ID

interval

间隔时间,单位为毫秒。

count

打印次数。

option参数总览:

参数

说明

class

class loader的行为统计。

compiler

HotSpot JIT编译器行为统计。

gc

垃圾回收堆的行为统计。

gccapacity

各个垃圾回收代容量(young、old、perm)和他们相应的空间统计。

gcutil

垃圾回收统计概述。

gccause

垃圾收集器概述。

gcnew

新生代行为统计。

gcnewcapacity

新生代与其相应的内存空间的统计。

gcold

老年代和永久代行为统计。

gcoldcapacity

老年代行为统计

gcmetacapacity

元数据区行为统计。

printcompilation

HotSpot编译方法统计。


二、常用命令

1、jstat -class pid : class loader行为统计

监视类装载、卸载数量、总空间以及耗费的时间

jstat -class pid

输出结果:

Loaded  Bytes  Unloaded  Bytes     Time
  4995 10540.4        0     0.0       5.22

字段说明:

字段

说明

Loaded

加载class的数量。

Bytes

class字节大小。

Unloaded

未加载class的数量。

Bytes

未加载class的字节大小。

Time

加载时间。


2、jstat -compiler pid : JIT编译器行为统计

输出JIT编译过的方法数量耗时等。

jstat -compiler pid

输出结果:

Compiled Failed Invalid   Time   FailedType FailedMethod
    3641      1       0    16.62          1 com/cloudwise/agent/deps/asm/ClassReader accept

字段说明:

字段

说明

Compiled

编译数量。

Failed

编译失败数量。

Invalid

无效数量。

Time

编译耗时。

FailedType

失败类型。

FailedMethod

失败方法的全限定名。


3、jstat -gc pid 5000 20 : 垃圾回收堆行为统计

5秒钟打印一次,一共打印20次。

jstat -gc pid 5000 20

输出结果:

root@yzh-zabbix-server:bin #jstat -gc 3111 5000 20
 S0C    S1C      S0U    S1U      EC       EU        OC         OU       MC     MU      CCSC   CCSU     YGC     YGCT  FGC    FGCT     GCT   
14336.0 24576.0  0.0    0.0   50688.0  50687.9   330752.0   330634.8  55296.0 53462.8 6400.0 5925.3    178    2.226  2483   438.892  441.117
14336.0 24576.0  0.0    0.0   50688.0  50688.0   330752.0   330607.2  55296.0 53467.9 6400.0 5925.3    178    2.226  2511   443.944  446.169
14336.0 24576.0  0.0    0.0   50688.0  50686.3   330752.0   330591.4  55296.0 53467.9 6400.0 5925.3    178    2.226  2541   449.050  451.275
14336.0 24576.0  0.0    0.0   50688.0  50687.9   330752.0   330603.5  55296.0 53467.9 6400.0 5925.3    178    2.226  2569   454.029  456.255
14336.0 24576.0  0.0    0.0   50688.0  50688.0   330752.0   330607.6  55296.0 53467.9 6400.0 5925.3    178    2.226  2598   458.971  461.197

CCapacity 总容量,UUsed 已使用的容量。

字段说明:

字段

说明

S0C

年轻代第一个Survivor区的大小(单位:KB)

S1C

年轻代第二个Survivor区的大小(单位:KB)

S0U

年轻代第一个Survivor区的使用大小(单位:KB)

S1U

年轻代第二个Survivor区的使用大小(单位:KB)

EC

年轻代中Eden区的大小(单位:KB)

EU

年轻代中Eden区的使用大小(单位:KB)

OC

老年代大小(单位:KB)

OU

老年代使用大小(单位:KB)

MC

方法区大小(单位:KB)

MU

方法区使用大小(单位:KB)

CCSC

压缩类空间大小(单位:KB)

CCSU

压缩类空间使用大小(单位:KB)

YGC

年轻代垃圾回收次数

YGCT

年轻代垃圾回收消耗时间

FGC

老年代垃圾回收次数

FGCT

老年代垃圾回收消耗时间

GCT

垃圾回收消耗总时间


4、jstat -gccapacity pid 5000 20 : 堆内存统计

5秒钟打印一次,一共打印20次。

-gc ,不过还会输出 Java 堆各区域使用到的最大、最小空间。

jstat -gccapacity pid 5000 20

输出结果:

root@yzh-zabbix-server:bin #jstat -gccapacity 3111 5000 20
 NGCMN    NGCMX     NGC     S0C      S1C       EC      OGCMN      OGCMX       OGC         OC       MCMN     MCMX       MC     CCSMN    CCSMX      CCSC    YGC    FGC 
 10752.0 164864.0 110080.0 14336.0 24576.0  50688.0    22016.0   330752.0   330752.0   330752.0     0.0   1097728.0  55296.0   0.0    1048576.0   6400.0  178    7491
 10752.0 164864.0 110080.0 14336.0 24576.0  50688.0    22016.0   330752.0   330752.0   330752.0     0.0   1097728.0  55296.0   0.0    1048576.0   6400.0  178    7520
 10752.0 164864.0 110080.0 14336.0 24576.0  50688.0    22016.0   330752.0   330752.0   330752.0     0.0   1097728.0  55296.0   0.0    1048576.0   6400.0  178    7547

字段说明:

字段

说明

NGCMN

新生代最小容量

NGCMX

新生代最大容量

NGC

当前新生代容量

S0C

第一个Survivor区大小

S1C

第二个Survivor区的大小

EC

Eden区的大小

OGCMN

老年代最小容量

OGCMX

老年代最大容量

OGC

当前老年代大小

OC

当前老年代大小

MCMN

最小元数据容量

MCMX

最大元数据容量

MC

当前元数据空间大小

CCSMN

最小压缩类空间大小

CCSMX

最大压缩类空间大小

CCSC

当前压缩类空间大小

YGC

年轻代gc次数

FGC

老年代GC次数


5、jstat -gcutil pid 5000 20 : 总结垃圾回收统计

5秒钟打印一次,一共打印20次。

-gc ,不过输出的是已使用空间占总空间的百分比

jstat -gcutil pid 5000 20

输出结果:

root@yzh-zabbix-server:bin #jstat -gcutil 3111 5000 20
  S0     S1     E      O      M     CCS    YGC     YGCT    FGC    FGCT     GCT   
  0.00   0.00 100.00  99.95  96.75  92.57  178    2.226   10172  1772.566 1774.791
  0.00   0.00 100.00  99.95  96.75  92.57  178    2.226   10203  1777.589 1779.814
  0.00   0.00 100.00  99.95  96.75  92.57  178    2.226   10234  1782.580 1784.806

字段说明:

字段

说明

S0

第一个Servivor区当前使用比例

S1

第二个Servivor区当前使用比例

E

Eden区使用比例

O

老年代使用比例

M

元数据区使用比例

CCS

压缩使用比例

YGC

年轻代垃圾回收次数

FGC

老年代垃圾回收次数

FGCT

老年代垃圾回收消耗时间

GCT

垃圾回收消耗总时间


6、jstat -gccause pid 5000 20 : 垃圾收集统计概述

5秒钟打印一次,一共打印20次。

-gcutil ,附加最近两次垃圾回收事件的原因。

jstat -gccause pid 5000 20

输出结果:

S0     S1     E      O      M     CCS    YGC     YGCT    FGC    FGCT     GCT    LGCC                 GCC
0.00   0.00  35.78  19.43  97.96  95.19     20    0.176    11    0.406    0.582 Heap Inspection Initiated GC No GC

字段说明:

字段

说明

S0

第一个Servivor区当前使用比例

S1

第二个Servivor区当前使用比例

E

Eden区使用比例

O

老年代使用比例

M

元数据区使用比例

CCS

压缩使用比例

YGC

年轻代垃圾回收次数

FGC

老年代垃圾回收次数

FGCT

老年代垃圾回收消耗时间

GCT

垃圾回收消耗总时间

LGCC

最近垃圾回收的原因

GCC

当前垃圾回收的原因


7、jstat -gcnew pid 5000 20 : 新生代垃圾回收统计

5秒钟打印一次,一共打印20次。

jstat -gcnew pid 5000 20

输出结果:

root@yzh-zabbix-server:bin #jstat -gcnew 3111 5000 20
 S0C       S1C      S0U    S1U  TT  MTT    DSS      EC       EU       YGC     YGCT  
14336.0  24576.0    0.0    0.0  12  15   24576.0  50688.0  50688.0    178    2.226
14336.0  24576.0    0.0    0.0  12  15   24576.0  50688.0  50688.0    178    2.226
14336.0  24576.0    0.0    0.0  12  15   24576.0  50688.0  50688.0    178    2.226

字段说明:

字段

说明

S0C

第一个Survivor区大小

S1C

第二个Survivor区的大小

S0U

第一个Survivor区的使用大小

S1U

第二个Survivor区的使用大小

TT

对象在新生代存活的次数

MTT

对象在新生代存活的最大次数

DSS

期望的Survivor区大小

EC

Eden区的大小

EU

Eden区的使用大小

YGC

年轻代垃圾回收次数

YGCT

年轻代垃圾回收消耗时间


8、jstat -gcnewcapacity pid 5000 20 : 新生代内存统计

5秒钟打印一次,一共打印20次。

jstat -gcnewcapacity pid 5000 20

输出结果:

root@yzh-zabbix-server:bin #jstat -gcnewcapacity 3111 5000 20
  NGCMN      NGCMX       NGC      S0CMX     S0C     S1CMX     S1C       ECMX        EC      YGC   FGC 
   10752.0   164864.0   110080.0  54784.0  14336.0  54784.0  24576.0   163840.0    50688.0   178 14824
   10752.0   164864.0   110080.0  54784.0  14336.0  54784.0  24576.0   163840.0    50688.0   178 14850
   10752.0   164864.0   110080.0  54784.0  14336.0  54784.0  24576.0   163840.0    50688.0   178 14878

字段说明:

字段

说明

NGCMN

新生代最小容量

NGCMX

新生代最大容量

NGC

当前新生代容量

S0CMX

第一个Survivor区最大大小

S0C

第一个Survivor区当前大小

S1CMX

第二个Survivor区最大大小

S1C

第二个Survivor区当前大小

ECMX

Eden区最大大小

EC

Eden区当前大小

YGC

年轻代垃圾回收次数

FGC

老年代回收次数


9、jstat -gcold pid 5000 20 : 老年代垃圾回收统计

5秒钟打印一次,一共打印20次。

jstat -gcold pid 5000 20

输出结果:

root@yzh-zabbix-server:bin #jstat -gcold 3111 5000 20
   MC       MU      CCSC     CCSU       OC          OU       YGC    FGC    FGCT     GCT   
 55552.0  53550.5   6400.0   5924.5    330752.0    330602.1    178 16635 2895.316 2897.541
 55552.0  53550.5   6400.0   5924.5    330752.0    330601.3    178 16665 2900.278 2902.504
 55552.0  53550.5   6400.0   5924.5    330752.0    330604.3    178 16693 2905.210 2907.435

字段说明:

字段

说明

MC

方法区大小

MU

方法区使用大小

CCSC

压缩类空间大小

CCSU

压缩类空间使用大小

OC

老年代大小

OU

老年代使用大小

YGC

年轻代垃圾回收次数

FGC

老年代垃圾回收次数

FGCT

老年代垃圾回收消耗时间

GCT

垃圾回收消耗总时间


10、jstat -gcoldcapacity pid 5000 20 : 老年代内存统计

5秒钟打印一次,一共打印20次。

jstat -gcoldcapacity pid 5000 20

输出结果:

root@yzh-zabbix-server:bin #jstat -gcoldcapacity 3111 5000 20
   OGCMN       OGCMX        OGC         OC       YGC   FGC    FGCT     GCT   
    22016.0    330752.0    330752.0    330752.0   178 17810 3099.915 3102.140
    22016.0    330752.0    330752.0    330752.0   178 17840 3104.912 3107.137
    22016.0    330752.0    330752.0    330752.0   178 17870 3109.847 3112.073

字段说明:

字段

说明

OGCMN

老年代最小容量

OGCMX

老年代最大容量

OGC

当前老年代大小

OC

老年代大小

YGC

年轻代垃圾回收次数

FGC

老年代垃圾回收次数

FGCT

老年代垃圾回收消耗时间

GCT

垃圾回收消耗总时间


11、jstat -gcmetacapacity pid 5000 20 : 元数据空间统计

5秒钟打印一次,一共打印20次。

jstat -gcmetacapacity pid 5000 20

输出结果:

root@yzh-zabbix-server:bin #jstat -gcmetacapacity 3111 5000 20
   MCMN       MCMX        MC       CCSMN      CCSMX       CCSC     YGC   FGC    FGCT     GCT   
    0.0     1097728.0    55552.0    0.0     1048576.0     6400.0   178  18795  3270.543 3272.768
    0.0     1097728.0    55552.0    0.0     1048576.0     6400.0   178  18824  3275.425 3277.650
    0.0     1097728.0    55552.0    0.0     1048576.0     6400.0   178  18853  3280.369 3282.595

字段说明:

字段

说明

MCMN

最小元数据容量

MCMX

最大元数据容量

MC

当前元数据空间大小

CCSMN

最小压缩类空间大小

CCSMX

最大压缩类空间大小

CCSC

当前压缩类空间大小

YGC

年轻代垃圾回收次数

FGC

老年代垃圾回收次数

FGCT

老年代垃圾回收消耗时间

GCT

垃圾回收消耗总时间


12、jstat -printcompilation pid : 编译方法统计

jstat -printcompilation -pid

输出结果:

Compiled  Size  Type Method
   3745      8    1  java/lang/Long toString

字段说明:

字段

说明

Compiled

被执行的编译任务的数量

Size

方法字节码的字节数

Type

编译类型

Method

编译方法的类名和方法名。类名使用"/" 代替 “.” 作为空间分隔符. 方法名是给出类的方法名. 格式是一致于HotSpot - XX:+PrintComplation 选项