WebSphere Application Server (WAS)

How to Monitor Heap Size or JVM WebSphere Application Server Usage

July 18, 2018

JVM WebSphere Application Server heap size usage how can be monitored? So, here are few easy steps that can be performed to achieve this requirement:

  • Create a file named as, showHeapSize.py and add the following code than save and exit:

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+”%”

  • Place the above file to directory /opt/jars/
  • Create a new file named heap.sh, paste the below lines (modify according to your environment), and place to /opt/scripts/ directory.

echo “WAS Profile 1 Start”
/opt/WAS9/IBM/WebSphere/AppServer/bin/wsadmin.sh -lang jython -f /opt/jars/showHeapSize.py server1 -username wasadmin -password password;
echo “WAS Profile 1 End”
echo “WAS Profile 2 Start”
/opt/WAS9/IBM/WebSphere/AppServer/profiles/AppSrv02/bin/wsadmin.sh -lang jython -f /opt/jars/showHeapSize.py server1 -username wasadmin -password password;
echo “WAS Profile 2 End”

  • Run the script from terminal. JVM websphere application server results will be displayed as mentioned below:

jvm websphere application server

Download sample code here.

You Might Also Like

3 Comments

  • Reply Venu January 30, 2021 at 12:01 am

    Thank you for the detailed scripts. Those worked perfectly.

    • Reply niranjan April 26, 2021 at 2:56 pm

      Where can i find jars folder. In opt/ it is not available.

  • Reply Junaid Azam May 19, 2021 at 1:39 pm

    Hi Niranjan,
    Its just an example. You can create your own folder where it is accessible either in /opt or somewhere else.

  • Leave a Reply

    error

    Subscribe