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