zabbix监控之redis自动发现并监控
部分资料来源于网上,这里一并谢过。
系统版本centos5.10
python版本2.4.3
1、python支持
yum -y install python-simplejson
2、discovery脚本
[root@localhost etc]# cat redis_port.py
#!/usr/bin/env python import os #import json import simplejson as json #特别要注意的地方 t=os.popen("""sudo netstat -tlpn |grep codis-server|grep 0.0.0.0|awk ‘{print $4}‘|awk -F: ‘{print $2}‘ """) ports = [] for port in t.readlines(): r = os.path.basename(port.strip()) ports += [{‘{#REDISPORT}‘:r}] print json.dumps({‘data‘:ports},sort_keys=True,indent=4,separators=(‘,‘,‘:‘))
3,、试执行脚本
[root@localhost etc]# python redis_port.py
{
"data":[
{
"{#REDISPORT}":"6379"
}
]
}
4,zabbix_agent设置
[root@localhost ~]# tail -n 2 /usr/local/zabbix/etc/zabbix_agentd.conf
UserParameter=redis.discovery,/usr/local/zabbix/etc/redis_port.py
UserParameter=redis_stats[*],redis-cli -h 127.0.0.1 -a redis_passwd -p $1 info|grep $2|cut -d : -f2
[root@localhost ~]# chmod a+x /usr/local/zabbix/etc/redis_port.py
5,sudo权限
[root@localhost ~]# tail -n 1 /etc/sudoers
zabbix ALL=(root) NOPASSWD:/bin/netstat
[root@localhost ~]# sed -i ‘s/^Defaults.*.requiretty/#Defaults requiretty/‘ /etc/sudoers
[root@localhost ~]# grep requiretty /etc/sudoers
#Defaults requiretty
# changed in order to be able to use sudo without a tty. See requiretty above.
6,服务端验证
[root@zabbixserver-nginx ~]# zabbix_get -s 172.17.2.114 -k redis.discovery
{
"data":[
{
"{#REDISPORT}":"6379"
}
]
}
[root@zabbixserver-nginx ~]# zabbix_get -s 172.17.2.114 -k redis_stats[6379,used_memory:]
651534360
[root@zabbixserver-nginx ~]# zabbix_get -s 172.17.2.114 -k "redis_stats[6379,blocked_clients]"
0
7,zabbix web界面导入下载的模板,添加监控项后检查监控图像
redis模板见附件
本文出自 “jerrymin” 博客,请务必保留此出处http://jerrymin.blog.51cto.com/3002256/1675728
原文地址:http://jerrymin.blog.51cto.com/3002256/1675728