Search This Blog

Showing posts with label JMS monitoring. Show all posts
Showing posts with label JMS monitoring. Show all posts

Friday, June 22, 2012

WLST JMS monitoring stats to CSV file

Intro: We got a mail from Richard who wish to write a WLST script to monitor a JMS Runtime. The Queue performance details wish to collect.

WLST script to monitor JMS and store the attribute values when there is Production live available or Performance test run  going on with multiple user load collect the statistcs and send that into a separate CSV file. Just to give little idea on CVS, A comma-separated values (CSV) file are also referred as a flat files, ascii files, and it is a spreadsheet convertible files. Richi want the logic to storing the statistics to a .csv file. Thought that it will be helpful for anyone who may have similar thoughts. We got the script idea from Richi that consisting the following prototype.

Writing to a CVS file has been simplified without using writer.csv, instead commas have been used and the file extension is hard coded as .csv, once you open the file you will see a prompt where in you need to select comma as the delimeter so that the values of jms statistics will be sorted accordingly, you can modify the script as per your need.

The script flow will be as mentioned below
  1. Open a file with write access.
  2. Get the RUNNING servers of the domain from domainRuntimeService.
  3. Print the headers of JMS counters.
  4. Get the details of JMS servers using JMSRuntime and JMSServers functions.
  5. Using a loop get the jms server destinations.
  6. Using a loop get the details of the parameters like ConsumersCurrentCount, ConsumersHighCount etc of the destinations and store those to variables.
  7. Print the variables.
  8. Close the file.
##################################################
#Title: WLST script to monitor JMS runtime and saving the values to CSV file
#Author: Sunil Nagavelli/Pavan Bhavani Shekar Devarakonda
#
###################################################
import sys


file1=open('JMS.csv','w+')

servers = domainRuntimeService.getServerRuntimes();

print>>file1, " ConsumersCurrentCount: ", ",", " ConsumersHighCount: ", ",", " DestinationType: ", ",", " BytesHighCount: ",
",", " BytesPendingCount: "

if (len(servers) > 0):
  for server in servers:
    jmsRuntime = server.getJMSRuntime();
    jmsServers = jmsRuntime.getJMSServers();
    for jmsServer in jmsServers:
      destinations = jmsServer.getDestinations();
      for destination in destinations:

        CCC = destination.getConsumersCurrentCount()
        CHC = destination.getConsumersHighCount()
        DT  = destination.getDestinationType()
        BHC = destination.getBytesHighCount()
        BPC = destination.getBytesPendingCount()

        print>>file1,CCC, ",", CHC, ",", DT,  ",", BHC, ",", BPC

print "values have been captured successfully into the csv file"
       
file1.close()

Saturday, November 14, 2009

JMS Monitoring using WLST

Let me walk through the script, The script is referring to a secure way of user credential usage in the WLST that is given here .

storeUserConfig() command in WLST can generates 2 file suserKeyFile, userConfigFile. These we can use multiple times in the script so I declared it on the top, Global scope variables, which can be used by any method in the script.
Coming to downside of the script, where you can find the main program logic. We need to understand from the main program onwards that is the good programmer reading habit :).

In the main module we don't want to see unnecessary data while running the script just want to see , so redirect useless data. first connect to the admin server in the domain.

Initialization of the URL dictionary for multiple server instances domain. The JmsStat module will tell you the actual status of each JMSRumtime Mbeans.

Here I got two hurdles the all script output is not from same MBean. I need to display the JMS statics from JMSRuntime MBean and need to navigate to the instance's specific JMS.

The list (ls) content need to store in variable and need to cding (cd)
myJmsls=ls(returnMap='true')

This makes turning point for the following script we surf for this found Satya Gattu Answer in ObjectMix.

Here (myJmsls) variable holds the value into list datastructure. Just by pointing index the value will be returned.

################################################################# 
# This script will  get the jms attributes
# Author : Prasanna Yalam
# Updated by: Pavan Devarakonda
################################################################# 

from java.util import Date

ucf='ursec'
ukf='urkey'
admurl='t3://url'
urldict={}

def conn():
try:
 connect(userConfigFile=ucf, userKeyFile=ukf, url=admurl)
except ConnectionException,e:
 print 'Unable to find admin server...'
 exit()
def initalize():
 serverlist= ['app010','app011',...]
 for svr in serverlist:
 cd("/Servers/"+svr)
 urldict[svr]='t3://'+get('ListenAddress')+':'+str(get('ListenPort'))

