me小怪兽

导航

zabbix监控tcp连接数脚本

1、添加脚本
[root@localhost]# vim /etc/zabbix/zabbix_agent2.d/plugins.d/check_tcp.sh #!/bin/bash NAME=$1 function LISTEN { netstat -an |grep 'LISTEN'|grep tcp |wc -l } function ESTABLISHED { netstat -an |grep 'ESTABLISHED'|grep tcp |wc -l } function TIME_WAIT { netstat -an |grep 'TIME_WAIT'|grep tcp |wc -l } case $NAME in listen) LISTEN ;; established) ESTABLISHED ;; time_wait) TIME_WAIT ;; *) echo -e "Usage: $0 [listen | established | time_wait]" esac

2、获取参数

[root@localhost plugins.d]# chmod +x check_tcp.sh
[root@localhost plugins.d]# sh check_tcp.sh 
Usage: check_tcp.sh [listen | established | time_wait]
[root@localhost plugins.d]# sh check_tcp.sh listen
44
[root@localhost plugins.d]# sh check_tcp.sh established
1050
[root@localhost plugins.d]# sh check_tcp.sh time_wait
526

3、添加子配置文件

[root@localhost plugins.d]# vim /etc/zabbix/zabbix_agent2.d/plugins.d/tcp.conf 
UserParameter=tcp.[*],/etc/zabbix/zabbix_agent2.d/plugins.d/check_tcp.sh $1

4、重启

[root@localhost plugins.d]# systemctl restart zabbix-agent2.service 

5、新建模版

6、依次添加剩余的键值

 

 

 7、主机添加模版

 

 

 8、等待片刻,观察数据

 

posted on 2023-03-31 16:51  me小怪兽  阅读(148)  评论(0编辑  收藏  举报