Share

Thursday, January 14, 2016

WAS - Get Running Server list with heap usage wsadmin

Objective:

This script will help you to print the “Running Server List” per everyNode registered under Cell(dmgr). With up time and heap usage

Compatibility: WAS6.1 and above

Script:
Running_Nodes=AdminControl.queryNames('*:type=Server,name=nodeagent,*').split(java.lang.System.getProperty("line.separator"))
print "Websphere Status Report  by Sarav@mwinventory.in"

print "CELLNAME: ", AdminControl.getCell()
print "HOST:     ", AdminControl.getHost()

ignorelist=['dmgr','nodeagent']
for nod in Running_Nodes:
        NodeName=AdminControl.invoke(nod ,"getNodeName()")
        Running_JVMS=AdminControl.queryNames('*:type=Server,node='+NodeName+',*').split(java.lang.System.getProperty("line.separator"))
        print "====================================================================="
        print "NODENAME:",NodeName
        print "====================================================================="
        print "--------------------------------------------"
        print "<< Running JVMs under the Node >>"
        print "--------------------------------------------"
        for Serv in Running_JVMS:
                print  AdminControl.invoke(Serv,"getName()")
        print "--------------------------------------------"

        print ""
        print ""
        print "--------------------------------------------"
        print "<< Server Runtime Information >>"
        print "--------------------------------------------"

        for JVM in Running_JVMS:
                ServerName=AdminControl.invoke(JVM ,"getName()")
                if ServerName not in ignorelist:
                        JVMName=AdminControl.completeObjectName('type=JVM,process='+ServerName+',*')
                        JVMObject=AdminControl.makeObjectName(JVMName)
                        perf=AdminControl.completeObjectName('type=Perf,process='+ServerName+',*')
                        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      :", ServerName
                print "uptime(in days) :", int(uptime)
                print "--------------------------------------------"
                print "CurrentUsage    :", current
                print "Usedmemory      :", used
                print "Usage in Percent:", int(usage)
                print "--------------------------------------------"
print ""
print "====================================================================="



Result:
bash-3.00# ./wsadmin.sh -lang jython -username wsadmin -password wsadmin -f getHeapSizeV3.py
WASX7209I: Connected to process "dmgr" on node MWICellManager01 using SOAP connector;  The type of process is: DeploymentManager
Websphere Status Report  by Sarav@mwinventory.in

CELLNAME:  MWICell
HOST:      as1.mwi.com


=====================================================================
NODENAME:   MWINode01
=====================================================================
--------------------------------------------
<< Running JVMs under the Node >>
--------------------------------------------
MWI_SERVER01
MWI_SERVER02
nodeagent
--------------------------------------------

--------------------------------------------
<< Server Runtime Information >>
--------------------------------------------
ServerName      : MWI_SERVER01
uptime(in days) : 27
--------------------------------------------
CurrentUsage    : 122176
Usedmemory      : 87480
Usage in Percent: 71
--------------------------------------------
--------------------------------------------
ServerName      : MWI_SERVER02
uptime(in days) : 64
--------------------------------------------
CurrentUsage    : 483904
Usedmemory      : 412135
Usage in Percent: 85
--------------------------------------------

=====================================================================

=====================================================================
NODENAME:   MWINode02
=====================================================================
--------------------------------------------
<< Running JVMs under the Node >>
--------------------------------------------
MWI_SERVER03
MWI_SERVER04
nodeagent
--------------------------------------------

--------------------------------------------
<< Server Runtime Information >>
--------------------------------------------
ServerName      : MWI_SERVER03
uptime(in days) : 251
--------------------------------------------
CurrentUsage    : 58432
Usedmemory      : 50091
Usage in Percent: 85
--------------------------------------------
--------------------------------------------
ServerName      : MWI_SERVER04
uptime(in days) : 36
--------------------------------------------
CurrentUsage    : 120704
Usedmemory      : 101834
Usage in Percent: 84
--------------------------------------------

=====================================================================


You can find the previous version of this code here

Feel free to comment for any questions.  For any general questions use our Forum

Hope it helps.


Cheers,
Sarav



5 comments :

  1. I am getting the below error:

    WASX7017E: Exception received while running file "C:\Program Files\IBM\WebSphere
    \AppServer\profiles\maximoDMgr\bin\deployConsole.py"; exception information: com
    .ibm.bsf.BSFException: exception from Jython:
    Traceback (innermost last):
    (no code object) at line 0
    File "", line 8
    NodeName=AdminControl.invoke(node,"getNodeName()")
    ^
    SyntaxError: invalid syntax

    ReplyDelete
    Replies
    1. I copied the script in deployConsole.py and executed the script using wsadmin.

      Delete
    2. please check you python indentation.

      Delete
    3. Hi Sarav,

      I am still facing the issues for any e multiple MBEans, is there any solution for that..

      Delete
    4. This comment has been removed by the author.

      Delete