Search This Blog

Monday, May 31, 2010

JDBC datasource monitoring

"JDBC Monitoring" script, which I was published 2 days back works good for simple single data source and also multi datasources on a domain. But, there is an inadquate information about targeted servers that script doesn't have the flexibility for displaying those managed server mapping with a DataSource.

One of blog follower(Mr. Venkatesh Durai) asked me for the same, A script works for managed server wise display for the Datasource performance monitoring with WLST. It was already discussed by Srikanth Sonti and Vijay Bheemaneni in Oracle WLST ORKUT forums.


Orkut link
Here we go with the latest script, HTH scriptors...

#========================================================
# ScriptFile: DSMonitor.py 
# Author : Pavan Devarakonda
# Purpose : Multi Datasource monitoring with Server wise
#========================================================
urldict={}
def conn():
try:
    print 'Connecting to Admin server....'
    connect(username, password, adminurl)
except:
    print 'Admin Server NOT in RUNNING state....'


def initialize():
    conn()
    try:
        serverlist=['app01','app02','app03'...]
        for s in serverlist:
            cd("/Servers/"+s)
            urldict[s]='t3://'+get('ListenAddress')+':'+str(get('ListenPort'))
            JDBCStat()
     except:
          print 'issue in accessing JDBC Pool'

def printline():
    print '------------------------------------------------------------'

def printHeadr():
    print 'JDBC CONNECTION POOLS STATISTICS'
    print ' '
    print 'Name      Max      Active  Active   WaitSecs Waiting  State'
    print '          capacity Current HighCnt  HighCnt  Count'
    printline()

def getJDBCDetails():
    pname=get("Name")
    pmcapacity=get("CurrCapacityHighCount")
    paccc = get("ActiveConnectionsCurrentCount")
    pachc = get("ActiveConnectionsHighCount")
    pwshc = get("WaitSecondsHighCount")
    pwfccc = get("WaitingForConnectionCurrentCount")
    pstate = get("State")
    print '%10s %7d %7d %7d %7d %7d %10s' % (pname,pmcapacity,paccc,pachc, pwshc,pwfccc,pstate)
    print ' '

def JDBCStat():
    Ks = urldict.keys()
    Ks.sort()
    printHeadr() 
    for s in Ks:
    try:
        connect(user, passwd,urldict[s])
        serverRuntime()
        cd('JDBCServiceRuntime/'+s+'/JDBCDataSourceRuntimeMBeans/')
        print ' '+s
        printline()
        DSlist=ls(returnMap='true')
        for ds in DSlist:
            cd(ds)
            getJDBCDetails()
            cd('..')
    except:
 #pass
        print 'Exception'
        quit()

def quit():
    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()
    else:
        JDBCStat() 

if __name__== "main":
    redirect('./logs/JDBCCntwlst.log', 'false')
    initialize()
    print 'done'




How to run this Script??
Recently one of my blog follower wrote to me " What is the right way for running this monitoring scripts?". Here I am editing my blogs for more readable and flexible for novice WLA.

You need to update with your environment details at line 5, 11, 14. Create this script in a separate folder where you should maintain logs folder, this is expected by line 67.

To run the above script you need to use regular WLST invoking command as follows:
prompt> java weblogic.WLST DSMonitor.py

This is universal way of running WLST I mean on UNIX flavours, on Windows, on Mac OS too.

12 comments:

  1. Hi Pavan, i'm a novice in WLST and trying to understand your py file. I tried various ways but i could not even get my Admin server connected with this DSMonitor.py file.
    I'm getting syntax errors at 'connect' command itself. Am i doing anything wrong ?

    Per your comments i filled all the required credentials where i need to enter my user, paswd and admin URL. Please advise

    ReplyDelete
  2. Dear Novice WLST user,
    You can try any command at your WLST command prompt as a trial. connect() command will makes you to turn from offline to online mode of WLST.
    OSPROMPT> setWLSEnv.sh for UNIX/ setWLSEnv.cmd for Windows
    OSPROMPT> java weblogic.WLST
    After you get WLST prompt you try connect() command assuming user as system, password as weblogic10 and adminurl as t3://localhost:8001 then the command will be given as shown as below
    wls:/offline> connect('system','weblogic10','t3://localhost:8001')

    ReplyDelete
  3. Pavan, my problem is when i'm running the WLST in script mode - in this way

    java weblogic.WLST DSMonitor.py

    ReplyDelete
  4. You need to replace your WebLogic credentials and adminurl in the 10th line. Even this is not helping... send me screen shot of ur window, and your customized script to bhavanishekhar@gmail.com

    ReplyDelete
  5. This comment has been removed by the author.

    ReplyDelete
  6. Hi Pavan,

    This is Srini.. Thanks a lot for your script and time,
    I just want to get the state of DS, what are things i need to change in above script?

    ReplyDelete
  7. hi srini,

    Thanks for visiting the blog, may be you didn't see the last section it is clearly mentioned what lines you need to change. please go thru that section "How to run this Script??"

    ReplyDelete
  8. Hi Pavan,

    Thanks for your reply.

    Yeah, i have changed those lines and tried to run the script .. but i am run the script.. i am seeing Syntax errors for try & except lines..
    have you seen this type of error ??

    ReplyDelete
  9. Hi Bhavani greetings of the day.
    Excellent blog ...

    Regards
    Santosh

    ReplyDelete
    Replies
    1. Hi Bhavani,

      i want WLST to Script check Status on Datasource connections on all the domains - if one of them fails it should send out an email for our team
      Script check Status on Bridges in AQ Domain - if one of them fails it should send out an email for out team

      Delete
  10. Hi Pavan,

    I am getting below after execution.
    java weblogic.WLST DSMonitor.py

    Initializing WebLogic Scripting Tool (WLST) ...

    Welcome to WebLogic Server Administration Scripting Shell

    Type help() for help on available commands

    Problem invoking WLST - Traceback (innermost last):
    (no code object) at line 0
    File "path/mani/DSMonitor.py", line 1
    ========================================================
    ^
    SyntaxError: invalid syntax

    ReplyDelete
  11. Hi Pavan,
    Thanks For writing such a good script.
    I was new to weblogic, I refered your script and resolved my issue.
    Its a very good reference.

    ReplyDelete

Please write your comment here

Popular Posts