JVM监测

JAVA基础:JVM监测&工具探究:

提到的JVM参数的设置需要根据应用的特性来进行设置,每个参数的设置都需要对JVM进行长时间的监测,并不断进行调整才能找到最佳设置方案。本文将介绍如果通过工具及Java api来监测JVM的运行状态,并详细介绍各工具的使用方法。

需要监测的数据:(内存使用情况 谁使用了内存 GC的状况)

内存使用情况--heap&PermGen

@ 表示通过jmap –heap pid 可以获取的值

# 表示通过jstat –gcutil pid 可以获取的值

参数的查看可以通过多种方法 本文中只随机列出一种。

 

描述最大值当前值报警值
堆内存@Heap Configuration::MaxHeapSize
sum(eden+servivor+old)
sum(eden+servivor+old)自设
非堆内存sum(perm+native) 
Eden@Eden Space::capacity@Eden Space::used
Survivor0@From Space::capacity@From Space::used
Survivor1@To Space::capacity@To Space::used
New gen
(注意区别于Xmn参数设置)
@New Generation::capacity
Eden + 1 Survivor Space
@New Generation::used
Old gen@concurrent mark-sweep generation::capacity
(CMS是对old区的gc,所以此处即表示old gen)
@concurrent mark-sweep generation::capacity(CMS)::used自设
Perm Gen@Perm Generation::capacity@Perm Generation::used自设

 

内存使用情况--config

 

描述配置值
MaxTenuringThresholdjinfo -flag MaxTenuringThreshold pid
MinHeapFreeRatio@Heap Configuration::MinHeapFreeRatio
MaxHeapFreeRatio@Heap Configuration::MaxHeapFreeRatio
new gen gc@using … in the new generation
old gen gcnew gen gc声明下方
类总数统计??

 

内存使用情况—C heap

◆  top or ps aux

谁使用了内存

◆ Heap

jmap –histo

jmap –dump ,then mat

◆ C heap

google perftools

GC的状况

 

描述收集次数收集时间应用暂停时间
Full GC#FGC#FGCT 设置-XX:+PrintGCApplicationStoppedTime后在日志中查看
Young GC#YGC#YGCT同上

 

-XX:+PrintGCDetails -XX:+PrintGCTimeStamps -XX:+PrintHeapAtGC -XX:+PrintGCApplicationStoppedTime -Xloggc:logs/gc.log

 

常用工具介绍:jinfo jmap jstack jstat

jinfo

◆ 可以从一个给定的java进程或core文件或远程debug服务器上获取java配置信息。包括java系统属性及JVM参数(command line flags)。注意在jvm启动参数中没有配置的参数也可使用jinfo –flag xxx pid输出默认值(很有用,但貌似一些简写的参数查不出来)。

◆ 可以修改运行时的java 进程的opts。

◆ 只有solaris和linux的JDK版本里有。

◆ 使用方式可使用jinfo –h 查询。

jmap

观察运行中的jvm物理内存的占用情况。

如果连用SHELL jmap -histo pid>a.log可以将其保存到文本中去,在一段时间后,使用文本对比工具,可以对比出GC回收了哪些对象。

参数很简单,直接查看jmap -h

举例:

  1. jmap -heap pid  
  2. jmap -dump:format=b,file=heap.hprof <pid>  

dump文件可以通过MemoryAnalyzer分析查看.网址:http://www.eclipse.org/mat/,可以查看dump时对象数量,内存占用,线程情况等。

jmap -dump:live为啥会触发Full GC

jstack

观察jvm中当前所有线程的运行情况和线程当前状态

如果java程序崩溃生成core文件,jstack工具可以用来获得core文件的java stack和native stack的信息,从而可以轻松地知道java程序是如何崩溃和在程序何处发生问题。另外,jstack工具还可以附属到正在运行的java程序中,看到当时运行的java程序的java stack和native stack的信息, 如果现在运行的java程序呈现hung的状态,jstack是非常有用的。目前只有在Solaris和Linux的JDK版本里面才有。

