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
- It will find all the running servers registered with DMGR (cell) and take a list of running connection pools targeted on those servers.
- It will automatically set 80 percent of the connection max_limit as a threshold.
- 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
- 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)
- If you have Autosys, you can rather schedule it with JIL and run this in a periodic interval.
- 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
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/

I have updated the new version of code. hope it helps.
ReplyDeleteI have tried this , but the script runs without any error but there is no output nor even the timestamp for the output file changes, could you please publish a simpler form of this , which prints the stats on screen.
ReplyDeleteI have tried this , but the script runs without any error but there is no output nor even the timestamp for the output file changes, could you please publish a simpler form of this , which prints the stats on screen.
ReplyDelete