redisのメモリおよびメモリ使用率およびフラグメント率を監視するスクリプト
1678 ワード
#!/bin/bash cmd=/lingtian/opt/redis/bin/redis-cli port=9736 host=localhost unit=
#追加テストredisは$cmd-h$host-p$port set monitor-test 1>/dev/null if[$?=0];then echo redis is ok! else echo redis set error fi
$cmd -h $host -p $port info memory |grep used_memory_human|cut -d: -f2|head -1|tr -d '\r'|awk -F '' '{print $NF}'
used_memory= $cmd -h $host -p $port info memory |grep used_memory_human|cut -d: -f2|head -1|tr -d '\r'
maxmemory= $cmd -h $host -p $port info memory |grep maxmemory_human|cut -d: -f2|head -1|tr -d '\r'
maxmemory_value= echo ${maxmemory%G}
if [ “$unit” == G ];then used_memory_value= echo ${used_memory%G}
echo echo "scale=2; $used_memory_value*1024/($maxmemory_value*10.24)"|bc
elif [ “$unit” == M ];then used_memory_value= echo ${used_memory%M}
echo echo "scale=2; $used_memory_value/($maxmemory_value*10.24)"|bc
elif [ “$unit” == K ];then used_memory_value= echo ${used_memory%K}
echo echo "scale=2; $used_memory_value/1024/($maxmemory_value*10.24)"|bc
else used_memory_value= echo ${used_memory%B}
echo echo "scale=2; $used_memory_value/1024/1024/($maxmemory_value*10.24)"|bc
fi echo $unit echo $used_memory echo $used_memory_value echo $maxmemory echo m a x m e m o r y v a l u e m e m f r a g m e n t a t i o n r a t i o = ‘ maxmemory_value mem_fragmentation_ratio=` maxmemoryvaluememfragmentationratio=‘cmd -p $port info memory |grep mem_fragmentation_ratio|cut -d: -f2` echo $mem_fragmentation_ratio #追加テストredisは$cmd-h$host-p$port set monitor-test 1>/dev/null if[$?=0];then echo redis is ok! else echo redis set error fi