Checking the number of database connections
This script checks DB2 database connections. Of couse you can change the threshold to what you think is the most appropriate to your environment.
What | |
---|---|
When |
2010-08-06 17:49
2010-08-06 17:49
2010-08-06 from 17:49 to 17:49 |
Add event to calendar |
vCal iCal |
#!/usr/bin/ksh
##############################################################
# Author: Felipe Alkain de Souza
#
# Script Name: check_db_connections.sh
#
# Functionality: This script checks DB2 database connections
#
# Usage: ./check_db_connections.sh <database_name>
#
##############################################################
. $HOME/sqllib/db2profile
### Nagios RCs Variables
STATE_OK=0
STATE_WARNING=1
STATE_CRITICAL=2
STATE_UNKNOWN=3
db2 connect to $1 > /dev/null 2>&1
if [ $? -ne 0 ]
then
echo "$STATE_CRITICAL&DB2 - The database $1 did not connect!"
exit $STATE_CRITICAL
db2 connect reset
fi
NUMCONN=`db2 list active databases |grep -ip $1 |tail -4|grep "Applications connected currently" |awk -F"= " '{print $2}'`
if [ $NUMCONN -lt 120 ]; then
echo "$STATE_OK&DB2 - The database $1 is healthy now , there are just $NUMCONN connections"
exit $STATE_OK
elif [ $NUMCONN -gt 120 -a $NUMCONN -lt 135 ]; then
echo "$STATE_WARNING&DB2 - The database $1 has $NUMCONN connections, crossing the threshold."
exit $STATE_WARNING
else
echo "$STATE_CRITICAL&DB2 - The database $1 has $NUMCONN connections, crossing the threshold."
exit $STATE_CRITICAL
fi