美文网首页
【redis】redis主从哨兵内存占用查看

【redis】redis主从哨兵内存占用查看

作者: Bogon | 来源:发表于2022-08-10 15:08 被阅读0次

    cat check_redis-memusage.sh

    #!/bin/bash
    
    passwd='XXX'
    
    function check_redis(){
    #设置每个redis主从哨兵实例的任一哨兵的IP 端口 实例编码,根据实际情况修改,用空格分隔
    
    name=(
    '192.168.1.101 16381   test01sentinel' 
    '192.168.1.102 16382   test02sentinel' 
    '192.168.1.103 16383   test03sentinel' 
    )
    
    for((k=0; k<${#name[@]};k++))
            do
                    host=$(echo     ${name[k]} | awk -F " " '{print $1}')
                    port=$(echo     ${name[k]} | awk -F " " '{print $2}')
                    instance=$(echo ${name[k]} | awk -F " " '{print $3}')
     
                    master_ip_port=`redis-cli -h $host  -p $port  SENTINEL get-master-addr-by-name $instance | awk "{print $1}"`
                    slave_ip_port=`redis-cli  -h $host  -p $port  SENTINEL slaves $instance | awk '{print $1}'`
                    
                    master_ip=`echo $master_ip_port   | awk '{print $1}'`
                    master_port=`echo $master_ip_port | awk '{print $2}'`
                    
                    slave_ip=`echo $slave_ip_port    | awk '{print $4}'`
                    slave_port=`echo $master_ip_port | awk '{print $2}'`
                    
                    master_total_mem=`redis-cli -h $master_ip  -p $master_port  -a ${passwd}  info | grep maxmemory_human   | awk -F ":" '{print $2}'`
                    master_used_mem=`redis-cli  -h $master_ip  -p $master_port  -a ${passwd}  info | grep used_memory_human | awk -F ":" '{print $2}'`
                    
                    slave_total_mem=`redis-cli  -h $slave_ip   -p $slave_port   -a ${passwd}  info | grep maxmemory_human   | awk -F ":" '{print $2}'`
                    slave_used_mem=`redis-cli   -h $slave_ip   -p $slave_port   -a ${passwd}  info | grep used_memory_human | awk -F ":" '{print $2}'`
                    
                    echo "###########################"
                    echo redis实例名: $instance
                    echo redis主IP: $master_ip
                    echo redis主端口: $master_port
                    echo redis主设置总内存: $master_total_mem
                    echo redis主已使用的内存: $master_used_mem
                    echo "***************************"
                    echo redis实例名: $instance
                    echo redis从IP: $slave_ip
                    echo redis从端口: $master_port
                    echo redis从设置总内存: $slave_total_mem
                    echo redis从已使用的内存: $slave_used_mem
                    echo "**************************"
            done
    }
    
    # 调用函数
    check_redis
    
    

    相关文章

      网友评论

          本文标题:【redis】redis主从哨兵内存占用查看

          本文链接:https://www.haomeiwen.com/subject/yswqmrtx.html