In this post we are providing WebSphere connection pool monitoring - wsadmin script. Its written in Python/Jython and can be used for WebSphere application server 6+ versions
How the script is designed
- It will find all the running server instances registered with Websphere Application server 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 an alert message, in case of possible connection pool overflow. When the current connection limit reaches the threshold.
Version compatibility
Websphere Application Server 6.1 and above ( for was 6 there is little bit modification required)
The Sourcecode
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 | 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 execute this script?
Save the above code with ".py" extension and run it with wsadmin
.For example
1 | wsadmin.sh -lang jython -username <username> -password <password> -lang jython -f <saved py file name> |
Hope it helps
For more exclusive posts like this in web and middleware technologies. Leave your name and mail id. Trust us, we hate spam like you do.
Thanks
A K S A R A V
Write to us at aksarav@mwinventory.in
Follow us on Facebook or Twitter
To Join our Community in Whatsapp – Click here