shell监控脚本-监控memcache
2013-03-27 13:35:25
标签:shell memcache 脚本 监控
原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 、作者信息和本声明。否则将追究法律责任。http://dngood.blog.51cto.com/446195/1163568
shell监控脚本-监控memcache
注意:请先参考 shell监控脚本-准备工作,监控脚本在 rhel5 下测试正常,其它版本的linux 系统请自行测试
#监控memcache
cat chk_memcache.sh
#!/bin/bash
#
#script_name:chk_memcache.sh
#check memcache
#
#last update 20130320 by dongnan
#bbs#
#blog# http://dngood.blog.51cto.com
#
#(echo "stats";sleep 2) | telnet IP 11211
#Trying IP...
#Connected to IP (IP).
#Escape character is '^]'.
#STAT pid 26090
#STAT uptime 3179206
#STAT time 1363157551
#STAT version 1.2.6
#.................
#STAT pointer_size 64
#STAT threads 1
#END
#Connection closed by foreign host.
#
#printf "stats\r\n" | nc IP 11211
#
#nc -z bbs.ywwd.net 80 && echo $?
#0
#nc -z bbs.ywwd.net 81 || echo $?
#1
#variables
nc=/usr/bin/nc
usleep=/bin/usleep
echo=/bin/echo
sh_dir=/root/sh/
crondir=${sh_dir}crontab
source ${sh_dir}CONFIG
hosts="$MEMCACHE_HOSTS"
check_count=8
fault_count=4
#main
#主循环遍历机器
for memcache in $hosts ;do
flag_file=${crondir}/log/${memcache}.memcache
log=$crondir/log/memcache_error.log
#true
if [ $(echo "stats" | nc -w 2 "$memcache" 11211 | wc -l) -gt 2 ];then
#flag
if [ -f $flag_file ];then
#sms
#for mobile in $MOBILES; do
#$echo "$memcache memache ok" | /usr/local/bin/gammu --sendsms TEXT "$mobile" -unicode
#done
#email
for mail in $MAILS;do
echo "$memcache memcache ok" | mail -s "$memcache memcache ok" $mail
done
#delete flag
test -e "$flag_file" && rm -f "$flag_file"
fi
#false
else
#flag存在,跳过本次循环
test -e $flag_file && continue
check_failed=0
#
for((i=1;i<="$check_count";i++));do
check_date=$(date '+ %F %T')
#
if [ ! $(echo "stats" | nc -w 2 "$memcache" 11211 | wc -l) -gt 2 ];then
#
((check_failed++))
#error.log
$echo "$(/bin/date +'%F %T') $memcache $check_failed fault" >> "$log"
#
$usleep 300000 || sleep 1 || sleep 1
fi
done
#大(等)于fault_count发送报警
if [ "$check_failed" -gt "$fault_count" ];then
#sms
#for mobile in $MOBILES;do
#$echo "$memcache memache error" | /usr/local/bin/gammu --sendsms TEXT "$mobile" -unicode
#/bin/date +'%F %T' && $echo "$memcache memache error"
#done
#mail
for mail in $MAILS;do
echo "$memcache memcache error" | mail -s "$memcache memcache error" $MAILS
done
#log
echo "$check_date $HOST memcache error" >> "$log"
#flag
$echo "$memcache memache error" > "$flag_file"
fi
#主if结束
fi
#主循环结束
done
#
结束
更多请:
linux 系统运维 37275208
vmware 虚拟化 166682360
本文出自 “dongnan” 博客,请务必保留此出处http://dngood.blog.51cto.com/446195/1163568
阅读(915) | 评论(0) | 转发(0) |