1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
| #!/bin/bash
if [ $# -ne 1 ];then echo -e "\033[31mERROR\033[0m: A port must be provided." echo "eg: sh $0 6379" exit 1 fi
PORT=$1 CLI_BIN=/data/redis/bin/redis-cli EXEC="$CLI_BIN -p $PORT "
# Define checking memory available. checkMem(){ USED_MEM=`$EXEC memory stats |grep -A 1 total.allocated|tail -n1` MAX_MEM=`$EXEC info memory|grep -w maxmemory|awk -F ':' '{print $2}'` MEM_POL=`$EXEC info memory|grep -w maxmemory_policy|awk -F ':' '{print $2}'` DATA_USE=`$EXEC memory stats|grep -A 1 'dataset.bytes'|tail -n1` EXCEPT_DATA=`$EXEC memory stats|grep -A 1 'overhead.total'|tail -n1` REPL_USE=`$EXEC memory stats|grep -A 1 'replication.backlog'|tail -n1` INOUT_USE=`$EXEC client list| awk 'BEGIN{sum=0} {sum+=substr($12,6);sum+=substr($13,11)}END{print sum}'` OUTPUT_USE=`$EXEC client list| awk 'BEGIN{sum=0} {sum+=substr($16,6)}END{print sum}'`
STATUS=`$EXEC set actionsky 1` if [ "$STATUS" = 'OK' ];then echo -e "Redis当前内存是否可用: \033\033[32m${STATUS}\033[0m" else echo -e "Redis当前内存是否可用: \033\033[31m${STATUS}\033[0m" fi echo "Redis当前内存淘汰策略: $MEM_POL" echo "Redis当前已使用的内存(byte): $USED_MEM" echo "Redis当前最大内限限制(byte): $MAX_MEM" echo "Redis当前数据对象已使用内存(byte): $DATA_USE" echo "Redis当前除数据外总内存消耗(byte): $EXCEPT_DATA" echo "Redis当前复制积压缓存区消耗(byte): $REPL_USE" echo " " echo "Redis当前客户端输入缓存总消耗(byte): $INOUT_USE" echo "Redis当前客户端输入缓存各连接消耗(TOP10):" $EXEC client list|awk '{print substr($12,6),$1,$12,$18}'|sort -nrk1,1 | cut -f1 -d" " --complement echo " " echo "Redis当前客户端输出缓存总消耗(byte): $OUTPUT_USE" echo "Redis当前客户端输出缓存各连接消耗(TOP10):" $EXEC client list|awk '{print substr($16,6),$1,$16,$18}'|sort -nrk1,1 | cut -f1 -d" " --complement |head -n10 }
|