1.1、编写redis_status.sh脚本
[fieldyang@centos7-135 sbin]$ mkdir -p /usr/lib/zabbix/scripts/
[fieldyang@centos7-135 sbin]$ cd /usr/lib/zabbix/scripts/
[fieldyang@centos7-135 scripts]$ cat >redis_status.sh
#!/bin/bash
#author:Fieldyang
#description:此脚本用于监控redis集群
REDISCLI='/app/redis/bin/redis-cli'
HOST='192.168.28.135'
PORT=7001
PASS='123456'
if [[ $# == 1 ]];then
case $1 in
cluster_state)
result=`$REDISCLI -c -h $HOST -p $PORT -a $PASS cluster info 2>/dev/null | grep -w "cluster_state" | awk -F':' '{print $2}'| grep -c ok`
echo $result
;;
cluster_slots_assigned)
result=`$REDISCLI -c -h $HOST -p $PORT -a $PASS cluster info 2>/dev/null | grep -w "cluster_slots_assigned" | awk -F':' '{print $2}'`
echo $result
;;
cluster_slots_ok)
result=`$REDISCLI -c -h $HOST -p $PORT -a $PASS cluster info 2>/dev/null | grep -w "cluster_slots_ok" | awk -F':' '{print $2}'`
echo $result
;;
cluster_slots_pfail)
result=`$REDISCLI -c -h $HOST -p $PORT -a $PASS cluster info 2>/dev/null | grep -w "cluster_slots_pfail" | awk -F':' '{print $2}'`
echo $result
;;
cluster_slots_fail)
result=`$REDISCLI -c -h $HOST -p $PORT -a $PASS cluster info 2>/dev/null | grep -w "cluster_slots_fail" | awk -F':' '{print $2}'`
echo $result
;;
cluster_known_nodes)
result=`$REDISCLI -c -h $HOST -p $PORT -a $PASS cluster info 2>/dev/null | grep -w "cluster_known_nodes" | awk -F':' '{print $2}'`
echo $result
;;
cluster_size)
result=`$REDISCLI -c -h $HOST -p $PORT -a $PASS cluster info 2>/dev/null | grep -w "cluster_size" | awk -F':' '{print $2}'`
echo $result
;;
cluster_current_epoch)
result=`$REDISCLI -c -h $HOST -p $PORT -a $PASS cluster info 2>/dev/null | grep -w "cluster_current_epoch" | awk -F':' '{print $2}'`
echo $result
;;
cluster_my_epoch)
result=`$REDISCLI -c -h $HOST -p $PORT -a $PASS cluster info 2>/dev/null | grep -w "cluster_my_epoch" | awk -F':' '{print $2}'`
echo $result
;;
cluster_stats_messages_ping_sent)
result=`$REDISCLI -c -h $HOST -p $PORT -a $PASS cluster info 2>/dev/null | grep -w "cluster_stats_messages_ping_sent" | awk -F':' '{print $2}'`
echo $result
;;
cluster_stats_messages_pong_sent)
result=`$REDISCLI -c -h $HOST -p $PORT -a $PASS cluster info 2>/dev/null | grep -w "cluster_stats_messages_pong_sent" | awk -F':' '{print $2}'`
echo $result
;;
cluster_stats_messages_sent)
result=`$REDISCLI -c -h $HOST -p $PORT -a $PASS cluster info 2>/dev/null | grep -w "cluster_stats_messages_sent" | awk -F':' '{print $2}'`
echo $result
;;
cluster_stats_messages_ping_received)
result=`$REDISCLI -c -h $HOST -p $PORT -a $PASS cluster info 2>/dev/null | grep -w "cluster_stats_messages_ping_received" | awk -F':' '{print $2}'`
echo $result
;;
cluster_stats_messages_pong_received)
result=`$REDISCLI -c -h $HOST -p $PORT -a $PASS cluster info 2>/dev/null | grep -w "cluster_s