当前位置: 首页 > OpenSource > 正文

learn shell check_tcpconn.sh from nagios

#check_tcpconn.sh
# warning value
W=1500
# critical value
C=2190
if [ -f /proc/net/tcp6 ]
        then
                TCP_FILE6=”/proc/net/tcp6″
fi
if [ -f /proc/net/tcp ]
        then
                TCP_FILE=”/proc/net/tcp”
fi
cat $TCP_FILE6 $TCP_FILE > /tmp/tcpstat
awk -v TOTAL_W=”$W” -v TOTAL_C=”$C” ‘BEGIN{ ESTABLISHED=TIME_WAIT=SYN_RECV=TOTAL=0}
                {if($4 ~/01/) {ESTABLISHED++ ; TOTAL++} else if($4 ~/06/) {TIME_WAIT++; TOTAL++} else if($4 ~/03/) {SYN_RECV++; TOTA
L++} else TOTAL++ }
                END{
                if (TOTAL < TOTAL_W)
                        {printf “OK CONN %s ESTABLISHED  %s TIME_WAIT  %s SYN_RECV  %s  TOTAL|CONN,%s,%s,%s,%s;”,ESTABLISHED,TIME_WA
IT,SYN_RECV,TOTAL,ESTABLISHED,TIME_WAIT,SYN_RECV,TOTAL ; exit 0}
                else if (TOTAL < TOTAL_C)
                        {printf “WARNING CONN %s ESTABLISHED  %s TIME_WAIT  %s SYN_RECV  %s  TOTAL|CONN,%s,%s,%s,%s;”,ESTABLISHED,TI
ME_WAIT,SYN_RECV,TOTAL,ESTABLISHED,TIME_WAIT,SYN_RECV,TOTAL ; exit 0}
                else
                        {printf “CRITICAL CONN %s ESTABLISHED  %s TIME_WAIT  %s SYN_RECV  %s  TOTAL|CONN,%s,%s,%s,%s;”,ESTABLISHED,T
IME_WAIT,SYN_RECV,TOTAL,ESTABLISHED,TIME_WAIT,SYN_RECV,TOTAL ; exit 0}

                }’ /tmp/tcpstat

this script check  /proc/net/tcp , u can find tcp connect status  .

cat /proc/net/tcp
enum {
  TCPF_ESTABLISHED = (1 << 1),
  TCPF_SYN_SENT  = (1 << 2),
  TCPF_SYN_RECV  = (1 << 3),
  TCPF_FIN_WAIT1 = (1 << 4),
  TCPF_FIN_WAIT2 = (1 << 5),
  TCPF_TIME_WAIT = (1 << 6),
  TCPF_CLOSE     = (1 << 7),
  TCPF_CLOSE_WAIT = (1 << 8),
  TCPF_LAST_ACK  = (1 << 9),
  TCPF_LISTEN    = (1 << 10),A
  TCPF_CLOSING   = (1 << 11),B
};

本文固定链接: http://2hei.net/learn_shell_check_tcpconnsh_fr.html | 2hei's site

该日志由 2hei 于2008年08月25日发表在 OpenSource 分类下,
原创文章转载请注明: learn shell check_tcpconn.sh from nagios | 2hei's site
关键字:

报歉!评论已关闭.