Zabbix---6 监控 端口 连接数
2021-01-08 本文已影响0人
Habit_1027
例如监控80端口和22端口
一、zabbix客户端编写获取端口连接数脚本
[root@localhost sbin]# pwd
/usr/local/sbin
[root@localhost sbin]# cat port_num.sh
#!/bin/bash
netstat -an | grep $1 | grep -c ESTABLISHED
[root@localhost sbin]#
二、添加自定义密钥(监控项里面的‘键值’)
[root@localhost zabbix_agentd.d]# pwd
/etc/zabbix/zabbix_agentd.d
[root@localhost zabbix_agentd.d]# cat port_num.conf
UnsafeUserParameters=1
UserParameter=estab.port80.num,/usr/local/sbin/port_num.sh 80
UserParameter=estab.port22.num,/usr/local/sbin/port_num.sh 22
[root@localhost zabbix_agentd.d]#
三、重启zabbix-agent
[root@localhost zabbix_agentd.d]# systemctl restart zabbix-agent
[root@localhost zabbix_agentd.d]# netstat -lntp | grep zabbix
tcp 0 0 0.0.0.0:10050 0.0.0.0:* LISTEN 26858/zabbix_agentd
tcp 0 0 0.0.0.0:10051 0.0.0.0:* LISTEN 1389/zabbix_server
tcp6 0 0 :::10050 :::* LISTEN 26858/zabbix_agentd
tcp6 0 0 :::10051 :::* LISTEN 1389/zabbix_server
[root@localhost zabbix_agentd.d]#
四、创建模板




五、主机链接模板

查看最新数据

验证一下
[root@localhost sbin]# sh port_num.sh 80
2
[root@localhost sbin]#