通过externalscripts监控redis sentinel的状态,但是只支持监控一个redis集群的sentinel,因为只监控master0,要支持多集群的sentinel的话自己写个返回各个master0-xxx的json格式的脚本,配合自动探索去做吧。
externalscripts 脚本
#cat check_sentinel.sh #放在externalscripts路径下,zabbix用户可执行
#!/bin/baship=$1port=$2check=$3#(echo -en "INFO\r\n";sleep 1)|nc $ip $port if [ $check == "uptime" ] || [ $check == "redisclustername" ] || [ $check == "redisclusterstatus" ] || [ $check == "slavenum" ] || [ $check == "sentinelnum" ] || [ $check == "redismaster" ] thencase $check in uptime)(echo -en "INFO\r\n";sleep 1)|nc $ip $port |grep ^uptime_in_seconds:|awk -F: '{print $2}';;redisclustername)(echo -en "INFO\r\n";sleep 1)|nc $ip $port |grep ^master0:name|sed 's/^.*:name=//'|sed 's/,status=.*$//';;redisclusterstatus)(echo -en "INFO\r\n";sleep 1)|nc $ip $port |grep ^master0:name|sed 's/^.*,status=//'|sed 's/,address=.*$//';;slavenum)(echo -en "INFO\r\n";sleep 1)|nc $ip $port |grep ^master0:name|sed 's/^.*slaves=//'|sed 's/,sentinels=.*$//';;sentinelnum)(echo -en "INFO\r\n";sleep 1)|nc $ip $port |grep ^master0:name|sed 's/^.*sentinels=//';;redismaster)(echo -en "INFO\r\n";sleep 1)|nc $ip $port |grep ^master0:name|sed 's/^.*,address=//'|sed 's/,slaves.*$//';;esacelseecho "not support $3."&&exit 1fi
监控模板如下
导出的zabbix模板
2.0 2016-04-01T07:17:19Z Templates template redis sentinel template redis sentinel Templates sentinel check redis sentinel $2 port 26379 3 0 net.tcp.service[tcp,{IPADDRESS},26379] 60 90 365 0 3 0 0 0 0 1 0 0 0 sentinel redis sentinel $1 redis cluster name 10 0 check_sentinel.sh[{IPADDRESS},26379,redisclustername] 60 90 365 0 4 0 0 0 0 1 0 0 0 sentinel redis sentinel $1 redis cluster status 10 0 check_sentinel.sh[{IPADDRESS},26379,redisclusterstatus] 60 90 365 0 4 0 0 0 0 1 0 0 0 sentinel redis sentinel $1 redis master 10 0 check_sentinel.sh[{IPADDRESS},26379,redismaster] 60 90 365 0 4 0 0 0 0 1 0 0 0 sentinel redis sentinel $1 sentinel num 10 0 check_sentinel.sh[{IPADDRESS},26379,sentinelnum] 60 90 365 0 3 s 0 0 0 0 1 0 0 0 sentinel redis sentinel $1 slave num 10 0 check_sentinel.sh[{IPADDRESS},26379,slavenum] 60 90 365 0 3 0 0 0 0 1 0 0 0 sentinel redis sentinel $1 uptime 10 0 check_sentinel.sh[{IPADDRESS},26379,uptime] 60 90 365 0 3 s 0 0 0 0 1 0 0 0 sentinel {template redis sentinel:check_sentinel.sh[{IPADDRESS},26379,redisclusterstatus].str(ok,#2)}=0 check redis cluster monited by sentinel {IPADDRESS} not ok 0 4 0 {template redis sentinel:net.tcp.service[tcp,{IPADDRESS},26379].last(#1)}<>1 check sentinel {IPADDRESS} port 26379 failed. 0 4 0