在zabbix上添加tcp连接数的监控项
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
4、在zabbix web界面添加监控项 配置--主机--创建监控项--填写名称和键值,键值即为tcpconnect_status
![](https://img2020.cnblogs.com/blog/1274745/202004/1274745-20200401111319317-1370565561.png)
5、至此添加完成-添加完成后变成已启用状态,以上就顺利实现了zabbix对tcp连接状态的监控。
![](https://img2020.cnblogs.com/blog/1274745/202004/1274745-20200401111539942-771117430.png)