Tuesday, December 21, 2010

WebSphere-Get Runtime JVM heapsize

The following script can be used to get the current JVM HeapSize:

serverJVM=AdminControl.completeObjectName(’type=JVM,process=server1,*’)

serverJVMObj=AdminControl.makeObjectName(serverJVM)

perf=AdminControl.completeObjectName(’type=Perf,process=server1,*’)

perfObj=AdminControl.makeObjectName(perf)

jvmObj=AdminControl.invoke_jmx(perfObj,’getStatsObject’,[serverJVMObj,java.lang.Boolean('false')],['javax.management.ObjectName','java.lang.Boolean'])

currentHeapsize=jvmObj.getStatistic(’HeapSize’).getCurrent()
usedMemory=jvmObj.getStatistic(’UsedMemory’).getCount()
usage=float(usedMemory)/float(currentHeapsize)*100

print serverName+” –> “+str(currentHeapsize)+”K –> “+str(usedMemory)+”K –> “+”Usage:%.2f” % usage+”%”

This script will print current heap size and used memory of JVM.

No comments:

Post a Comment