1、监控tcp状态脚本文件如下
# cat tcp_connections.sh
#!/bin/bash
#scripts for tcp status
function SYNRECV {
/usr/sbin/ss -ant | awk ‘{++s[$1]} END {for(k in s) print k,s[k]}‘ | grep ‘SYN-RECV‘ | awk ‘{print $2}‘
}
function ESTAB {
/usr/sbin/ss -ant | awk ‘{++s[$1]} END {for(k in s) print k,s[k]}‘ | grep ‘ESTAB‘ | awk ‘{print $2}‘
}
function FINWAIT1 {
/usr/sbin/ss -ant | awk ‘{++s[$1]} END {for(k in s) print k,s[k]}‘ | grep ‘FIN-WAIT-1‘ | awk ‘{print $2}‘
}
function FINWAIT2 {
/usr/sbin/ss -ant | awk ‘{++s[$1]} END {for(k in s) print k,s[k]}‘ | grep ‘FIN-WAIT-2‘ | awk ‘{print $2}‘
}
function TIMEWAIT {
/usr/sbin/ss -ant | awk ‘{++s[$1]} END {for(k in s) print k,s[k]}‘ | grep ‘TIME-WAIT‘ | awk ‘{print $2}‘
}
function LASTACK {
/usr/sbin/ss -ant | awk ‘{++s[$1]} END {for(k in s) print k,s[k]}‘ | grep ‘LAST-ACK‘ | awk ‘{print $2}‘
}
function LISTEN {
/usr/sbin/ss -ant | awk ‘{++s[$1]} END {for(k in s) print k,s[k]}‘ | grep ‘LISTEN‘ | awk ‘{print $2}‘
}
function CLOSED {
/usr/sbin/ss -ant | awk ‘{++s[$1]} END {for(k in s) print k,s[k]}‘ | grep ‘CLOSED‘ | awk ‘{print $2}‘
}
function SYN_SENT {
/usr/sbin/ss -ant | awk ‘{++s[$1]} END {for(k in s) print k,s[k]}‘ | grep ‘SYN_SENT‘ | awk ‘{print $2}‘
}
function CLOSE_WAIT {
/usr/sbin/ss -ant | awk ‘{++s[$1]} END {for(k in s) print k,s[k]}‘ | grep ‘CLOSE_WAIT‘ | awk ‘{print $2}‘
}
function CLOSING {
/usr/sbin/ss -ant | awk ‘{++s[$1]} END {for(k in s) print k,s[k]}‘ | grep ‘CLOSING‘ | awk ‘{print $2}‘
}
case $1 in
SYNRECV)
SYNRECV
;;
ESTAB)
ESTAB
;;
FINWAIT1)
FINWAIT1
;;
FINWAIT2)
FINWAIT2
;;
TIMEWAIT)
TIMEWAIT
;;
LASTACK)
LASTACK
;;
LISTEN)
LISTEN
;;
CLOSED)
CLOSED
;;
SYN_SENT)
SYN_SENT
;;
CLOSE_WAIT)
CLOSE_WAIT
;;
CLOSING)
CLOSING
;;
*)
exit 1
;;
esac注:其实不一样非要监控所有的状态,其实只监控自己关心的即可,不需要的可以吧脚本内容case下面的选项注释即可
2、userparameter_tcp配置文件,以及重启zabbix-agent服务即可。。
# cat userparameter_tcp.conf UserParameter=tcp.status[*],/bin/bash /etc/zabbix/scripts/tcp_connections.sh $1
3、 导入模板,然后主机连接到tcp模板。稍等片刻查看状态信息
有啥问题记得看l提示和log,恩,先这样。
本文出自 “村里的男孩” 博客,请务必保留此出处http://noodle.blog.51cto.com/2925423/1811703
原文地址:http://noodle.blog.51cto.com/2925423/1811703