Wednesday 10 January 2018

Monitor JVM memory usage in WAS


Now, here is the Jython script designed to help monitor the “HeapSize”  which can let us able to proactively measure and take action for Outofmemoryerror issue.

Copy the Below Code and  Save this with .py extension and run it with wsadmin.

appServer=raw_input("Enter application server name: ")
JVMName = AdminControl.completeObjectName('type=JVM,process='+ appServer +',*')
JVMObject = AdminControl.makeObjectName(JVMName)
perf = AdminControl.completeObjectName('type=Perf,process='+appServer+',*')
perfObject = AdminControl.makeObjectName(perf)
Obj = AdminControl.invoke_jmx(perfObject,"getStatsObject",[JVMObject,java.lang.Boolean('false')],['javax.management.ObjectName','java.lang.Boolean'])
current = Obj.getStatistic('HeapSize').getCurrent()
used = Obj.getStatistic('UsedMemory').getCount()
usage = float(used)/float(current)*100
uptime = float(Obj.getStatistic('UpTime').getCount())/60/60/24
print "--------------------------------------------"
print "ServerName      :", appServer
print "uptime(in days) :",  int(uptime)
print "--------------------------------------------"
print "CurrentUsage    :", current
print "Usedmemory      :", used
print "Usage in Percent:", int(usage)
print "--------------------------------------------"


Let see how this script will work

Here i saved above code as getHeapSize.py and run as below.

Syntax :   $WAS_HOME/bin/wsadmin.sh  -lang jython  -f getHeapSize.py



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




No comments: