Get the JVM heap utilisation for a running WebSphere server
I recently had to find out the amount of heap memory (the place a JVM stores it's object instances) being used by a running WebSphere v7.0 instance we suspected of being close to out of memory.
To do this, I could use the below jython script called 'showHeapSize.py':
serverJVM=AdminControl.completeObjectName('type=JVM,process=' + sys.argv[0] + ',*')
serverJVMObj=AdminControl.makeObjectName(serverJVM)
perf=AdminControl.completeObjectName('type=Perf,process=' + sys.argv[0] + ',*')
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 sys.argv[0] + ".> "+str(currentHeapsize)+"K .> "+str(usedMemory)+"K .> "+"Usage:%.2f" % usage+"%"
Which can then be executed as follows:
/opt/WebSphere/7.0/AppServer/profiles/AppSrv01/bin/wsadmin.sh -lang jython -f showHeapSize.py server1
where "AppSrv01" is your profile name and "server1" is the server name - producing the following output:
server1 .> 893760K .> 483776K .> Usage:54.13%
Remember that WebSphere allows you to set an Initial as well as a Maximum heap size - if they're not the same then the heap size could be anywhere between these two values. The output above will show you the percentage use of the *current* heapsize, which may not be the maximum. Some recommend setting these to the same value to remove the performance overhead of the JVM needed to allocate more memory as it grows the heap.
Comments
Leave a comment
Allowed XHTML tags: <p, ul, ol, li, dl, dt, dd, address, blockquote, ins, del, span, bdo, br, em, strong, dfn, code, samp, kdb, var, cite, abbr, acronym, q, sub, sup, tt, i, b, big, small>
this makes it easy o find out what is ur jvm status rather than going to tivoli
Comment by shaikh [Visitor] — 10/07/10 @ 01:57
Comment by Raj [Visitor] — 05/20/11 @ 17:56
Comment by Sara [Visitor] — 05/11/15 @ 20:36
I added condition for the 1st argument (whoever uses the script will be forced to enter the 1st arguemnt, otherwise it won't run)
Muneeb
Comment by Muneeb [Visitor] — 02/23/16 @ 06:10
Comment by Daryl [Visitor] — 08/05/16 @ 01:42