redis監控指令碼

來源:互聯網
上載者:User

標籤:使用redis-cli編寫redis監控指令碼

配合redis-cli工具,編寫的shell指令碼。按照規則,可以監控info頁面寫的所有資料資訊


redis-cli用法:

# redis-cli -h 127.0.0.1 -p 6379 -a passwoed     //串連指定的redis# redis-cli info        //沒有密碼的情況下,列印本地redis-srv的狀態資訊# redis-cli info Keyspace     //查看指定狀態域的資訊


指令碼通過執行的參數,查看所有狀態資訊,匹配輸出,可用參數

    -p 連接埠,預設是6379

    -s 狀態域,info資訊中’#‘開頭的那個欄位,必須指定

    -k 具體key,狀態域內具體的項;若該值為‘dbs‘,則是查看當前執行個體有幾個庫在使用

    -d 指定當前執行個體的庫

    -o 某個庫的統計選項,可以是:keys,expires,avg_ttl


指令碼如下:redis_sts.sh

#!/bin/bashhost="127.0.0.1"passwd1="password1"passwd2="password2"passwd3="password3"if [ $# -lt 4 ];then        echo "Usage: bash $0 -p [6379] -s section [-k] keys [-d] db [-o] opt"        exit 1else        port=6379        db=‘‘        opt=‘‘        while [ $# -gt 0 ]        do                if [ $1 == "-p" ];then                        port=$2                fi                if [ $1 == "-s" ];then                        section=$2                fi                if [ $1 == "-k" ];then                        key=$2                fi                if [ $1 == "-d" ];then                        db=$2                fi                if [ $1 == "-o" ];then                        opt=$2                fi                shift 2        doneficase $port in        6379)                passwd=$passwd1                ;;        6380)                passwd=$passwd2                ;;        6381)                passwd=$passwd3                ;;        *)                passwd=""                ;;esacif [[ $section == "Keyspace" && $key == "dbs" ]];then        cmd="/usr/local/redis/bin/redis-cli -p $port -a $passwd info Keyspace |grep ‘^db[0-9]\{1,2\}:*‘|wc -l"elif [[ ! -z $db && ! -z $opt ]];then        cmd="/usr/local/redis/bin/redis-cli -p $port -a $passwd info Keyspace |grep $db |tr -s ‘,‘ ‘\n‘|grep $opt|cut -d ‘=‘ -f 2"        #cmd="/usr/local/redis/bin/redis-cli -p $port -a $passwd info Keyspace |grep $db |tr -s ‘,‘ ‘\n‘ |awk -F [=] -v akey=$opt ‘/$akey/{print """$NF"""}‘"else        cmd="/usr/local/redis/bin/redis-cli -p $port -a $passwd info $section|grep ${key}: |cut -d ‘:‘ -f 2"fi#echo $cmdeval $cmd



用法也在指令碼中有說明

本文出自 “11414123” 部落格,轉載請與作者聯絡!

redis監控指令碼

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.