Share

Sunday, January 31, 2016

WAS JMS Listener Status wsadmin

In environments where you have more usage of WAS JMS services  and  integration with Websphere MQ and MB. We might be in the need to look after the  JMS listener status, always.

If the Listener status  is "false"  it means that your listener is not picking/writing messages from/to the Queue.

Before we end up in the backlog. Its always  recommended to have one listener status monitoring  which should/could intimate you in case of  abrupt  failure (or) stoppage in listener.

Here is the wsadmin Jython Script which will let you know the status of WAS Listeners under the Cell.

Jython code

import re
Running_Nodes=AdminControl.queryNames('*:type=Server,name=nodeagent,*').split(java.lang.System.getProperty("line.separator"))
print "----------------------------------------------------------------------------------------------"
print "Websphere Listener Status Report for the Cell", AdminControl.getCell()
cell=AdminControl.getCell()
print "----------------------------------------------------------------------------------------------"
print ""
print ""
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"))
        for Serv in Running_JVMS:
                ServerName=AdminControl.invoke(Serv,"getName()")
                Listener_Ports=AdminControl.queryNames('*:type=ListenerPort,cell='+cell+',process='+ServerName+',*').split(java.lang.System.getProperty("line.separator"))
                if Listener_Ports == ['']:
                        break
                else:
                        print ""
                        print ">>Server %r Running at %r"%(AdminControl.invoke(Serv,"getName()"),NodeName)
                        print "----------------------------------------------------------------------------------------------"
                        print "Name\tJNDIName\tDestiationQueueName\tAvailable"
                        print "----------------------------------------------------------------------------------------------"
                        for lis in Listener_Ports:
                                JNDIName=AdminControl.invoke(lis,"getJmsConnJNDIName()")
                                DestName=AdminControl.invoke(lis,"getJmsDestJNDIName()")
                                match=re.search(r'([:\w]+)=([\w]+)',lis)
                                name=match.group(2)
                                state=AdminControl.invoke(lis,"isStarted()")
                                print "%r\t%r\t%r\t%r"%(name,JNDIName,DestName,state)
                print "----------------------------------------------------------------------------------------------"

Note on compatibility:

WAS6.1 and above as it has REGEX usage.

Result

--------------------------------------------------------------------------------------
Websphere Listener Status Report for the Cell MWICell
--------------------------------------------------------------------------------------
>>Server 'MWIServer1" Running at 'mwiNode01'
--------------------------------------------------------------------------------------
Name                 JNDIName            DestinationQueue               Available
--------------------------------------------------------------------------------------
'Queue1_Rec'        'jms/App1_QCF'      'jms/App1receiverqueue'         'true'
'Queue2_Rec'        'jms/App2_QCF'      'jms/App2receiverqueue'         'true'
'Queue1_Send'       'jms/App1s_QCF'     'jms/App1senderqueue'           'true'
'Queue2_Send'       'jms/App2s_QCF'     'jms/App1senderqueue'           'true'
--------------------------------------------------------------------------------------

You can have a shell script on top of it which would trigger alert email in case of any "false" in the Available status.

Here is the sample shell script to send email notification. ( Make sure you have valid mail setup in your server with dummy mail before setting this up)

Environment Setup:  

  • Create a directory in your server and copy all these script files (.py file and .sh file).
  • Make sure you have full access on that directory as the script will be creating some temp files for processing.


Shell script

#!/bin/sh
BASEDIR=`dirname $0`
/apps/websphere8/mwi/bin/wsadmin.sh -conntype SOAP -host MWICell -port 8834 -user wasadminusr -password wasadminpass -lang jython -f $BASEDIR/listenerstatus.py > report

RECIPIENTS="sara@mwinventory.in"

grep -i "false"  $report > $BASEDIR/outfile

if [ $? -eq 0 ]
then
    echo "Hi Team" >> $BASEDIR/outfile
    echo "" >> $BASEDIR/outfile
    echo "Below Listeners are seem to be notrunning or stopped, Please check the status and restart the JVM if required." >> $BASEDIR/outfile
    echo "" >> $BASEDIR/outfile
    mailx -s "ALERT: Listener Status Stopped" $RECIPIENTS < $BASEDIR/outfile
fi

As usual let me know your queries by comments.

Hope it helps.

Cheers,
Sarav

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



websphere application server status report wsadmin

Objective:

This script will help you to print the “Running Server List” per everyNode registered under Cell. Server statistics made easy now with wsadmin. 

Compatibility:


WAS6.1 and above


Script

Running_Nodes=AdminControl.queryNames('*:type=Server,name=nodeagent,*').split(java.lang.System.getProperty("line.separator"))
print "-----------------------------------------------------------------------"
print "Websphere Status Report by Sarav@mwinventory.in"
print "------------------------------------------------------------------------"
print ""
print ""
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 "----------------------------------"
        for Serv in Running_JVMS:
                print AdminControl.invoke(Serv,"getName()")
        print "----------------------------------"
print "--------------------------------------------------"

Result:
bash-3.00# ./wsadmin.sh -lang jython -username wsadmin -password wsadmin -f status_v2.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
--------------------------------------------------


----------------------------------
NODENAME:   MWINode01
----------------------------------
MWI_SERVER01
MWI_SERVER02
MWI_SERVER03
MWI_SERVER04
nodeagent
----------------------------------

----------------------------------
NODENAME:   MWINode02
----------------------------------
MWI_SERVER01
MWI_SERVER02
MWI_SERVER03
MWI_SERVER04
nodeagent
----------------------------------


--------------------------------------------------


Share if you like. Comment for any help as usual.

Hope it helps.

Cheers,
Sarav