Redis Monitoring Scripts

Source: Internet
Author: User

With the Redis-cli tool, write the shell script. According to the rules, all the data information written on the info page can be monitored.


REDIS-CLI usage:

# redis-cli-h 127.0.0.1-p 6379-a passwoed//connection specified redis# REDIS-CLI info//without password, print the status information of local REDIS-SRV # redis- CLI Info keyspace//View information for the specified state field


Script to view all status information, match output, available parameters by executing parameters

-P port, default is 6379

-S State field, the field that begins with ' # ' in info information, must be specified

-K specific key, the specific item in the state domain, if the value is ' DBS ', then there are several libraries in use to view the current instance

-d Specifies the library for the current instance

-O A library's statistical options, which can be: Keys,expires,avg_ttl


The script is as follows: 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= $passwd 1                ;;         6380)                  passwd= $passwd 2                 ;;         6381)                  passwd= $passwd 3                 ;;         *)                  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 



Usage is also explained in the script

This article from the "11414123" blog, reproduced please contact the author!

Redis Monitoring Scripts

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.