|JDBC Monitoring with LWLST script|
Of-course the task is not that easy, I have gone through various WebLogic forums to find a appropriate solution for this task.
Oracle WebLogic provides two ways to Monitor a Datasource
1. Monitoring Datasource server wise
2. Testing the Connection Pool
Here I am publishing the same script which Madan Noru/Satya prepared in the old bea fourms or ObjectMix forums. Only one thing is difference is that displaying pattern, I had created a separate header, so that output looks good to see in a table form. To make this possible I have used C-Style print command from Python Language. This format you can change as per your screen display size.
The script will retrieve the JDBC Connection Pool MBean using adminHome, which is deprecated object in WLST. The output of the script will gives you the values of the following attributes:
- DataSource Name
- Maximum Capacity of the Connection Pool at Run-time
- Active Connections Current Count
- Active Connections High Count
- Wait Seconds High Count
- Waiting For Connection Current Count
- State of the Connection Pool
#======================================================= # This script will monitor the JDBC CONNECTION POOL # more details on this script contact: Pavan Devarkonda #======================================================= connect("username","passwd","t3://AdminIP:AdminPort") try: poolrtlist=adminHome.getMBeansByType('JDBCConnectionPoolRuntime') print ' ' print ' ' print 'JDBC CONNECTION POOLS' print ' ' print 'Name Max Active Active WaitSecs Waiting State' print ' capacity Current HighCnt HighCnt Count' for poolRT in poolrtlist: pname = poolRT.getName() pmaxcapacity = poolRT.getAttribute("MaxCapacity") paccc = poolRT.getAttribute("ActiveConnectionsCurrentCount") pachc = poolRT.getAttribute("ActiveConnectionsHighCount") pwshc = poolRT.getAttribute("WaitSecondsHighCount") pwfccc = poolRT.getAttribute("WaitingForConnectionCurrentCount") pstate = poolRT.getAttribute("State") print '%10s %7d %7d %7d %7d %7d %10s' % (pname,pmaxcapacity,paccc,pachc, pwshc,pwfccc,pstate) print ' ' except: print 'Error:' dumpStack() pass disconnect()
In Year 2012 revisting the same scriptWe have trouble in the produciton environment with JDBC Connection pool overloaded. All the ActiveConnectionCount reaching the MaxCapacity of the Connection pool. As a temprory workaround we need to reset the Connection pool for that movement. Permanent cure is tuning the Connection pool. For both solutions we need active monitoring the JDBC Connection pool.
To monitor this we have revisited the same script. Now adding more saus to the script we need to find that ActiveConnectionCount reaching 85% as threshold limit. Once it reaches 85 or greater then monitoring tool like HP OV/some other tool will reads log file generated by the script and then sends warns message to supporting Middleware Admin when threshold crossed. If you have sendmail service on your machine you can send message fromt he script itself.
To do this we had manupulated the above script according to the requirements
- We have specified DataSource that are causing this trouble
- Used separate properties file for user credentials.
- The output of script is redirected to a file
- Managed Server name opposite to the monitor values it is tricky but resolved The new script is
#======================================================= # This script will monitor the JDBC CONNECTION POOL # Date : 18 Apr 2012 #======================================================= import sys import time try: loadProperties('./DBcheck.properties') fp=open('ActiveConn.log','a+') Date = time.ctime(time.time()) admurl='t3://'+admAdrs+':'+admPort connect(userConfigFile=UCF, userKeyFile=UKEY, url=admurl) poolrtlist=adminHome.getMBeansByType('JDBCConnectionPoolRuntime') print ' ' print 'JDBC CONNECTION POOLS' print>>fp, '================================================ ' for poolRT in poolrtlist: pname = poolRT.getName() pmaxcapacity = poolRT.getAttribute("MaxCapacity") paccc = poolRT.getAttribute("ActiveConnectionsCurrentCount") if pname == 'myDataSource1' or pname == 'myDS2'' or pname == 'myDS3': server= str(poolRT).split(',').split('=') p=(paccc /(pmaxcapacity * 1.0)) * 100 if p >= 85: print >>fp, 'WARNING: The Active connections are Greater than Threshold 85%' print>>fp, '%24s %15s %18s %7d %7d' % (Date,server,pname,pmaxcapacity,paccc) except Exception, e: sys.stderr.write('ERROR: %s\n' % str(e)) print 'Error:', e dumpStack() pass fp.close() disconnect()
Post script actions
- Prepare a Shellscript that will let you know howmuch time it will counsume to run py script.
clear date $JAVA_HOME/bin/java weblogic.WLST /path/urscript/jdbcmon.py date
- Schedule a scheduler to run this script autosys or crontab that invokes above shell script.
- Configure a monitoring tool frequently lookup the logs and send alert messages such as HP OVO or smpt mailing also fine.