def JmsStat():
 d = Date() # now
 print  d 

 print 'Instance         ConCur ConHi ConTot High  MsgCur MsgPnd'
 print 'Name             Count  Count Count  Count Count  Count'
 print '===========**=======**==================================' 
 Ks = urldict.keys()
 Ks.sort()

 for key in Ks:
  try:
   connect(userConfigFile=ucf, userKeyFile=ukf,url=urldict[key])
   serverRuntime()
   cd('JMSRuntime/'+key+'.jms/JMSServers')
   curCnt= get('ConnectionsCurrentCount')
   cHiCnt=get('ConnectionsHighCount')
   cTotCnt=get('ConnectionsTotalCount')

   myJmsls=ls(returnMap='true')
   x=myJmsls[0]
   cd(x)

   hiCnt= get('MessagesHighCount')
   currCnt= get('MessagesCurrentCount')
   pendCnt= get('MessagesPendingCount')
   print '%14s   %4d   %4d  %4d  %4d  %4d  %4d' %  (key, curCnt, cHiCnt, cTotCnt,  hiCnt, currCnt, pendCnt) 
  except:
   print 'Exception...in server:', key
   pass
 quit()

def quit():
 d = Date() # now
 print  d
 print 'Hit any key to Re-RUN this script ...'
 Ans = raw_input("Are you sure Quit from WLST... (y/n)")
 if (Ans == 'y'):
  disconnect()
  stopRedirect() 
  exit()
else:
 JmsStat()

if __name__== "main":
 redirect('./logs/jmsCnt.log', 'false')
 conn()
 initalize()
 JmsStat()
Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. #################################################################
  2. # This script will  get the jms attributes
  3. # Author : Prasanna Yalam
  4. # Updated by: Pavan Devarakonda
  5. #################################################################
  6.  
  7. from java.util import Date
  8.  
  9. ucf='ursec'
  10. ukf='urkey'
  11. admurl='t3://url'
  12. urldict={}
  13.  
  14. def conn():
  15. try:
  16.     connect(userConfigFile=ucf, userKeyFile=ukf, url=admurl)
  17. except ConnectionException,e:
  18.     print 'Unable to find admin server...'
  19.     exit()
  20. def initalize():
  21.     serverlist= ['app010','app011',...]
  22.     for svr in serverlist:
  23.     cd("/Servers/"+svr)
  24.     urldict[svr]='t3://'+get('ListenAddress')+':'+str(get('ListenPort'))
  25.  
  26. def JmsStat():
  27.     d = Date() # now
  28.     print  d
  29.  
  30.     print 'Instance         ConCur ConHi ConTot High  MsgCur MsgPnd'
  31.     print 'Name             Count  Count Count  Count Count  Count'
  32.     print '===========**=======**=================================='
  33.     Ks = urldict.keys()
  34.     Ks.sort()
  35.  
  36.     for key in Ks:
  37.         try:
  38.             connect(userConfigFile=ucf, userKeyFile=ukf,url=urldict[key])
  39.             serverRuntime()
  40.             cd('JMSRuntime/'+key+'.jms/JMSServers')
  41.             curCnt= get('ConnectionsCurrentCount')
  42.             cHiCnt=get('ConnectionsHighCount')
  43.             cTotCnt=get('ConnectionsTotalCount')
  44.  
  45.             myJmsls=ls(returnMap='true')
  46.             x=myJmsls[0]
  47.             cd(x)
  48.  
  49.             hiCnt= get('MessagesHighCount')
  50.             currCnt= get('MessagesCurrentCount')
  51.             pendCnt= get('MessagesPendingCount')
  52.             print '%14s   %4d   %4d  %4d  %4d  %4d  %4d' %  (key, curCnt, cHiCnt, cTotCnt,  hiCnt, currCnt, pendCnt)
  53.         except:
  54.             print 'Exception...in server:', key
  55.             pass
  56.     quit()
  57.  
  58. def quit():
  59.     d = Date() # now
  60.     print  d
  61.     print 'Hit any key to Re-RUN this script ...'
  62.     Ans = raw_input("Are you sure Quit from WLST... (y/n)")
  63.     if (Ans == 'y'):
  64.         disconnect()
  65.         stopRedirect()
  66.         exit()
  67. else:
  68.     JmsStat()
  69.  
  70. if __name__== "main":
  71.     redirect('./logs/jmsCnt.log', 'false')
  72.     conn()
  73.     initalize()
  74.     JmsStat()

Popular Posts