# !/bin/bash
# author : Denny
# Monitor the memory of redis

# 获取实例占用内存大小
used_memory_rss=`redis-cli -p 6379 info memory | grep "used_memory_rss:" |awk -F":" '{ print $2 '}|tr -d "\r"`
# 获取分配给redis最大的内存大小
maxmemory=`redis-cli -p 6379 info memory | grep "maxmemory:" |awk -F":" '{ print $2 }'|tr -d "\r"`
#echo ues=$used_memory_rss
#echo maxmem=$maxmemory

#instance_utilization=$(`echo "scale=2;$used_memory_rss/$maxmemory" | bc`)
# 使用awk来进行除法运算，当然上面的bc计算也可以
instance_utilization=$(echo $used_memory_rss $maxmemory | awk '{printf "%0.2f\n" ,$1/$2}')

echo  "scale=1; ($instance_utilization * 100)/1 "|bc
