1、在客户端编写监控tcp连接状态的脚本,并放在自定义位置。
[root@node root]# vim /home/zabbix/scripts/tcp_connection_status_count.sh #!/bin/bash SYNRECV(){ a=`/usr/sbin/ss -ant | awk '{++s[$1]} END {for(k in s) print k,s[k]}' | grep 'SYN-RECV' | awk '{print $2}'` if test -z "$a" then echo 0 else echo $a fi } ESTAB(){ a=`/usr/sbin/ss -ant | awk '{++s[$1]} END {for(k in s) print k,s[k]}' | grep 'ESTAB' | awk '{print $2}'` if test -z "$a" then echo 0 else echo $a fi } TIMEWAIT(){ a=`/usr/sbin/ss -ant | awk '{++s[$1]} END {for(k in s) print k,s[k]}' | grep 'TIME-WAIT' | awk '{print $2}'` if test -z "$a" then echo 0 else echo $a fi } TOTAL(){ a=`/usr/sbin/ss -ant | awk 'BEGIN{t=0;} { t++; } END{print t; }'` if test -z "$a" then echo 0 else echo $a fi } $1 [root@node root]# chmod +x /home/zabbix/scripts/tcp_connection_status_count.sh
2、在客户端中修改zabbix-agentd服务配置文件
[root@node root]# vim /home/zabbix/etc/zabbix_agentd.conf.d/check_tcp_status.conf UserParameter=synrecv,/home/zabbix/scripts/check_tcp_status.sh SYNRECV UserParameter=estab,/home/zabbix/scripts/check_tcp_status.sh ESTAB UserParameter=timewait,/home/zabbix/scripts/check_tcp_status.sh TIMEWAIT UserParameter=total,/home/zabbix/scripts/check_tcp_status.sh TOTAL
3、重启zabbix-agent
####重启脚本 [root@node root]# vim /home/zabbix/zabbix_restart.sh ps aux |grep zabbix_agentd if [[ $? -eq 0 ]];then echo "项目检测到项目运行正在重启''''" killall zabbix_agentd sleep 3 fi ps aux |grep zabbix_agentd if [[ $? -ne 0 ]];then echo "已经停止" sleep 3 fi /home/zabbix/sbin/zabbix_agentd if [[ $? -eq 0 ]];then echo "正在启动" sleep 3 fi ps aux |grep zabbix_agentd if [[ $? -eq 0 ]];then echo "已经启动" fi [root@node root]# chmod +x /home/zabbix/zabbix_restart.sh [root@node root]# /home/zabbix/zabbix_restart.sh