Script to monitor the TCP Send-Queue.
Send-Q is retrived from the netstat cmd. ex.:
#netstat -anp |more
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
The script syntax example:
#check_sendq -w 900 -c 1000 -f
CRITICAL – Total = 1530 items in TCP Send-Q and 33 MB|sendq_items=1530
#!/bin/bash #Get current Send-Q number of connections #Version 1.0 #By Felipe Ferreira October 2012 # Exit codes STATE_OK=0 STATE_WARNING=1 STATE_CRITICAL=2 STATE_UNKNOWN=3 STATE_DEPENDENT=4 #Variables port=8080 maxconwarn=10 maxconcrti=30 perfdata=0 total=0 totalcnt=0 MB=0 KB=0 #Check arguments print help if [ $# -lt 1 ]; then echo "Usage: $0 [-w|--warning] [-c|--critical ] -f(for perdata)" exit $STATE_UNKNOWN fi #GET ARGUMENTS while test -n "$1"; do case "$1" in --help) echo "Uso: $0 [-w|--warning ] [-c|--critical ] -f(for perdata)" exit $STATE_OK ;; -h) echo "Uso: $0 [-w|--warning ] [-c|--critical ] -f(for perdata)" exit $STATE_OK ;; --warning) maxconwarn=$2 shift ;; -w) maxconwarn=$2 shift ;; --critical) maxconcrit=$2 shift ;; -c) maxconcrit=$2 shift ;; -f) perfdata=1 ;; -perfdata) perfdata=1 ;; esac shift done result=`/bin/netstat -an |/bin/awk '{print $3}' |/bin/grep -e ^[2-9]` for line in $result; do total=`echo "$total+$line" | bc -q`; totalcnt=`echo "$totalcnt+1" | bc -q`; done MB=$(($total / 2**20)) KB=$(($total / 2**10)) if ( [ $MB -eq 0 ] && [ $KB -ne 0 ]) then MSG="Total = $totalcnt items in TCP Send-Q and $KB KB" elif [ $KB -eq 0 ] then MSG="Total = $totalcnt items in TCP Send-Q and $total Bytes" else MSG="Total = $totalcnt items in TCP Send-Q and $MB MB" fi if [ $totalcnt -ge $maxconwarn ]; then OUTPUT="WARNING - $MSG" exitstatus=$STATE_WARNING fi if [ $totalcnt -ge $maxconcrit ]; then OUTPUT="CRITICAL - $MSG" exitstatus=$STATE_CRITICAL fi if [ $totalcnt -lt $maxconwarn ];then OUTPUT="OK - $MSG" exitstatus=$STATE_OK fi if [ $perfdata -eq 1 ]; then OUTPUT="$OUTPUT|sendq_items=$totalcnt" fi echo $OUTPUT exit $exitstatus