参数很简单,直接查看jstack -h

举例:

  1. jstack pid  

jstat

JVM监测工具(Java Virtual Machine Statistics Monitoring Tool)。利用了JVM内建的指令对Java应用程序的资源和性能进行实时的命令行的监控,包括各种堆和非堆的大小及其内存使用量、classloader、compiler、垃圾回收状况等。

举例:

  1. jstat –printcompilation -h10 3024 250 600 

每250毫秒打印一次,一共打印600次 每隔10行显示一次head

语法结构:

  1. Usage: jstat -help|-options  
  2. jstat -<option> [-t] [-h<lines>] <vmid> [<interval> [<count>]]  

参数介绍:

◆ -h n 每隔几行输出标题

◆ vmid VM的进程号,即当前运行的java进程号

◆ -t 在第一列显示自JVM启动以来的时间戳

◆ -J 修改java进程的参数。类似jinfo -flag <name>=<value>。例如-J-Xms48m 设置初始堆为48M。详见这里。这个参数挺有用的,可以在运行中调整参数以方便测试、监测。

◆ -option option为要检测的参数。参数列表可通过jstat –options 获取。下面将分别介绍每个参数及输出字段的含义。

 

class统计class loader行为信息
compiler统计编译行为信息
gc统计jdk gc时heap信息
gccapacity统计堆内存不同代的heap容量信息
gccause统计gc的情况(同-gcutil)和引起gc的事件
gcnew统计gc时新生代的信息(相比gcutil更详细)
gcnewcapacity统计gc时新生代heap容量
gcold统计gc时,老年区的情况
gcoldcapacity统计gc时,老年区heap容量
gcpermcapacity统计gc时,permanent区heap容量
gcutil统计gc时,heap情况
printcompilation统计编译行为信息

 

-class option:Class Loader Statistics

 

ColumnDescription
LoadedNumber of classes loaded.
BytesNumber of Kbytes loaded.
UnloadedNumber of classes unloaded.
BytesNumber of Kbytes unloaded.
TimeTime spent performing class load and unload operations.

 

-compiler:HotSpot Just-In-Time Compiler Statistics

 

ColumnDescription
CompiledNumber of compilation tasks performed.
FailedNumber of compilation tasks that failed.
InvalidNumber of compilation tasks that were invalidated.
TimeTime spent performing compilation tasks.
FailedTypeCompile type of the last failed compilation.
FailedMethodClass name and method for the last failed compilation.

 

-gc Option:Garbage-collected heap statistics

 

ColumnDescription
S0CCurrent survivor space 0 capacity (KB).
S1CCurrent survivor space 1 capacity (KB).
S0USurvivor space 0 utilization (KB).
S1USurvivor space 1 utilization (KB).
ECCurrent eden space capacity (KB).
EUEden space utilization (KB).
OCCurrent old space capacity (KB).
OUOld space utilization (KB).
PCCurrent permanent space capacity (KB).
PUPermanent space utilization (KB).
YGCNumber of young generation GC Events.
YGCTYoung generation garbage collection time.
FGCNumber of full GC events.
FGCTFull garbage collection time.
GCTTotal garbage collection time.

 

-gccapacity Option:Memory Pool Generation and Space Capacities

 

ColumnDescription
NGCMNMinimum new generation capacity (KB).
NGCMXMaximum new generation capacity (KB).
NGCCurrent new generation capacity (KB).
S0CCurrent survivor space 0 capacity (KB).
S1CCurrent survivor space 1 capacity (KB).
ECCurrent eden space capacity (KB).
OGCMNMinimum old generation capacity (KB).
OGCMXMaximum old generation capacity (KB).
OGCCurrent old generation capacity (KB).
OCCurrent old space capacity (KB).
PGCMNMinimum permanent generation capacity (KB).
PGCMXMaximum Permanent generation capacity (KB).
PGCCurrent Permanent generation capacity (KB).
PCCurrent Permanent space capacity (KB).
YGCNumber of Young generation GC Events.
FGCNumber of Full GC Events.

 

