Created
April 11, 2012 02:44
-
-
Save khill/2356503 to your computer and use it in GitHub Desktop.
Shell script to query connection pool usage on JBoss and flush the JDBC pool if limit is exceeded
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| # | |
| # Script to check the number of connections in a JBoss connection pool via JMX and | |
| # invoke flush() if the connection count is over a certain limit | |
| # | |
| JBOSS_HOME=/apps/jboss-eap-4.3/jboss-as | |
| JBOSS_USER=admin | |
| JBOSS_PASSWORD=secret1 | |
| JDBC_POOL_MBEAN="jboss.jca:service=ManagedConnectionPool,name=example_ds" | |
| JBOSS_URL=fenris.khill.org:1099 | |
| JBOSS_INSTANCE_NAME=development | |
| MAX_CONN_COUNT=100 | |
| CONN_COUNT=`$JBOSS_HOME/bin/twiddle.sh --server=$JBOSS_URL -u $JBOSS_USER -p $JBOSS_PASSWORD get $JDBC_POOL_MBEAN InUseConnectionCount | cut -d "=" -f 2` | |
| if [ $CONN_COUNT -ge $MAX_CONN_COUNT ]; then | |
| echo "Connection pool has exceeded maximum size!" | |
| # invoke a thread dump | |
| kill -3 `ps auxw | grep java | grep $JBOSS_INSTANCE_NAME | grep -v grep | awk '{print $2}'` | |
| # wait a bit and take another dump | |
| echo "Sleeping for 10 seconds before second thread dump..." | |
| sleep 10 | |
| kill -3 `ps auxw | grep java | grep $JBOSS_INSTANCE_NAME | grep -v grep | awk '{print $2}'` | |
| echo "Thread dumps completed. Flushing JDBC connection pool..." | |
| # flush the JDBC Pool | |
| $JBOSS_HOME/bin/twiddle.sh --server=$JBOSS_URL -u $JBOSS_USER -p $JBOSS_PASSWORD invoke $JDBC_POOL_MBEAN flush | |
| echo "Recovery complete" | |
| else | |
| echo "Connection count $CONN_COUNT is within acceptable limits" | |
| fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Do you have the twiddle.sh in the github?