Chinaunix首页 | 论坛 | 博客
  • 博客访问: 490134
  • 博文数量: 99
  • 博客积分: 3621
  • 博客等级: 中校
  • 技术积分: 1089
  • 用 户 组: 普通用户
  • 注册时间: 2010-06-22 16:29
文章存档

2012年(21)

2011年(28)

2010年(50)

分类: Mysql/postgreSQL

2011-06-22 11:55:03

  1. #monitor mysql service status and server load
  2. #!/bin/bash
  3. function Send_Email()
  4. {
  5. ADMIN="bruce.zuo@csoftintl.com"
  6. MESSAGE_FILE="/tmp/monitor.log"
  7.         echo "VIP has been changed at `date`,please check it!Message:$1" > $MESSAGE_FILE
  8.         /bin/mail -s "VIP has been changed" $ADMIN < $MESSAGE_FILE
  9. rm -r $MESSAGE_FILE
  10. }
  11.  
  12. while true; do
  13.     sleep 1
  14. CPU_NUMBER=`cat /proc/cpuinfo |grep processor |wc -l`
  15. MAX_LOAD=`echo $CPU_NUMBER*2|bc`
  16. KEEPALIVED_ALIVE=`ps aux |grep keepalived |grep -v "grep" |wc -l`
  17. # some optional
  18. # USER_NAME=$1
  19. # PASSWORD=$2
  20. # IS_SLAVE=$3
  21. if [ `service mysql status |awk '{print $2}'` = 'running' ]
  22. then
  23.    LOAD=`uptime`
  24.    LOAD=${LOAD##* }
  25. # if [ `expr $LOAD \< $CPU_LOAD` = 1 ] # another method,compare integer and decimal
  26.    if [ `echo "$LOAD > $MAX_LOAD" | bc` = 1 ]
  27.    then
  28. # echo "Average load is BUSY"
  29.       pkill keepalived # if load is greater than max load then kill keepalived,take VIP point to another server.
  30.       Send_Email "Mysql is alived,Average load is busy,so kill keepalived"
  31.    else
  32.       if [ `echo "$KEEPALIVED_ALIVE < 2 " | bc` = 1 ] # if keepalived is not running ,run it immediately.
  33.       then
  34.           keepalived -D
  35.           Send_Email "Mysql is alived,Average load is Free,Keepalived is not alived,so start keepalived"
  36.       fi
  37.    fi
  38. elif [ `echo "$KEEPALIVED_ALIVE < 2 " | bc` = 0 ]
  39.    then
  40.            pkill keepalived # if mysql service is not running ,then kill keepalived,take VIP point to another server.
  41.            Send_Email "Mysql service is not alived,Keepalived is alived,so kill keepalived."
  42. fi
  43. done
  44. exit 0
阅读(1405) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~