wge thttps://pypi.python.org/packages/source/r/redis/redis-2.9.1.tar.gz python
tar xf redis-2.9.1.tar.gz redis
cd redis-2.9.1 bash
python setup.py installide
(1) 將zabbix-redis.py 放入到/usr/local/zabbix/etc/scripts目錄下 spa
(2) 更改zabbix_agentd.conf include${dir}/zabbix.UserParameter 操作系統
(3) 重啓zabbix_agentd code
killall zabbix_agentd ip
/usr/local/zabbix/sbin/zabbix_agentd -c/usr/local/zabbix/etc/zabbix_agentd.conf內存
客戶端查詢key值命中數和未命中數,可計算出命中率 utf-8
當前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: root.db.root@gmail.com 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