jvm监控工具之jstat篇

1.jstat用于输出指定 java 进程的统计信息

用法:
Jstat : jstat -<option> [-t] [-h<lines>] <vmid> [<interval> [<count>]]
其中的<option>为必须提供的选项,所有的可用选项可使用jstat -options列出

[root@VM_82_178_redhat ~]# jstat -options
-class
-compiler
-gc
-gccapacity
-gccause
-gcmetacapacity
-gcnew
-gcnewcapacity
-gcold
-gcoldcapacity
-gcutil
-printcompilation

2.常用选项(附带每个选项的输出列名介绍)

class:统计classloader的行为
compiler:统计hotspot just-in-time编译器的行为
gc:统计gc行为
gccapacity:统计堆中代的容量、空间
gccause:垃圾收集统计,包括最近引用垃圾收集的事件,基本同gcutil,比gcutil多了两列
gcnew:统计新生代的行为
gcnewcapacity:统计新生代的大小和空间
gcold:统计旧生代的行为
gcoldcapacity:统计旧生代的大小和空间
gcpermcapacity:统计永久代的大小和空间
gcutil:垃圾收集统计
printcompilation:hotspot编译方法统计
-h n 每n个样本,显示header一次
-t n 在第一列显示时间戳列,时间戳时从jvm启动开始计算
<vmid> 就是进程号
<interval> interval是监控时间间隔,单位为微妙,不提供就意味着单次输出
<count> count是最大输出次数,不提供且监控时间间隔有值的话, 就无限打印

3.具体参数使用介绍

1.class选项:

#jstat -class 4214 2000 10 (每隔2秒监控一次,一共做10次)

Loaded Bytes Unloaded Bytes  Time 
9197   18418.   0 0    0.0  12.49 
9197   18418.   0 0    0.0  12.49
列名介绍:
Column  Description
Loaded  被读入类的数量
Bytes   被读入的字节数(K)
Unloaded    被卸载类的数量
Bytes   被卸载的字节数(K)
Time    花费在load和unload类的时间

2.选项-compiler

[root@tomcat01 test001]# jstat -compiler  13614
Compiled Failed Invalid   Time   FailedType FailedMethod
3463      2       0    70.23          1 org/apache/tomcat/util/IntrospectionUtils setProperty

3.GC选项:

[root@tomcat01 test001]# jstat -gc 13614 2000 10     
 S0C    S1C    S0U    S1U      EC       EU        OC         OU       PC     PU    YGC     YGCT    FGC    FGCT     GCT   
69888.0 69888.0  0.0   440.5  559232.0 392816.0 1398144.0   200682.0  131072.0 91892.5    665    5.352   0      0.000    5.352
69888.0 69888.0  0.0   440.5  559232.0 392816.0 1398144.0   200682.0  131072.0 91892.5    665    5.352   0      0.000    5.352

列名介绍:

Column  Description
S0C 当前S0的容量 (KB)
S1C 当前S1的容量 (KB)
S0U S0已使用 (KB)
S1U S1已使用 (KB)
EC  当前eden的容量(KB)
EU  Eden已使用 (KB)
OC  当前old的容量(KB)
OU  Old已使用 (KB)
PC  当前perm的容量 (KB)
PU  Perm已使用 (KB)
YGC young代gc的次数
YGCT    young代gc花费的时间
FGC full gc的次数
FGCT    full gc的时间
GCT 垃圾收集收集的总时间

4.gccapacity选项:
每隔两秒统计一次新生代,一共统计5次

[root@tomcat01 test001]# jstat -gccapacity  13614 2000 5
 NGCMN    NGCMX     NGC     S0C   S1C       EC      OGCMN      OGCMX       OGC         OC      PGCMN    PGCMX     PGC       PC     YGC    FGC 
699008.0 699008.0 699008.0 69888.0 69888.0 559232.0  1398144.0  1398144.0  1398144.0  1398144.0 131072.0 262144.0 131072.0 131072.0    699     0
列名介绍:
Column  Description
NGCMN   年轻代的最小容量 (KB)
NGCMX   年轻代的最大容量 (KB)
NGC 当前年轻代的容量 (KB)
S0C 当前S0的空间 (KB)
S1C 当前S1的空间 (KB)
EC  当前eden的空间 (KB)
OGCMN   年老代的最小容量 (KB)
OGCMX   年老代的最大容量 (KB)
OGC 当前年老代的容量 (KB)
OC  当前年老代的空间 (KB)
PGCMN   永久代的最小容量 (KB)
PGCMX   永久代的最大容量 (KB)
PGC 当前永久代的容量 (KB)
PC  当前永久代的空间 (KB)
YGC 年轻代gc的次数
FGC full gc的次数

5.gccause参数:

[root@tomcat01 ~]# jstat -gccause 13614
  S0     S1     E      O      P     YGC     YGCT    FGC    FGCT     GCT    LGCC       GCC                 
  1.63   0.00  33.97  14.39  70.21    726    5.674     0    0.000    5.674 Allocation Failure   No GC

列名介绍:

Column  Description
LGCC    最近垃圾回收的原因
GCC 当前垃圾回收的原因

6.gcnew选项:

7.gcoldcapacity选项

