【转】JVM统计监控工具-jstat

原文链接 http://www.javaranger.com/archives/575



jstat概要
 
帮助
jstat [ generalOption | outputOptions vmid [interval[s|ms] [count]] ]
 
 
generalOption
通用命令行选项 (-help, -options, or -version)
 
outputOptions
若干个输出选项(output option),可以包括单个statOption,加上其他的-t, -h 或者-J选项。
 
vmid
虚拟机ID(Virtual machine identifier), 代表目标JVM的字符串.vimid的一般语法格式是
[protocol:][//]lvmid[@hostname[:port]/servername]
该语法和URI的语法类似. vmid可以是个数字,也可以由协议+主机名+端口等更复杂的字串组成。
 
interval[s|ms]
采样时间间隔,以秒或者ms为单位,缺省为毫秒,必须是个正整数。设定此参数值后,jstat会在每个采样间隔内输出结果。
 
count
要显示的样本个数,缺省为无穷大,即直到目标JVM进程终结或者jstat进程终结为止,值必须是个正整数。
 
 
描述
jstat命令工具用于显示JVM的性能统计数据,目标虚拟机用vmid标示。
 
VIRTUAL MACHINE IDENTIFIER(VMID)
语法:
 
[protocol:][//]lvmid[@hostname][:port][/servername]
protocol
通讯协议,如果protocol 和hostname都未指定,则采用平台自身的最优本地协议,
如果protocol 未指定但是hostname指定了,则缺省协议为rmi。
 
lvmid
本地虚拟机标识(The local virtual machine identifier for the target JVM),是vmid唯一一个必需指定的参数值。
The lvmid 常常是操作系统目标JVM的进程ID,你可以用jps命令或者ps命令来查看lvmid。
 
hostname
主机名或者IP地址,未指定的话默认为localhost.
 
port
与远程服务器通讯的缺省端口,如果hostname或者protocol都未指定的话,port也不必指定。
对于缺省的rmi协议,port指的是远程主机注册的rmi端口号,缺省为1099。
 
servername
如果protocol指定为本地最优协议(the optimized local protocol ),则该字段可忽略,
对于rmi协议,servername代表的是远程主机中RMI远程对象的名字。
 
参数选项
jstat命令支持两种参数,通用参数(general options)和输出参数(output options)。
通用参数用于显示jstat的基本用法和版本信息,输出参数决定了输出的统计数据的格式和内容。
 
通用选项(GENERAL OPTIONS)
有排他性,指定通用参数的其中一个则不能指定其他参数,包括其他通用参数和输出参数选项。
 
-help
帮助信息
-version
版本信息
-options
显示输出选项参数列表
 
输出选项(OUTPUT OPTIONS)
如果不设定通用选项,则可以设定输出选项。输出选项决定了jstat命令的输出内容和格式,
它可以包含单个statOption,外加其他输出命令(-h, -t 和-J).
statOption 必须放在前面。如jstat -gccapacity -t 1234
 
输出内容被格式化为表格的形式,第一行为每一列的列明。可以使用-h参数来指定每隔多少行显示行名,
如jstat -gcnewcapacity -h 2 31538 250 7表示显示垃圾回收新生代的容量统计,
每两行显示一次列名,采样时间间隔为250ms,共采样7次。
 
使用-t参数显示时间戳,作为第一列输出,列名为Timestamp它表示自从目标JVM启动以来逝去的时间,以秒为单位。
 
使用interval 和 count 参数来决定采样的频度和时间,如上个例子所示。
 
注意: jstat 输出内容格式在以后的版本中可能改变,所以不建议自己写脚本来解析。
 
-statOption
决定jstat 显示的统计信息。
下表列出了可用的选项(同事显示英文方便查看各个缩写的含义)。可以使用 -options查看系统平台上安装了哪些选项。
Option Displays…
class class loader的行为统计。Statistics on the behavior of the class loader.
compiler HotSpt JIT编译器行为统计。Statistics of the behavior of the HotSpot Just-in-Time compiler.
gc 垃圾回收堆的行为统计。Statistics of the behavior of the garbage collected heap.
gccapacity 各个垃圾回收代容量(young,old,perm)和他们相应的空间统计。Statistics of the capacities of the generations and their corresponding spaces.
gccause 垃圾收集统计概述(同-gcutil),附加最近两次垃圾回收事件的原因。Summary of garbage collection statistics (same as -gcutil), with the cause of the last and
current (if applicable) garbage collection events.
gcnew 新生代行为统计。Statistics of the behavior of the new generation.
gcnewcapacity 新生代与其相应的内存空间的统计。Statistics of the sizes of the new generations and its corresponding spaces.
gcold 年老代和永生代行为统计。Statistics of the behavior of the old and permanent generations.
gcoldcapacity 年老代行为统计。Statistics of the sizes of the old generation.
gcpermcapacity 永生代行为统计。Statistics of the sizes of the permanent generation.
gcutil 垃圾回收统计概述。Summary of garbage collection statistics.
printcompilation HotSpot编译方法统计。HotSpot compilation method statistics.
-h n
每隔n个样本 (行),n是正整数,
缺省为0,代表只有第一行为列头。
-t n
第一行输出为时间戳,
它表示自从目标JVM启动以来逝去的时间,以秒为单位。
-JjavaOption
传递javaOption到java启动参数。
比如,-J-Xms48m 设置java启动最小内存为48M。
完整得启动参数清单,请查看:
java – the Java application launcher (Solaris)
java – the Java application launcher (Linux)
java – the Java application launcher (Windows)
 
-class Option
类加载器统计信息。Class Loader Statistics
列名 描述
Loaded 已加载的类个数。
Bytes 已加载类占用字节数(KB为单位)。
Unloaded 卸载的类个数。
Bytes 卸载的类占用字节数(KB为单位)。
Time 加载和卸载操作花费的时间。
-compiler Option
HotSpt JIT编译器行为统计
列名 描述
Compiled 执行过的编译任务个数
Failed 编译失败次数
Invalid 失效的编译任务个数
Time 编译任务执行花费的时间
FailedType 失败的编译任务类型
FailedMethod 上次编译失败的类名和方法
-gc Option
垃圾回收统计
列名 描述
S0C 当前survivor space 0容量。Current survivor space 0 capacity (KB).
S1C survivor space 1容量。Current survivor space 1 capacity (KB).
S0U Survivor space 0 利用情况。Survivor space 0 utilization (KB).
S1U Survivor space 1 利用情况。Survivor space 1 utilization (KB).
EC 当前新生代eden空间容量。Current eden space capacity (KB).
EU 新生代eden空间利用情况。Eden space utilization (KB).
OC 当前年老代空间容量。Current old space capacity (KB).
OU 年老代利用情况。Old space utilization (KB).
PC 当前永生代空间容量。Current permanent space capacity (KB).
PU 永生代空间利用情况。Permanent space utilization (KB).
YGC 新生代GC事件次数。 Number of young generation GC Events.
YGCT 新生代GC耗时。Young generation garbage collection time.
FGC full GC次数。Number of full GC events.
FGCT full gc耗时。Full garbage collection time.
GCT 总GC耗时。Total garbage collection time.
-gccapacity Option
GC内存空间使用统计
列名 描述
NGCMN 最小新生代容量。Minimum new generation capacity (KB).
NGCMX 最大新生代容量。Maximum new generation capacity (KB).
NGC 当前新生代容量。Current new generation capacity (KB).
S0C 当前新生代survivor 0区容量。Current survivor space 0 capacity (KB).
S1C 当前新生代survivor 1区容量。Current survivor space 1 capacity (KB).
EC 当前新生代eden空间容量。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).
PGCMN 最小永生代容量。Minimum permanent generation capacity (KB).
PGCMX 最大永生代容量。Maximum Permanent generation capacity (KB).
PGC 当前永生代容量。Current Permanent generation capacity (KB).
PC 最小永生代空间容量。Current Permanent space capacity (KB).
YGC 新生代GC次数。Number of Young generation GC Events.
FGC Full GC次数。Number of Full GC Events.
-gccause Option
垃圾收集统计概述(同-gcutil),附加最近两次垃圾回收事件的原因。
相对 -gcutil给出的统计数据, gccause新增了以下几列:
 
Garbage Collection Statistics, Including GC Events
列名 描述
LGCC 上次GC原因。Cause of last Garbage Collection.
GCC 本次GC原因。Cause of current Garbage Collection.
-gcnew Option
新生代统计
列名 描述
S0C 当前survivor 0区容量。Current
survivor space 0 capacity (KB).
S1C 当前survivor 1区容量。Current
survivor space 1 capacity (KB).
S0U 当前survivor 0区利用情况。
Survivor space 0 utilization (KB).
S1U 当前survivor 1区利用情况。
Survivor space 1 utilization (KB).
TT 阀值, 用于控制对象在新生代存活的次数。
Tenuring threshold.
MTT 阀值, 用于控制对象在新生代存活的最大次数。Maximum tenuring threshold.
DSS 期望存活大小。
Desired survivor size (KB).
EC 当前eden空间容量。Current eden space capacity (KB).
EU eden空间利用情况。
Eden space utilization (KB).
YGC 年轻代gc次数。Number of young generation GC events.
YGCT 年轻代GC耗时。
Young generation garbage collection time.
note: 若某个age上的survivor space对象的大小如果超过Desired survivor size,则重新计算tenuring threshold,以age和MaxTenuringThreshold的最小值为准
 
-gcnewcapacity Option
新生代空间统计
列名 描述
NGCMN 最小新生代容量。Minimum new generation capacity (KB).
NGCMX 最大新生代容量。Maximum new generation capacity (KB).
NGC 当前新生代容量。Current new generation capacity (KB).
S0CMX 最大survivor 0区容量。Maximum survivor space 0 capacity (KB).
S0C 当前survivor 0区容量。Current survivor space 0 capacity (KB).
S1CMX 最大survivor 1区容量。Maximum
survivor space 1 capacity (KB).
S1C 当前survivor 1区容量。Current survivor space 1 capacity (KB).
ECMX 最大eden区容量。Maximum eden space capacity (KB).
EC 当前eden区容量。Current eden space capacity (KB).
YGC young gc次数。
Number of young generation GC events.
FGC full gc次数。Number of Full GC Events.
-gcold Option
年老代和永久代统计
列名 描述
PC 当前永久代空间容量。Current permanent space capacity (KB).
PU 永久代空间利用情况。Permanent space utilization (KB).
OC 当前年老代空间容量。Current old space capacity (KB).
OU 年老代空间利用情况。
old space utilization (KB).
YGC young gc次数。
Number of young generation GC events.
FGC full gc次数。Number of full GC events.
FGCT full gc耗时。
Full garbage collection time.
GCT gc总耗时。
Total garbage collection time.
-gcoldcapacity Option
年老代统计
列名 描述
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 young gc次数。
Number of young generation GC events.
FGC full gc次数。
Number of full GC events.
FGCT full gc耗时。Full garbage collection time.
GCT 总GC耗时。
Total garbage collection time.
-gcpermcapacity Option
永生代统计
列名 描述
PGCMN Minimum permanent generation capacity (KB).
PGCMX Maximum permanent generation capacity (KB).
PGC Current permanent generation capacity (KB).
PC Current permanent space capacity (KB).
YGC Number of young generation GC events.
FGC Number of full GC events.
FGCT Full garbage collection time.
GCT Total garbage collection time.
-gcutil Option
Summary of Garbage Collection Statistics
列名 描述
S0 survivor 0区利用率。
Survivor space 0 utilization as a percentage of
the space’s current capacity.
S1 survivor 1区利用率。
Survivor space 1 utilization as a percentage of
the space’s current capacity.
E eden区利用率。
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.
P 永生代空间利用率。Permanent space utilization as a percentage of
the space’s current capacity.
YGC young gc次数。
Number of young generation GC events.
YGCT young gc耗时。
Young generation garbage collection time.
FGC full gc次数。
Number of full GC events.
FGCT full gc耗时。
Full garbage collection time.
GCT GC总耗时。
Total garbage collection time.
-printcompilation Option
HotSpot Compiler Method Statistics
列名 描述
Compiled 执行的编译任务次数
Size Number of bytes of bytecode for the method.
Type 编译类型。Compilation type.
Method 类名和方法名。类名使用”/”代替了原命名空间符号”.”
 
范例
 
以下范例代表了针对本地JVM(lvmid 为21891)的一些统计。
 
gcutil 使用范例
 
使用-gcutil展示gc统计信息,每个250ms采样一次,共采样7次。
 
jstat -gcutil 21891 250 7
S0 S1 E O P YGC YGCT FGC FGCT GCT
12.44 0.00 27.20 9.49 96.70 78 0.176 5 0.495 0.672
12.44 0.00 62.16 9.49 96.70 78 0.176 5 0.495 0.672
12.44 0.00 83.97 9.49 96.70 78 0.176 5 0.495 0.672
0.00 7.74 0.00 9.51 96.70 79 0.177 5 0.495 0.673
0.00 7.74 23.37 9.51 96.70 79 0.177 5 0.495 0.673
0.00 7.74 43.82 9.51 96.70 79 0.177 5 0.495 0.673
0.00 7.74 58.11 9.51 96.71 79 0.177 5 0.495 0.673
该范例显示了在第三和第四样本间发生了一次新生代GC,耗时0.001秒。
本次gc将一些对象从eden区(E)移至年老代空间(O),导致年老代空间
利用率从9.49%升至9.51%。在本次gc之前,survivor区利用率为12.44%,gc
之后变为7.44%。
 
重复显示列名
 
本范例展示了利用-h3选项使-gcnew的输出内容每3行显示一次列名。
 
jstat -gcnew -h3 21891 250
S0C S1C S0U S1U TT MTT DSS EC EU YGC YGCT
64.0 64.0 0.0 31.7 31 31 32.0 512.0 178.6 249 0.203
64.0 64.0 0.0 31.7 31 31 32.0 512.0 355.5 249 0.203
64.0 64.0 35.4 0.0 2 31 32.0 512.0 21.9 250 0.204
S0C S1C S0U S1U TT MTT DSS EC EU YGC YGCT
64.0 64.0 35.4 0.0 2 31 32.0 512.0 245.9 250 0.204
64.0 64.0 35.4 0.0 2 31 32.0 512.0 421.1 250 0.204
64.0 64.0 0.0 19.0 31 31 32.0 512.0 84.4 251 0.204
S0C S1C S0U S1U TT MTT DSS EC EU YGC YGCT
64.0 64.0 0.0 19.0 31 31 32.0 512.0 306.7 251 0.204
该范例展示了两次gc操作,第一次young gc发生在第二个样本和第三个样本之间,
持续了0.001秒。这次gc发现了 survivor 0区使用量超过了DSS,于是将对象移到了
老生代,TT从31降到了2.
 
另一次gc发生在第5和第6个样本间,这次gc将TT重设回31.
 
包含时间戳的范例
 
本范例每隔250ms采样一次共采样3次。
-t 选项用于在第一列显示时间戳。
 
jstat -gcoldcapacity -t 21891 250 3
Timestamp OGCMN OGCMX OGC OC YGC FGC FGCT GCT
150.1 1408.0 60544.0 11696.0 11696.0 194 80 2.874 3.799
150.4 1408.0 60544.0 13820.0 13820.0 194 81 2.938 3.863
150.7 1408.0 60544.0 13820.0 13820.0 194 81 2.938 3.863
Timestamp列显示了自从目标JVM启动以来逝去的时间,以
秒为单位。另外,-gcoldcapacity 选项输出显示了年老代容量 (OGC)
和年老代空间占用一直在增长。第81次Full GC之后OGC从11696KB涨到13820KB。
年老代最大容量为60544KB,所以空间还够用。
 
监控远程JVM
 
本范例显示了使用-gcutil 选项监控了系统名字为remote.domain lvmid 为40496的JVM,
每一秒输出一次。
 
jstat -gcutil 40496@remote.domain 1000
… 输出略
lvmid加远程主机名称组成了vmid 40496@remote.domain。vmid采用了
rmi协议连接远程主机缺省的jstatd服务。jstatd服务使用rmiregistry注册了1099端口
 
 
原文地址:https://www.cnblogs.com/ihongyan/p/5042226.html