[Redis] Redis Cluster统计脚本

统计Redis集群的指标。注:此脚本仅针对GB级别的数据量,MB可以改了再用。

1.Redis集群Redis_Cluster_MEM_Used

2.Redis集群Redis_Cluster_MEM_Percent

3.Redis集群Redis_Cluster_MEM_TOTAL

4.Redis集群Redis_Cluster_INSTANCE_SUM

5.Redis集群Redis_Keys_Total


#!/bin/bash

source /home/ap/zacks/Hadoop_Redis/bigdata_env
A_HOST=("IP1" "IP2" "IP3" "IP4" "IP5" "IP6" "IP7" "IP8" "IP9" "IP10")
B_PORT=("22400" "22401" "22402" "22403" "22404" "22405" "22406" "22407")

array_mem=`cat cd.log|awk '{print $1}'`
array_keys=`cat ab.log`

SUM_INSTANCE_MEM=10 # single redis instance memory total:10 G
SUM_REDIS_INSTANCE=0
SUM_MEM_USED=0
SUM_INSTANCE=0
SUM_KEYS=0

for host in ${A_HOST[@]}
do
for port in ${B_PORT[@]}
do
#########
## Step3.1 Get Redis Mem Info
#########
String_mem=`redis-cli -c -h ${host} -p ${port} info |grep used_memory_human`
SUM_REDIS_INSTANCE=$[$SUM_REDIS_INSTANCE+1]
A=${String_mem#*used_memory_human:} #Get Words after ,Result: 6.66G
B=${A%%G*} #Get Words before,Redulst: 6.66
SUM_INSTANCE=$[$SUM_INSTANCE+1]
SUM_MEM_USED=`echo "$SUM_MEM_USED + $B"|bc`

#########
## Step3.2 Get Redis Keys Info
#########
String_keys=`redis-cli -c -h ${host} -p ${port} info |grep db0:keys`
C=${String_keys#*db0:keys=:} #Get Words after ,Result: 6.66G
D=${A%%,expires*} #Get Words before,Redulst: 6.66
SUM_KEYS=$[$SUM_KEYS+$D]
#echo $SUM_KEYS
done
done

avg_redis_memory_used=`echo "scale=6;$SUM_MEM_USED/$SUM_INSTANCE"|bc`
percent_redis_memory_used=`echo "scale=2;$avg_redis_memory_used*100/$SUM_INSTANCE_MEM"|bc`
echo "Redis_Cluster_MEM_Used = "$percent_redis_memory_used "%"
echo "Redis_Cluster_MEM_Percent = "$SUM_MEM_USED "GB"
echo "Redis_Cluster_MEM_TOTAL = " $[$SUM_INSTANCE_MEM*$SUM_INSTANCE] "GB"
echo "Redis_Cluster_INSTANCE_SUM = "$SUM_INSTANCE
echo "Redis_Keys_Total = "$SUM_KEYS

 

分类上一篇:     分类下一篇:

Leave a Reply