#!/bin/sh # -*- sh -*- : << =cut =head1 NAME tcpstates - Plugin to monitor TCP socket states =head1 CONFIGURATION No configuration =head1 AUTHOR Babak Farrokhi Modified by Mark Saad =head1 LICENSE BSD 2-Clause License =head1 BUGS =head1 MAGIC MARKERS #%# family=auto #%# capabilities=autoconf =cut . $MUNIN_LIBDIR/plugins/plugin.sh print_cfg() { fname=$1 fdesc=`echo $1 | tr [:lower:] [:upper:]` echo "$fname.label $fdesc" echo "$fname.min 0" echo "$fname.max 50000" echo "$fname.info The number of sockets in $fdesc state" print_warning $fname print_critical $fname } if [ "$1" = "autoconf" ]; then if ( /usr/bin/netstat -s 2>/dev/null >/dev/null ); then echo yes exit 0 else if [ $? -eq 127 ] then echo "no (netstat program not found)" exit 0 else echo no exit 0 fi fi fi if [ "$1" = "config" ]; then echo 'graph_title TCP Socket States' echo 'graph_args --base 1000' echo 'graph_vlabel TCP states per ${graph_period}' echo 'graph_category network' echo 'graph_period second' echo 'graph_info This graph shows the TCP activity of all the network interfaces combined.' for f in syn_sent listen time_wait closing closed last_ack fin_wait_1 fin_wait_2 close_wait do print_cfg $f done exit 0 else netstat -an -p tcp -f inet | awk '$NF ~ /[A-Z]/ {print $NF}'|awk ' BEGIN{ estab = "0"; syn_sent = "0"; listen = "0"; time_wait = "0"; closing = "0"; closed = "0"; last_ack = "0"; fin_wait_1 = "0"; fin_wait_2 = "0"; close_wait = "0"; } /ESTABLISH/ { estab=estab+1 } /SYN_SENT/ { syn_sent=syn_sent+1 } /LISTEN/ { listen=listen+1 } /TIME_WAIT/ { time_wait=time_wait+1 } /CLOSING/ { closing=closing+1 } /CLOSED/ { closed=closed+1 } /LAST_ACK/ { last_ack=last_ack+1 } /FIN_WAIT_1/ { fin_wait_1=fin_wait_1+1 } /FIN_WAIT_2/ { fin_wait_2=fin_wait_2+1 } /CLOSE_WAIT/ { close_wait=close_wait+1 } END{ print "ESTABLISH.value " estab; print "SYN_SENT.value " syn_send; print "LISTEN.value " listen; print "TIME_WAIT.value " time_wait; print "CLOSING.value " closing; print "CLOSED.value " closed; print "LAST_ACK.value " last_ack; print "FIN_WAIT_1.value " fin_wait_1; print "FIN_WAIT_2.value " fin_wait_2; print "CLOSE_WAIT.value " close_wait; } ' fi