编写脚本并设置键值
监控脚本
[root@localhost ~]# cat /etc/zabbix/scripts/mongodb.sh #!/bin/bash index=$(echo $@ | tr " " ".") status=$(echo "db.serverStatus().${index}" |/usr/bin/mongo --quiet admin)
##mongo指定特定端口和设置密码验证,如下格式
##status=$(echo "db.serverStatus().${index}" |/usr/bin/mongo -uroot -ppassword --port 17017 --quiet admin) if [[ "$status" =~ "NumberLong" ]];then echo $status|sed -n 's/NumberLong(//p'|sed -n 's/)//p' else echo $status fi
[root@localhost ~]# chmod u+x /etc/zabbix/scripts/mongodb.sh //设置权限
设置键值
注:yum安装zabbix的话agent默认配置文件为/etc/zabbix/zabbix_agentd.conf
[root@localhost ~]# cat /etc/zabbix/zabbix_agentd.conf |grep conf|grep -v ‘#’ Include=/etc/zabbix/zabbix_agentd.d/*.conf
[root@localhost ~]# cat /etc/zabbix/zabbix_agentd.d/userparameter_mongodb.conf UserParameter=mongodb.status[*],sudo sh /etc/zabbix/scripts/mongodb.sh $1 $2 $3 $4 $5
[root@localhost ~]# visudo
zabbix ALL=(ALL) NOPASSWD:/bin/sh
重启agent
[root@test zabbix_agentd.d]# systemctl restart zabbix-agent
下载模板,并导入模板
模板地址:zbx_mongodb_templates