计算每秒命中率,这里脚本获取到底是当前命中率,模板中可调试
这里的命中率需要命中才会计算才会有值
[root@c7-test scripts]# cat redis_hits.sh
#!/bin/bash
# -------------------------------------------------------------------------------
# -------------------------------------------------------------------------------
# Notice
# redis Take hits
# is scripts Take hits hits/(hits+misses)
#################################################################################
#REDISPORT=$1
/usr/local/bin/redis-cli -h 127.0.0.1 -p $1 info > /tmp/redis-$1-info.txt
hits=`awk -F ":" "/keyspace_hits/{print $2}" /tmp/redis-$1-info.txt`
misses=`awk -F ":" "/keyspace_misses/{print $2}" /tmp/redis-$1-info.txt`
a=$hits
#a=14414110
#b=3228654
b=$misses
c=`awk "BEGIN{a=$a;b=$b;print "$a+$b"}"`
awk "BEGIN{c=$c;a=$a;print "$a/$c*100"}"
#awk "{a[NR]=$2;b[NR]=$1;s+=$1}END{for (j=1;j<=NR;j++) printf "%s %.2f%\n",a[j],b[j]*100/s}"
这里是自动发现端口
[root@c7-test scripts]# cat redis-port.py
#!/usr/bin/env python
# -------------------------------------------------------------------------------
# -------------------------------------------------------------------------------
# Notice
# redis auto Discovery port
# is scripts Use ps to view the output port after .json format
#################################################################################
import os
import json
t=os.popen("""ps -ef|grep redis-server|grep -v grep|awk -F"(:| )+" "{print $13}" """)
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=(",",":"))
UserParameter设置:
UserParameter=redis_port,/etc/zabbix/scripts/redis-port.py
UserParameter=redis_info[*],/usr/bin/redis-cli -h 127.0.0.1 -p $1 info |awk -F":" "/$2\>/{print $$2}"
UserParameter=redis_hits[*],/etc/zabbix/scripts/redis_hits.sh $1 $2
[zabbix监控原理]zabbix自动发现监控redis多实例的应用
http://m.bbyears.com/shujuku/109256.html
推荐访问:zabbix可以监控什么 zabbix监控交换机