最近在处理zabbix 监控,监控redis时发现官方并没有提供相关的模板,自己参照之前mysql的监控改写了一个。
主要支持 info命令下所有参数,自动发现有key的数据库,并提供info中的参数数据
特点:较为通用,代码简洁
需要设置zabbix agent 自定义脚本,具体设置方式不做说明,请百度
具体脚本如下:
check_redis.sh
#!/bin/bash # ------------------------------------------------------------------------------- # FileName: check_redis.sh # Revision: 1.0 # Date: 2019-3-21 # Author: xsj # Email: [email protected] # Description: # Notes: ~ # ------------------------------------------------------------------------------- # Copyright: 2019 (c) xsj # License: GPL REDISPATH='/usr/local/bin/redis-cli' HOST='127.0.0.1' PORT='6379' PASSWD='111111' REDIS_CMD="$REDISPATH -h $HOST -p $PORT -a $PASSWD " # 参数是否正确 if [[ $# -gt 2 || $# -lt 1 ]];then echo "arg error!"; exit 1; fi if [[ $# == 1 ]];then case $1 in Discovery) array=(`$REDIS_CMD info 2>/dev/null|grep ":keys="|awk -F: '{ print $1}'`) length=${#array[@]} printf "{\n" printf '\t'"\"data\":[" for ((i=0;i<$length;i++)) do printf '\n\t\t{' printf "\"{#DB}\":\"${array[$i]}\"}" if [ $i -lt $[$length-1] ];then printf ',' fi done printf "\n\t]\n" printf "}\n" ;; Ping) $REDIS_CMD ping|grep -c PONG ;; Status_*) $REDIS_CMD info 2>/dev/null| grep "${1#*Status_}"|awk 'NR==1'|awk -F: '{print $NF}' ;; *) echo "Usage:$0 (Ping|Status_key);其中 Status_ key为info中的key,注意大小写" ;; esac elif [[ $# == 2 ]];then param1="${1#*Status_}"; case $2 in keys) $REDIS_CMD info 2>/dev/null |grep -w "$param1"|grep -w "$2"| awk -F'=|,' '{print $2}' ;; expires) $REDIS_CMD info 2>/dev/null |grep -w "$param1"|grep -w "$2"| awk -F'=|,' '{print $4}' ;; avg_ttl) $REDIS_CMD info 2>/dev/null |grep -w "$param1"|grep -w "$2"| awk -F'=|,' '{print $6}' ;; *) echo "Usage:$0{db0 keys|db0 expires|db0 avg_ttl}" ;; esac fi
status_redis.conf
#redis db自动发现 UserParameter=redis.discovery,/etc/zabbix/scripts/check_redis.sh Discovery #监控redis状态,我们可以根据这个参数对应的监控项创建redis状态触发器。 UserParameter=redis.ping,/etc/zabbix/scripts/check_redis.sh Ping #状态信息 UserParameter=redis.status[*],/etc/zabbix/scripts/check_redis.sh Status_$1 $2
web管理端配置模板



只设置了部分,所有info 下的参数都支持
