zabbix监控redis
通过redis自带的info命令来监控redis的健康状态,通过redis-cli PING命令来监控redis的存活状态。
创新互联主营临沂网站建设的网络公司,主营网站建设方案,成都app软件开发,临沂h5微信平台小程序开发搭建,临沂网站营销推广欢迎临沂等地区企业咨询
附件中有监控模板,将监控脚本放在redis服务器的自定义的/scripts/zabbix_redis/下:
#! /bin/bash #Name: redismontior.sh REDISCLI="/usr/bin/redis-cli" HOST="127.0.0.1" PORT=6379 if [[ $# == 1 ]];then case $1 in version) result=`$REDISCLI -h $HOST -p $PORT info | grep -w "redis_version" | awk -F':' '{print $2}'` echo $result ;; uptime) result=`$REDISCLI -h $HOST -p $PORT info | grep -w "uptime_in_seconds" | awk -F':' '{print $2}'` echo $result ;; connected_clients) result=`$REDISCLI -h $HOST -p $PORT info | grep -w "connected_clients" | awk -F':' '{print $2}'` echo $result ;; blocked_clients) result=`$REDISCLI -h $HOST -p $PORT info | grep -w "blocked_clients" | awk -F':' '{print $2}'` echo $result ;; used_memory) result=`$REDISCLI -h $HOST -p $PORT info | grep -w "used_memory" | awk -F':' '{print $2}'` echo $result ;; used_memory_rss) result=`$REDISCLI -h $HOST -p $PORT info | grep -w "used_memory_rss" | awk -F':' '{print $2}'` echo $result ;; used_memory_peak) result=`$REDISCLI -h $HOST -p $PORT info | grep -w "used_memory_peak" | awk -F':' '{print $2}'` echo $result ;; used_memory_lua) result=`$REDISCLI -h $HOST -p $PORT info | grep -w "used_memory_lua" | awk -F':' '{print $2}'` echo $result ;; used_cpu_sys) result=`$REDISCLI -h $HOST -p $PORT info | grep -w "used_cpu_sys" | awk -F':' '{print $2}'` echo $result ;; used_cpu_user) result=`$REDISCLI -h $HOST -p $PORT info | grep -w "used_cpu_user" | awk -F':' '{print $2}'` echo $result ;; used_cpu_sys_children) result=`$REDISCLI -h $HOST -p $PORT info | grep -w "used_cpu_sys_children" | awk -F':' '{print $2}'` echo $result ;; used_cpu_user_children) result=`$REDISCLI -h $HOST -p $PORT info | grep -w "used_cpu_user_children" | awk -F':' '{print $2}'` echo $result ;; rdb_last_bgsave_status) result=`$REDISCLI -h $HOST -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 -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 -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 -p $PORT info | grep -w "$1" | grep -w "keys" | awk -F'=|,' '{print $2}'` echo $result ;; expires) result=`$REDISCLI -h $HOST -p $PORT info | grep -w "$1" | grep -w "keys" | awk -F'=|,' '{print $4}'` echo $result ;; avg_ttl) result=`$REDISCLI -h $HOST -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参数key的设置:
# cat /etc/zabbix/zabbix_agentd.d/userparameter_redis.conf UserParameter=Redis.Status, redis-cli PING|grep -c "PONG" UserParameter=Redis.Info[*], /bin/sh /scripts/zabbix_redis/zabbix_redis.sh $1
模板见附件.其中对脚本传入两个参数的部分,对于不同的环境可能会不太兼容,可以对模板和脚本进行修改,或者直接在模板中禁用对应的item。
附件:http://down.51cto.com/data/2366694
网页标题:zabbix监控redis
分享地址:http://azwzsj.com/article/gdgpij.html