Share

Showing posts with label wsadmin scripts. Show all posts
Showing posts with label wsadmin scripts. Show all posts

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


Thursday, December 31, 2015

Websphere Application Server heap size monitoring with wsadmin

In Middleware infrastructure, These two issues are very common.

1. Connection Pool Overflow
 2. OutOfMemory(OOM)

Both of them will lead the application to the rock bottom and application unavailability, So its always recommended to have on eye on both of these key factors, by having some kind of Run time Monitoring and alerting system tools. (Tivoli, Wily, Nagios etc..)

Sometime, We will not be having the sufficient monitoring tool to capture this OutOfMemory and Connection Pool Overflow.

That's when, we fall back into the efficient and easiest way,  which is scripting tools,  like WLST and WSADMIN etc.

Hope you have read our another post about "Connection Pool Overflow monitoring and Alerting System" if not click here

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

As mentioned earlier in our post, You can have some kind of scheduling tools like Autosys (or) Cron and run it in a frequent interval along with Shell/Perl script and generate an email (or) ticket.

Let me know if there is any help required in designing of Shell/perl (or) in the scheduling part.

Latest version of this code can be found here

TheCode
Running_JVMS=AdminControl.queryNames("*:type=Server,*").split(java.lang.System.getProperty("line.separator"))
ignorelist=['nodeagent','dmgr']
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 "--------------------------------------------"



Save this with .py extention and run it with wsadmin

The Result
bash-3.00# ./wsadmin.sh -username wasadmin -password wasadmin -lang jython -f ./python_scripts/getHeapStatus.py
WASX7209I: Connected to process "dmgr" on node mwiCellManager01 using SOAP connector;  The type of process is: DeploymentManager
--------------------------------------------
ServerName      : mwi_server01
uptime(in days) : 13
--------------------------------------------
CurrentUsage    : 119936
Usedmemory      : 85675
Usage in Percent: 71
--------------------------------------------
--------------------------------------------
ServerName      : mwi_server02
uptime(in days) : 50
--------------------------------------------
CurrentUsage    : 483392
Usedmemory      : 319485
Usage in Percent: 66
--------------------------------------------



Hope it helps.

For any question related to this. Please feel free to reach us via comment.
Always you can write an email to us at admin@mwinventory.in

Cheers and Have a great and prosperous new year. Best wishes from teammwi.


Thursday, December 17, 2015

Websphere Connection Pool monitoring and Alerting System ( Connection Pool runtime information)


Many of the infrastructure monitoring tools  brings their own JMX monitoring now a days to monitor all the JVM components including connection pool (DataSource) JMS etc.

But, If in case you wanted to set  up your own alerting system (Email Notification etc) for Connection pool.  You can use this  wsadmin script.

Design
  1. It will find all the running servers registered with DMGR (cell) and take a list of running connection pools targeted on those servers.
  2. It will automatically set 80 percent of the connection max_limit as a threshold.
  3. It will print a alert message, in case of possible connection pool overflow. When the current connection limit reaches the threshold.
If you do not want any alerting system and want to see the connection pool usage manually in case of requirement (or) on demand basis. you can just use this jython script with wsadmin. In case if you wanted to setup alerting system refer the additional notes for some ideas of designing the alerting system.

Additional notes
  1. you can run this script in a frequent interval like 2 minutes (or) 10 minutes using the external shell script scheduled in crontab and get the alert generated. ( let me know in comment section if you need help) 
  2. If you have Autosys, you can rather schedule it with JIL and run this in a periodic interval.
  3. After scheduling it to run on certain interval you can use any log parse monitoring tools like Tivoli and get alerts/tickets upon your infrastructure set up.

Version compatibility

was6.1 and above ( for was 6 there is little bit modification required, write a comment if you need)

wsadmin script

import re
Running_JVMS=AdminControl.queryNames("*:type=Server,*").split(java.lang.System.getProperty("line.separator"))
ignorelist=['nodeagent','dmgr']
TMPFILE='/tmp/PoolContents.tmp'
global current_conn
for JVM in Running_JVMS:
        ServerName=AdminControl.invoke(JVM ,"getName()")
        if ServerName not in ignorelist:
                DS=AdminControl.queryNames('*:process='+ServerName+',type=DataSource,*').split(java.lang.System.getProperty("line.separator"))
                for entry in DS:
                        if AdminControl.invoke(entry, "getStatus()") != '99':
                                print "============================================"
                                print "ServerName    :", ServerName
                                DSN=AdminControl.invoke(entry, "getName()")
                                print "DataSourceName:", DSN
                                JNDN=AdminControl.invoke(entry, "getJndiName()")
                                print "JNDIName      :", JNDN
                                MaxConn=AdminControl.invoke(entry, "getMaxConnections()")
                                print "MaxConnections:", MaxConn
                                print "StatusCode    :", AdminControl.invoke(entry, "getStatus()")
                                ##########################
                                fout=open(TMPFILE, 'w')
                                data=AdminControl.invoke(entry, "showPoolContents")
                                fout.write(data)
                                fout.close()
                                percent=0.8
                                threshold=int(MaxConn)*float(percent)
                                print "Threshold     :", threshold
                                try:
                                        fin=open(TMPFILE)
                                        filedata=fin.readlines()
                                        for line in filedata:
                                                #match 1= re.search(r'\:\s\d', line)
                                                #matchstr=re.search(r'Total number of connection in shared pool', line)
                                                matchstr=re.search('(.....\s......\s..\s..........\s..\s......\s....):(\s\d)', line)
                                                if matchstr:
                                                        #current_conn=match.group().split(":")[1].strip(" ")
                                                        current_conn=matchstr.group(2)
                                                        if int(current_conn) >= int(threshold):
                                                                ALERT='YES'
                                                                ALERTSTRING='Connection Pool %r reached 80 percent of its max_limit on Server %r'%(DSN,ServerName)
                                                                print ALERTSTRING
                                                        else:
                                                                ALERT='NO'
                                                        break

                                                else:
                                                        current_conn=0


                                        fin.close()
                                        print "Currently used:", current_conn
                                        print "============================================"
                                except IOError:
                                        print  'Something went Wrong.'



how to run

Save the above code with ".py" extension and run it with wsadmin.

In example


wsadmin.sh -lang jython -username <username> -password <password> -lang jython -f <saved py file name>

Cheers,
Sara Velu

Follow us at  : https://www.facebook.com/middlewareinventory/