码迷,mamicode.com
首页 > 其他好文 > 详细

zabbix监控redis集群

时间:2017-07-27 20:31:26      阅读:580      评论:0      收藏:0      [点我收藏+]

标签:doc   mrr   net   pod   vnc   jpa   jmp   acdb   atq   

1.agent端新建自动发现redis集群端口

脚本如下

#!/bin/bash
#redis_sport_scan.sh
redis() {
            port=($(sudo netstat -tpln | awk -F "[ :]+" ‘/redis/ && /0.0.0.0/ {print $5}‘))

            printf ‘{\n‘

            printf ‘\t"data":[\n‘

               for key in ${!port[@]}

                   do

                       if [[ "${#port[@]}" -gt 1 && "${key}" -ne "$((${#port[@]}-1))" ]];then

              socket=`ps aux|grep ${port[${key}]}|grep -v grep|awk -F ‘=‘ ‘{print $10}‘|cut -d ‘ ‘ -f 1`

                          printf ‘\t {\n‘

                          printf "\t\t\t\"{#REDISPORT}\":\"${port[${key}]}\"},\n"

                     else [[ "${key}" -eq "((${#port[@]}-1))" ]]

              socket=`ps aux|grep ${port[${key}]}|grep -v grep|awk -F ‘=‘ ‘{print $10}‘|cut -d ‘ ‘ -f 1`

                          printf ‘\t {\n‘

                          printf "\t\t\t\"{#REDISPORT}\":\"${port[${key}]}\"}\n"

                       fi

               done

                          printf ‘\t ]\n‘

                          printf ‘}\n‘

}
redis  $1

 技术分享

redis_status.sh

#!/bin/bash
############################################################
# $Name:         redis_status.sh
# $Version:      v1.0
# $Function:     Redis Status
# $Author:       xuliangwei
# $organization: www.xuliangwei.com
# $Create Date:  2016-06-23
# $Description:  Monitor Redis Service Status
############################################################

R_PORT="$1"  #根据实际情况调整端口

R_COMMAND="$2"

R_SERVER="192.168.10.99"  #根据具体情况调整IP地址

PASSWD="hhly"       #如果没有设置Redis密码,为空即可

redis_status(){

#   (echo -en "AUTH $PASSWD\r\nINFO\r\n";sleep 1;) | /usr/bin/nc "$R_SERVER" "$R_PORT" > /tmp/redis_"$R_PORT".tmp

#      REDIS_STAT_VALUE=$(grep "$R_COMMAND:" /tmp/redis_"$R_PORT".tmp | cut -d ‘:‘ -f2)

#       echo "$REDIS_STAT_VALUE"
       
   REDIS_STAT_VALUE=$((echo info; sleep 1) | /usr/sbin/redis-cli -p $1 -h $R_SERVER -a $PASSWD | grep $2 | awk -F":" ‘{print $2}‘)
       echo "$REDIS_STAT_VALUE"

}

case $R_COMMAND in

    used_cpu_user_children)

    redis_status "$R_PORT" "$R_COMMAND"

    ;;

    used_cpu_sys)

    redis_status "$R_PORT" "$R_COMMAND"

    ;;

    total_commands_processed)

    redis_status "$R_PORT" "$R_COMMAND"

    ;;

    role)

    redis_status "$R_PORT" "$R_COMMAND"

    ;;

    lru_clock)

    redis_status "$R_PORT" "$R_COMMAND"

    ;;

    latest_fork_usec)

    redis_status "$R_PORT" "$R_COMMAND"

    ;;

    keyspace_misses)

    redis_status "$R_PORT" "$R_COMMAND"

    ;;

    keyspace_hits)

    redis_status "$R_PORT" "$R_COMMAND"

    ;;

    keys)

    redis_status "$R_PORT" "$R_COMMAND"

    ;;

    expires)

    redis_status "$R_PORT" "$R_COMMAND"

    ;;

    expired_keys)

    redis_status "$R_PORT" "$R_COMMAND"

    ;;

    evicted_keys)

    redis_status "$R_PORT" "$R_COMMAND"

    ;;

    connected_clients)

    redis_status "$R_PORT" "$R_COMMAND"

    ;;

    changes_since_last_save)

    redis_status "$R_PORT" "$R_COMMAND"

    ;;

    blocked_clients)

    redis_status "$R_PORT" "$R_COMMAND"

    ;;

    bgsave_in_progress)

    redis_status "$R_PORT" "$R_COMMAND"

    ;;

    bgrewriteaof_in_progress)

    redis_status "$R_PORT" "$R_COMMAND"

    ;;

    used_memory_peak)

    redis_status "$R_PORT" "$R_COMMAND"

    ;;

    used_memory)

    redis_status "$R_PORT" "$R_COMMAND"

    ;;

    used_cpu_user)

    redis_status "$R_PORT" "$R_COMMAND"

    ;;

    used_cpu_sys_children)

    redis_status "$R_PORT" "$R_COMMAND"

    ;;

    total_connections_received)

    redis_status "$R_PORT" "$R_COMMAND"

    ;;

    *)

    echo $"USAGE:$0 {used_cpu_user_children|used_cpu_sys|total_commands_processed|role|lru_clock|latest_fork_usec|keyspace_misses|keyspace_hits|keys|expires|expired_keys|connected_clients|changes_since_last_save|blocked_clients|bgrewriteaof_in_progress|used_memory_peak|used_memory|used_cpu_user|used_cpu_sys_children|total_connections_received}"

    esac

在agent上调试脚本

技术分享

在server端调试

技术分享

提示redis-cli命令不存在

技术分享

技术分享

zabbix监控redis集群

标签:doc   mrr   net   pod   vnc   jpa   jmp   acdb   atq   

原文地址:http://www.cnblogs.com/qmfsun/p/7246511.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!