Redis monitoring script
Shell script written with redis-cli tool. According to the rules, you can monitor all the data information written on the info page.
Redis-cli Usage:
# redis-cli -h 127.0.0.1 -p 6379 -a passwoed //connect the specified redis# redis-cli info //Print the status information of local redis-srv # redis-cli info Keyspace without password //View information about the specified status field
Script by parameters executed, view all status information, match output, available parameters
-p port, default is 6379
-s status field, the field starting with '#' in info information, must be specified
-k Specific key, specific item in the status field; if the value is 'dbs', it is to check how many libraries are in use in the current instance.
-d Specifies the library of the current instance
-o Statistics options for a library, such as 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=$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
Usage is also explained in the script