#!/bin/bash
##获取80端口并发连接数
netstat -ant |grep ':80 ' |grep -c ESTABLISHED
UnsafeUserParameters=1 //表示使用自定义脚本
UserParameter=my.estab.count[*],/usr/local/sbin/estab.sh
//自定义监控项的key为my.estab.count,后面的[*]里面写脚本的参数,如果没有参数则可以省略,脚本为/usr/local/sbin/estab.sh
[root@hf-02 ~]# vim /usr/local/sbin/estab.sh
#!/bin/bash
##获取80端口并发连接数
netstat -ant |grep ':80 ' |grep -c ESTABLISHED
保存退出
B机器
[root@hf-02 ~]# chmod 755 /usr/local/sbin/estab.sh
[root@hf-02 ~]#
B机器
[root@hf-02 ~]# vim /etc/zabbix/zabbix_agentd.conf
搜索 /UnsafeUserParameters
将# UnsafeUserParameters=0
改为UnsafeUserParameters=1
#目的是使用自定义脚本
搜索 /UserParameter
将# UserParameter=
改为UserParameter=my.estab.count[*],/usr/local/sbin/estab.sh
#表示自定义监控项的key为my.estab.count,后面的[*]里面写脚本的参数,如果没有参数则可以省略,如果有参数写入到 [ ] 里面,用逗号分隔,脚本为/usr/local/sbin/estab.sh
保存退出
B机器
[root@hf-02 ~]# systemctl restart zabbix-agent
[root@hf-02 ~]#
A机器
[root@hf-01 ~]# zabbix_get -s 192.168.202.131 -p 10050 -k 'my.estab.count'
0
[root@hf-01 ~]#