官网提高的python版本监控redis很久没有更新了,今天按照官网操作的一遍,出现了好多报错,后来问了一个哥们,他给了我监控配置文件和脚本。下面我分享给大家参考参考。
添加zabbix-agent配置文件
[root@test-mq01 redis]# cat /etc/zabbix/zabbix_agentd.d/redis.conf
UserParameter=Redis.Status,status=`/usr/bin/redis-cli -h 192.168.2.189 -a abcxxx -p 6379 ping|grep -c PONG` &&echo $status
UserParameter=Redis.Info[*],/etc/zabbix/script/redis/redismonitor.sh $1 $2
添加redismonitor.sh脚本文件
按照上面路径目录存放redismonitor.sh,并授权可执行
[root@test-mq01 redis]# cat /etc/zabbix/script/redis/redismonitor.sh
#!/bin/bash
REDISCLI="/usr/bin/redis-cli"
HOST="192.168.2.189"
PORT=6379
PASS=abcxxx
if [[ $# == 1 ]];then
case $1 in
version)
result=`$REDISCLI -h $HOST -a $PASS -p $PORT info | grep -w "redis_version" | awk -F':' '{print $2}'`
echo $result
;;
uptime)
result=`$REDISCLI -h $HOST -a $PASS -p $PORT info | grep -w "uptime_in_seconds" | awk -F':' '{print $2}'`
echo $result
;;
connected_clients)
result=`$REDISCLI -h $HOST -a $PASS -p $PORT info | grep -w "connected_clients" | awk -F':' '{print $2}'`
echo $result
;;
blocked_clients)
result=`$REDISCLI -h $HOST -a $PASS -p $PORT info | grep -w "blocked_clients" | awk -F':' '{print $2}'`
echo $result
;;
used_memory)
result=`$REDISCLI -h $HOST -a $PASS -p $PORT info | grep -w "used_memory" | awk -F':' '{print $2}'`
echo $result
;;
used_memory_rss)
result=`$REDISCLI -h $HOST -a $PASS -p $PORT info | grep -w "used_memory_rss" | awk -F':' '{print $2}'`
echo $result
;;
used_memory_peak)
result=`$REDISCLI -h $HOST -a $PASS -p $PORT info | grep -w "used_memory_peak" | awk -F':' '{print $2}'`
echo $result
;;
used_memory_lua)
result=`$REDISCLI -h $HOST -a $PASS -p $PORT info | grep -w "used_memory_lua" | awk -F':' '{print $2}'`
echo $result
;;
used_cpu_sys)
result=`$REDISCLI -h $HOST -a $PASS -p $PORT info | grep -w "used_cpu_sys" | awk -F':' '{print $2}'`
echo $result
;;
used_cpu_user)
result=`$REDISCLI -h $HOST -a $PASS -p $PORT info | grep -w "used_cpu_user" | awk -F':' '{print $2}'`
echo $result
;;
used_cpu_sys_children)
result=`$REDISCLI -h $HOST -a $PASS -p $PORT info | grep -w "used_cpu_sys_children" | awk -F':' '{print $2}'`
echo $result
;;
used_cpu_user_children)
result=`$REDISCLI -h $HOST -a $PASS -p $PORT info | grep -w "used_cpu_user_children" | awk -F':' '{print $2}'`
echo $result
;;
rdb_last_bgsave_status)
result=`$REDISCLI -h $HOST -a $PASS -p $PORT info | grep -w "rdb_last_bgsave_status" | awk -F':' '{print $2}' | grep -c ok`
echo $result
;;
aof_last_bgrewrite_status)
result=`$REDISCLI -h $HOST -a $PASS -p $PORT info | grep -w "aof_last_bgrewrite_status" | awk -F':' '{print $2}' | grep -c ok`
echo $result
;;
aof_last_write_status)
result=`$REDISCLI -h $HOST -a $PASS -p $PORT info | grep -w "aof_last_write_status" | awk -F':' '{print $2}' | grep -c ok`
echo $result
;;
*)
echo -e "\033[33mUsage: $0 {connected_clients|blocked_clients|used_memory|used_memory_rss|used_memory_peak|used_memory_lua|used_cpu_sys|used_cpu_user|used_cpu_sys_children|used_cpu_user_children|rdb_last_bgsave_status|aof_last_bgrewrite_status|aof_last_write_status}\033[0m"
;;
esac
elif [[ $# == 2 ]];then
case $2 in
keys)
result=`$REDISCLI -h $HOST -a $PASS -p $PORT info | grep -w "$1" | grep -w "keys" | awk -F'=|,' '{print $2}'`
echo $result
;;
expires)
result=`$REDISCLI -h $HOST -a $PASS -p $PORT info | grep -w "$1" | grep -w "keys" | awk -F'=|,' '{print $4}'`
echo $result
;;
avg_ttl)
result=`$REDISCLI -h $HOST -a $PASS -p $PORT info | grep -w "$1" | grep -w "avg_ttl" | awk -F'=|,' '{print $6}'`
echo $result
;;
*)
echo -e "\033[33mUsage: $0 {db0 keys|db0 expires|db0 avg_ttl}\033[0m"
;;
esac
fi
在zabbix-web端导入模板文件
模板名字叫 zabbix_redis.xml,导入后,主机绑定模板即可
2.0
2014-08-07T10:04:35Z
RedisMontior
Templates
RedisMontior
RedisMontior
RedisMontior
Templates
Redis Clients
Redis CPU
Redis DbKey
Redis Memory
Redis WriteStatus
-
Redis.Info[aof_last_bgrewrite_status]
0
0
Redis.Info[aof_last_bgrewrite_status]
30
90
365
0
3
0
0
0
0
1
0
0
0
Redis WriteStatus
-
Redis.Info[aof_last_write_status]
0
0
Redis.Info[aof_last_write_status]
30
90
365
0
3
0
0
0
0
1
0
0
0
Redis WriteStatus
-
Redis.Info[blocked_clients]
0
0
Redis.Info[blocked_clients]
30
90
365
0
3
0
0
0
0
1
0
0
0
Redis Clients
-
Redis.Info[connected_clients]
0
0
Redis.Info[connected_clients]
30
90
365
0
3
0
0
0
0
1
0
0
0
Redis Clients
-
Redis.Info[db0,avg_ttl]
0
0
Redis.Info[db0,avg_ttl]
30
90
365
0
3
0
0
0
0
1
0
0
0
Redis DbKey
-
Redis.Info[db0,expires]
0
0
Redis.Info[db0,expires]
30
90
365
0
3
0
0
0
0
1
0
0
0
Redis DbKey
-
Redis.Info[db0,keys]
0
0
Redis.Info[db0,keys]
30
90
365
0
3
0
0
0
0
1
0
0
0
Redis DbKey
-
Redis.Info[rdb_last_bgsave_status]
0
0
Redis.Info[rdb_last_bgsave_status]
30
90
365
0
3
0
0
0
0
1
0
0
0
Redis WriteStatus
-
Redis.Info[uptime]
0
0
Redis.Info[uptime]
30
90
365
0
3
uptime
0
0
0
0
1
0
0
0
-
Redis.Info[used_cpu_sys]
0
0
Redis.Info[used_cpu_sys]
30
90
365
0
0
0
0
0
0
1
0
0
0
Redis CPU
-
Redis.Info[used_cpu_sys_children]
0
0
Redis.Info[used_cpu_sys_children]
30
90
365
0
0
0
0
0
0
1
0
0
0
Redis CPU
-
Redis.Info[used_cpu_user]
0
0
Redis.Info[used_cpu_user]
30
90
365
0
0
0
0
0
0
1
0
0
0
Redis CPU
-
Redis.Info[used_cpu_user_children]
0
0
Redis.Info[used_cpu_user_children]
30
90
365
0
0
0
0
0
0
1
0
0
0
Redis CPU
-
Redis.Info[used_memory]
0
0
Redis.Info[used_memory]
30
90
365
0
3
0
0
0
0
1
0
0
0
Redis Memory
-
Redis.Info[used_memory_lua]
0
0
Redis.Info[used_memory_lua]
30
90
365
0
3
0
0
0
0
1
0
0
0
Redis Memory
-
Redis.Info[used_memory_peak]
0
0
Redis.Info[used_memory_peak]
30
90
365
0
3
0
0
0
0
1
0
0
0
Redis Memory
-
Redis.Info[used_memory_rss]
0
0
Redis.Info[used_memory_rss]
30
90
365
0
3
0
0
0
0
1
0
0
0
Redis Memory
-
Redis.Info[version]
0
0
Redis.Info[version]
30
90
365
0
1
0
0
0
0
1
0
0
0
-
Redis Status
0
0
Redis.Status
30
90
365
0
3
0
0
0
0
1
0
0
0
{RedisMontior:Redis.Status.last(0)}=0
Redis is down
0
5
0
Redis Client
900
200
0.0000
100.0000
1
1
0
1
0
0.0000
0.0000
0
0
0
0
0
0
C80000
0
2
0
-
RedisMontior
Redis.Info[blocked_clients]
1
0
00C800
0
2
0
-
RedisMontior
Redis.Info[connected_clients]
Redis CPU
900
200
0.0000
100.0000
1
1
0
1
0
0.0000
0.0000
0
0
0
0
0
2
C80000
0
2
0
-
RedisMontior
Redis.Info[used_cpu_sys]
1
2
00C800
0
2
0
-
RedisMontior
Redis.Info[used_cpu_user]
2
2
0000C8
0
2
0
-
RedisMontior
Redis.Info[used_cpu_sys_children]
3
2
C800C8
0
2
0
-
RedisMontior
Redis.Info[used_cpu_user_children]
Redis DbKeys
900
200
0.0000
100.0000
1
1
0
1
0
0.0000
0.0000
0
0
0
0
0
2
C80000
0
2
0
-
RedisMontior
Redis.Info[db0,avg_ttl]
1
2
00C800
0
2
0
-
RedisMontior
Redis.Info[db0,expires]
2
2
0000C8
0
2
0
-
RedisMontior
Redis.Info[db0,keys]
Redis Memory
900
200
0.0000
100.0000
1
1
0
1
0
0.0000
0.0000
0
0
0
0
0
2
C80000
0
2
0
-
RedisMontior
Redis.Info[used_memory]
1
2
00C800
0
2
0
-
RedisMontior
Redis.Info[used_memory_lua]
2
2
0000C8
0
2
0
-
RedisMontior
Redis.Info[used_memory_peak]
3
2
C800C8
0
2
0
-
RedisMontior
Redis.Info[used_memory_rss]
Redis WriteStatus
900
200
0.0000
100.0000
1
1
0
1
0
0.0000
0.0000
0
0
0
0
0
2
C80000
0
2
0
-
RedisMontior
Redis.Info[aof_last_bgrewrite_status]
1
2
0000C8
0
2
0
-
RedisMontior
Redis.Info[rdb_last_bgsave_status]
2
2
00C800
0
2
0
-
RedisMontior
Redis.Info[aof_last_write_status]
重启监控端agent
service zabbix-agent restart
如果看不到数据,请看服务端和被监控端日志