redis集群内存监控(shell版)

redis集群内存监控(shell版)

这里采用shell来实现,并借助钉钉webhook实现告警

#!/bin/bash
function dingdingalarm(){
   	echo "下面是函数内部的值"
  	echo $1
  	curl 'https://oapi.dingtalk.com/robot/send?access_token=**********' 
  		-H 'Content-Type: application/json'
  		 -d $1
}
function alarmbody(){
   	msg='超哥!!!这个节点内存告急:主机名称是'$1',主机是'$2',端口是'$3',内存是'$4
 	echo $msg
 	json_data='{"msgtype":"text","text":{"content":"'$msg'"},}'
  	echo $json_data
  	dingdingalarm $json_data 
}
	
num_id='1 2 3'
for id in $num_id
do
host=`redis-cli -c -h 10.111.3.20 -p 10409 cluster nodes |grep master |awk '{print $2}'|awk -F: '{print $1}'| sed -n $id'p'`
port=`redis-cli -c -h 10.111.3.20 -p 10409 cluster nodes |grep master |awk '{print $2}'|awk -F: '{print $2}'| sed -n $id'p'`
mem=`redis-cli -c -h $host -p $port info memory |grep used_memory_human |awk -F: '{print $2}'`
int_mem=`echo $mem |sed 's/G//g'|sed 's/\r//g'`

#判断并确定主机名称
if [ $host == '10.111.3.18' ];then
	nodename='lopscoop-vpc-redis-1'
elif [ $host == '10.111.3.19' ];then
	nodename='lopscoop-vpc-redis-2'
else:
	nodename='lopscoop-vpc-redis-3'
fi

if [ $(echo "$int_mem > 8" | bc) = 1 ];then
	alarmbody $nodename $host $port $int_mem
else
 	echo "that's will be ok"
fi
done

上面是简易版的 ,后期逐步优化。增加功能

你可能感兴趣的:(redis,shell脚本)