系统版本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模板下载见下:
------------------------------------------分割线------------------------------------------
免费下载地址在 http://linux.linuxidc.com/
用户名与密码都是www.linuxidc.com
具体下载目录在 /2015年资料/7月/19日/Zabbix监控之Redis自动发现并监控/
下载方法见 http://www.linuxidc.com/Linux/2013-07/87684.htm
------------------------------------------分割线------------------------------------------
Ubuntu 14.04下Redis安装及简单测试 http://www.linuxidc.com/Linux/2014-05/101544.htm
Redis集群明细文档 http://www.linuxidc.com/Linux/2013-09/90118.htm
Ubuntu 12.10下安装Redis(图文详解)+ Jedis连接Redis http://www.linuxidc.com/Linux/2013-06/85816.htm
Redis系列-安装部署维护篇 http://www.linuxidc.com/Linux/2012-12/75627.htm
CentOS 6.3安装Redis http://www.linuxidc.com/Linux/2012-12/75314.htm
Redis安装部署学习笔记 http://www.linuxidc.com/Linux/2014-07/104306.htm
Redis配置文件redis.conf 详解 http://www.linuxidc.com/Linux/2013-11/92524.htm
Redis 的详细介绍:请点这里
Redis 的下载地址:请点这里
本文永久更新链接地址:http://www.linuxidc.com/Linux/2015-07/120138.htm