wge thttps://pypi.python.org/packages/source/r/redis/redis-2.9.1.tar.gz
tar xf redis-2.9.1.tar.gz
cd redis-2.9.1
python setup.py install
(1) 将zabbix-redis.py 放入到/usr/local/zabbix/etc/scripts目录下
(2) 更改zabbix_agentd.conf include${dir}/zabbix.UserParameter
(3) 重启zabbix_agentd
killall zabbix_agentd
/usr/local/zabbix/sbin/zabbix_agentd -c/usr/local/zabbix/etc/zabbix_agentd.conf
客户端查询key值命中数和未命中数,可计算出命中率
当前redis实例的客户端连接数
当前处于阻塞状态下的客户端数量
客户端每秒执行命令的频率
连接从库的数量
内存使用状况
keyspace_misses //表示未命中数
keyspace_hits //表示命中数
keyspace_hits_rate = keyspace_hits /(keyspace_hits + keyspace_misses)
connected_clients //客户端连接数
blocked_clients //客户端阻塞数
connected_slaves //从库数
instantaneous_ops_per_sec //客户端每秒执行命令频率
used_memory_rss //操作系统分配给redis的内存
used_memory //redis分配器分配的内存
mem_fragmentation_ratio //内存碎片比例 在理想情况下,
used_memory_rss 的值应该只比 used_memory 稍微高一点儿。当rss > used ,且两者的值相差较大时,表示存在(内部或外部的)内存碎片。 当used > rss时,表示Redis的部分内存被操作系统换出到交换空间了,在这种情况下,操作可能会产生明显的延迟。
cat zabbix-redis.py
#!/usr/bin/env python #coding:utf-8 #Author yujianglei Mail: [email protected] QQ: 1074841124 import redis import sys keyindex = ['used_memory', 'used_memory_rss', 'mem_fragmentation_ratio', 'blocked_clients', 'connected_clients', 'connected_slaves', 'instantaneous_ops_per_sec', 'keyspace_hits', 'keyspace_misses', 'keypace_query_total_count', 'keyspace_hits_rate', 'status'] returnval = None def zabbix_faild(): print "ZBX_NOTSUPPORTED" sys.exit(2) if len(sys.argv) != 2 : zabbix_faild() try: conn=redis.Redis(host='192.168.0.140',port='46379',password='bjjd120xunishijie') except Exception, e: zabbix_faild() if sys.argv[1] in keyindex: if sys.argv[1] == 'status': try: conn.ping() returnval = 1 except Exception,e: returnval = 0 elif sys.argv[1] == 'keyspace_hits_rate': merit = conn.info() keyspace_hits_count = float(merit['keyspace_hits']) keyspace_misses_count = float(merit['keyspace_misses']) keyspace_hits_rate = keyspace_hits_count / (keyspace_hits_count + keyspace_misses_count) * 100 returnval = keyspace_hits_rate elif sys.argv[1] == 'keypace_query_total_count': merit = conn.info() keyspace_hits_count = merit['keyspace_hits'] keyspace_misses_count = merit['keyspace_misses'] keypace_query_total_count = keyspace_hits_count + keyspace_misses_count returnval = keypace_query_total_count else: merit = conn.info() try: returnval = merit[unicode(sys.argv[1])] except Exception,e: pass if returnval == None: zabbix_faild() else: print returnval
cat zabbix.UserParameter
#zabbix-redis-python UserParameter=redis_python[*],/etc/zabbix/scripts/zabbix-redis.py $1