-gccause Option:Garbage Collection Statistics, Including GC Events

 

ColumnDescription
LGCCCause of last Garbage Collection.
 
GCCCause of current Garbage Collection.
 

 

前面的字段与gcutil相同.

-gcnew Option:New Generation Statistics

 

ColumnDescription
S0CCurrent survivor space 0 capacity (KB).
S1CCurrent survivor space 1 capacity (KB).
S0USurvivor space 0 utilization (KB).
S1USurvivor space 1 utilization (KB).
TTTenuring threshold.
MTTMaximum tenuring threshold.
DSSDesired survivor size (KB).
ECCurrent eden space capacity (KB).
EUEden space utilization (KB).
YGCNumber of young generation GC events.
YGCTYoung generation garbage collection time.

 

-gcnewcapacity Option:New Generation Space Size Statistics

 

ColumnDescription
NGCMN
 
Minimum new generation capacity (KB).
 
NGCMXMaximum new generation capacity (KB).
NGCCurrent new generation capacity (KB).
S0CMXMaximum survivor space 0 capacity (KB).
S0CCurrent survivor space 0 capacity (KB).
S1CMXMaximum survivor space 1 capacity (KB).
S1CCurrent survivor space 1 capacity (KB).
ECMXMaximum eden space capacity (KB).
ECCurrent eden space capacity (KB).
YGCNumber of young generation GC events.
FGCNumber of Full GC Events.

 

-gcold Option:Old and Permanent Generation Statistics

 

ColumnDescription
PCCurrent permanent space capacity (KB).
PUPermanent space utilization (KB).
OCCurrent old space capacity (KB).
OUold space utilization (KB).
YGCNumber of young generation GC events.
FGCNumber of full GC events.
FGCTFull garbage collection time.
GCTTotal garbage collection time.

 

-gcoldcapacity Option:Old Generation Statistics

 

ColumnDescription
OGCMNMinimum old generation capacity (KB).
OGCMXMaximum old generation capacity (KB).
OGCCurrent old generation capacity (KB).
OCCurrent old space capacity (KB).
YGCNumber of young generation GC events.
FGCNumber of full GC events.
FGCTFull garbage collection time.
GCTTotal garbage collection time.

 

-gcpermcapacity Option: Permanent Generation Statistics

 

ColumnDescription
PGCMNMinimum permanent generation capacity (KB).
PGCMXMaximum permanent generation capacity (KB).
PGCCurrent permanent generation capacity (KB).
PCCurrent permanent space capacity (KB).
YGCNumber of young generation GC events.
FGCNumber of full GC events.
FGCTFull garbage collection time.
GCTTotal garbage collection time.

 

-gcutil Option:Summary of Garbage Collection Statistics

 

ColumnDescription
S0Survivor space 0 utilization as a percentage of the space's current capacity.
S1Survivor space 1 utilization as a percentage of the space's current capacity.
EEden space utilization as a percentage of the space's current capacity.
OOld space utilization as a percentage of the space's current capacity.
PPermanent space utilization as a percentage of the space's current capacity.
YGCNumber of young generation GC events.
YGCTYoung generation garbage collection time.
FGCNumber of full GC events.
FGCTFull garbage collection time.
GCTTotal garbage collection time.

 

-printcompilation Option: HotSpot Compiler Method Statistics

 

ColumnDescription
CompiledNumber of compilation tasks performed.
SizeNumber of bytes of bytecode for the method.
TypeCompilation type.
MethodClass name and method name identifying the compiled method. Class name uses "/" instead of "." as namespace separator. Method name is the method within the given class. The format for these two fields is consistent with the HotSpot - XX:+PrintComplation option.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值