[root@tomcat01 ~]# jstat -gcoldcapacity  13614
   OGCMN       OGCMX        OGC         OC       YGC   FGC    FGCT     GCT   
  1398144.0   1398144.0   1398144.0   1398144.0   779     0    0.000    5.976

列名介绍:

Column  Description
OGCMN   最小年老代容量 (KB)
OGCMX   最大年老代容量(KB)
OGC 当前年老代容量 (KB)
OC  当前年老代空间 (KB)
YGC 年轻代gc次数
FGC full gc次数
FGCT    full gc时间
GCT 垃圾收集总时间

8.gcutil

[root@tomcat01 ~]# jstat -gcutil 13614 2000 10                             
  S0     S1     E      O      P     YGC     YGCT    FGC    FGCT     GCT   
  0.68   0.00  98.02  14.48  70.23    804    6.117     0    0.000    6.117
  0.00   0.83  34.27  14.48  70.23    805    6.124     0    0.000    6.124
  0.00   0.83  34.27  14.48  70.23    805    6.124     0    0.000    6.124

列名介绍:

Column  Description
S1  S1使用百分比
E   eden使用百分比
O   old使用百分比
P   perm使用百分比
YGC 年轻代gc次数
YGCT    年轻代gc时间
FGC full gc次数
FGCT    full gc时间
GCT 垃圾收集总时间

9.printcompilation
编译统计的方法

[root@tomcat01 ~]# jstat -printcompilation 13614
Compiled  Size  Type Method
    3514    173    1 net/sf/jsqlparser/parser/CCJSqlParser jj_scan_token
[root@tomcat01 ~]# jstat -printcompilation 13614
Compiled  Size  Type Method
3516    126    1 java/security/Provider$ServiceKey hashCode

列名介绍:

Column  Description
Compiled    被执行的编译任务的数量
Size    方法字节码的字节数
Type    编译类型
Method  编译方法的类名和方法名。类名使用"/" 代替 "." 作为空间分隔符. 方法名是给出类的方法名. 格式是一致于HotSpot - XX:+PrintComplation 选项

4.详细堆栈内存空间使用状态信息查看分析

jmap -heap 4214

Attaching to process ID 4214, please wait... 
Debugger attached successfully. 
Server compiler detected. 
JVM version is 24.55-b03 

using parallel threads in the new generation. 
using thread-local object allocation. 
Concurrent Mark-Sweep GC 

Heap Configuration:                        # 堆配置情况
MinHeapFreeRatio = 40                      #  最小堆的使用比例
MaxHeapFreeRatio = 70                      # 最大堆的可用比例
MaxHeapSize = 2684354560 (2560.0MB)        # 最大堆空间大小
NewSize = 713031680 (680.0MB)              # 新生代分配大小
MaxNewSize = 713031680 (680.0MB)           # 最大可用新生代分配大小 
OldSize = 5439488 (5.1875MB)               # 老年代大小
NewRatio = 2                               # 新生代比例
SurvivorRatio = 8                          # 新生代与suvivor的比例
PermSize = 251658240 (240.0MB)             # perm区大小
MaxPermSize = 251658240 (240.0MB)          # 最大可分配perm区大小
G1HeapRegionSize = 0 (0.0MB)               # G1堆区大小

Heap Usage:                                # 堆使用情况
New Generation (Eden + 1 Survivor Space):  # 新生代(伊甸区 + survior空间)
capacity = 641728512 (612.0MB)             # 伊甸区容量
used = 507109064 (483.6168899536133MB)     # 已经使用大小
free = 134619448 (128.38311004638672MB)    # 剩余容量
79.0223676394793% used                     # 使用比例
Eden Space:                                # 伊甸区
capacity = 570425344 (544.0MB)             # 伊甸区容量
used = 503156488 (479.84741973876953MB)    # 伊甸区使用
free = 67268856 (64.15258026123047MB)      # 伊甸区当前剩余容量
88.2072462755091% used                     # 伊甸区使用情况
From Space:                                # survior1区
capacity = 71303168 (68.0MB)               # survior1区容量
used = 3952576 (3.76947021484375MB)        # surviror1区已使用情况
free = 67350592 (64.23052978515625MB)      # surviror1区剩余容量
5.543338551240809% used                    # survior1区使用比例
To Space:                                  # survior2 区
capacity = 71303168 (68.0MB)               # survior2区容量
used = 0 (0.0MB)                           # survior2区已使用情况
free = 71303168 (68.0MB)                   # survior2区剩余容量
0.0% used                                  # survior2区使用比例
concurrent mark-sweep generation:          # 老生代使用情况
capacity = 1971322880 (1880.0MB)           # 老生代容量
used = 1514740296 (1444.5689163208008MB)   # 老生代已使用容量
free = 456582584 (435.4310836791992MB)     # 老生代剩余容量
76.83877214472345% used                    # 老生代使用比例
Perm Generation:                           # perm区使用情况
capacity = 251658240 (240.0MB)             # perm区容量
used = 57814400 (55.1361083984375MB)       # perm区已使用容量
free = 193843840 (184.8638916015625MB)     # perm区剩余容量
22.973378499348957% used                   # perm区使用比例
28645 interned Strings occupying 3168232 bytes.

参考文档:
http://nolinux.blog.51cto.com/4824967/1588716

猜你喜欢

转载自blog.51cto.com/wujianwei/2106399
今日推荐