Error[8]: Undefined offset: 8, File: /www/wwwroot/outofmemory.cn/tmp/plugin_ss_superseo_model_superseo.php, Line: 121
File: /www/wwwroot/outofmemory.cn/tmp/plugin_ss_superseo_model_superseo.php, Line: 473, decode(

监控MySQL主从状态的shell脚本

分享一个Linux下,监控MySQL主从状态及配合企业微信机器人报警的Shell脚本

#! /bin/bash
#
source /etc/profile
export PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"

SLAVE_IP=`ip add | grep inet | grep brd | awk -F / '{print }' | awk -F " " '{print }' | awk 'NR==1'`
USER=monitor
PASSWORD=xxxxxx
TIME=`date`
WHEREIS_MYSQL=/opt/mysql/bin/mysql
WEBHOOK='https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=bb09197b-5ff6-4928-9872-xxxxxx'

wx(){
cat > [+++].msg << EOF
curl '$WEBHOOK' \
 -H 'Content-Type: application/json' \
 -d '
 {
  "msgtype": "text",
  "text": {
   "content": "",
  }
 }'
EOF
sh [+++].msg && rm -rf [+++].msg
}


Check_Mysql_Slave()
{
 $WHEREIS_MYSQL -u$USER -p$PASSWORD -h$SLAVE_IP -e "select version();" >/dev/null 2>&1
 if [ $? -ne 0 ];then
  echo "Mysql is stopped $DATE" >> /data/mysql/check.log
    ERROR="ERROR:Mysql-$SLAVE_IP cannot connect\n$TIME"
  wx "$ERROR"
 else
  #echo "1" >> /data/mysql/check.log
    IO_SQL_STATUS=`$WHEREIS_MYSQL -u$USER -p$PASSWORD -h$SLAVE_IP -e "show slave status \G" 2>/dev/null | awk '/Slave_.*_Running:/{print }'`
    for i in $IO_SQL_STATUS;do
      THREAD_STATUS_NAME=${i%:*}
      THREAD_STATUS=${i#*:}
      if [ "$THREAD_STATUS" != "Yes" ];then
        STATUS="ERROR:Mysql-$SLAVE_IP $THREAD_STATUS_NAME status is $THREAD_STATUS!\n$TIME"
    echo "$STATUS" >> /data/mysql/check.log
        wx "$STATUS"
      fi
    done
  fi
}

Check_Mysql_Slave

最终报警效果如下:

以上就是监控MySQL主从状态的shell脚本的详细内容,更多关于监控MySQL主从状态的资料请关注脚本之家其它相关文章!

)
File: /www/wwwroot/outofmemory.cn/tmp/route_read.php, Line: 126, InsideLink()
File: /www/wwwroot/outofmemory.cn/tmp/index.inc.php, Line: 165, include(/www/wwwroot/outofmemory.cn/tmp/route_read.php)
File: /www/wwwroot/outofmemory.cn/index.php, Line: 30, include(/www/wwwroot/outofmemory.cn/tmp/index.inc.php)
Error[8]: Undefined offset: 9, File: /www/wwwroot/outofmemory.cn/tmp/plugin_ss_superseo_model_superseo.php, Line: 121
File: /www/wwwroot/outofmemory.cn/tmp/plugin_ss_superseo_model_superseo.php, Line: 473, decode(

监控MySQL主从状态的shell脚本

分享一个Linux下,监控MySQL主从状态及配合企业微信机器人报警的Shell脚本

#! /bin/bash
#
source /etc/profile
export PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"

SLAVE_IP=`ip add | grep inet | grep brd | awk -F / '{print }' | awk -F " " '{print }' | awk 'NR==1'`
USER=monitor
PASSWORD=xxxxxx
TIME=`date`
WHEREIS_MYSQL=/opt/mysql/bin/mysql
WEBHOOK='https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=bb09197b-5ff6-4928-9872-xxxxxx'

wx(){
cat > .msg << EOF
curl '$WEBHOOK' \
 -H 'Content-Type: application/json' \
 -d '
 {
  "msgtype": "text",
  "text": {
   "content": "",
  }
 }'
EOF
sh [+++].msg && rm -rf [+++].msg
}


Check_Mysql_Slave()
{
 $WHEREIS_MYSQL -u$USER -p$PASSWORD -h$SLAVE_IP -e "select version();" >/dev/null 2>&1
 if [ $? -ne 0 ];then
  echo "Mysql is stopped $DATE" >> /data/mysql/check.log
    ERROR="ERROR:Mysql-$SLAVE_IP cannot connect\n$TIME"
  wx "$ERROR"
 else
  #echo "1" >> /data/mysql/check.log
    IO_SQL_STATUS=`$WHEREIS_MYSQL -u$USER -p$PASSWORD -h$SLAVE_IP -e "show slave status \G" 2>/dev/null | awk '/Slave_.*_Running:/{print }'`
    for i in $IO_SQL_STATUS;do
      THREAD_STATUS_NAME=${i%:*}
      THREAD_STATUS=${i#*:}
      if [ "$THREAD_STATUS" != "Yes" ];then
        STATUS="ERROR:Mysql-$SLAVE_IP $THREAD_STATUS_NAME status is $THREAD_STATUS!\n$TIME"
    echo "$STATUS" >> /data/mysql/check.log
        wx "$STATUS"
      fi
    done
  fi
}

Check_Mysql_Slave

最终报警效果如下:

以上就是监控MySQL主从状态的shell脚本的详细内容,更多关于监控MySQL主从状态的资料请关注脚本之家其它相关文章!

)
File: /www/wwwroot/outofmemory.cn/tmp/route_read.php, Line: 126, InsideLink()
File: /www/wwwroot/outofmemory.cn/tmp/index.inc.php, Line: 165, include(/www/wwwroot/outofmemory.cn/tmp/route_read.php)
File: /www/wwwroot/outofmemory.cn/index.php, Line: 30, include(/www/wwwroot/outofmemory.cn/tmp/index.inc.php)
Error[8]: Undefined offset: 10, File: /www/wwwroot/outofmemory.cn/tmp/plugin_ss_superseo_model_superseo.php, Line: 121
File: /www/wwwroot/outofmemory.cn/tmp/plugin_ss_superseo_model_superseo.php, Line: 473, decode(

监控MySQL主从状态的shell脚本

分享一个Linux下,监控MySQL主从状态及配合企业微信机器人报警的Shell脚本

#! /bin/bash
#
source /etc/profile
export PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"

SLAVE_IP=`ip add | grep inet | grep brd | awk -F / '{print }' | awk -F " " '{print }' | awk 'NR==1'`
USER=monitor
PASSWORD=xxxxxx
TIME=`date`
WHEREIS_MYSQL=/opt/mysql/bin/mysql
WEBHOOK='https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=bb09197b-5ff6-4928-9872-xxxxxx'

wx(){
cat > .msg << EOF
curl '$WEBHOOK' \
 -H 'Content-Type: application/json' \
 -d '
 {
  "msgtype": "text",
  "text": {
   "content": "",
  }
 }'
EOF
sh .msg && rm -rf [+++].msg
}


Check_Mysql_Slave()
{
 $WHEREIS_MYSQL -u$USER -p$PASSWORD -h$SLAVE_IP -e "select version();" >/dev/null 2>&1
 if [ $? -ne 0 ];then
  echo "Mysql is stopped $DATE" >> /data/mysql/check.log
    ERROR="ERROR:Mysql-$SLAVE_IP cannot connect\n$TIME"
  wx "$ERROR"
 else
  #echo "1" >> /data/mysql/check.log
    IO_SQL_STATUS=`$WHEREIS_MYSQL -u$USER -p$PASSWORD -h$SLAVE_IP -e "show slave status \G" 2>/dev/null | awk '/Slave_.*_Running:/{print }'`
    for i in $IO_SQL_STATUS;do
      THREAD_STATUS_NAME=${i%:*}
      THREAD_STATUS=${i#*:}
      if [ "$THREAD_STATUS" != "Yes" ];then
        STATUS="ERROR:Mysql-$SLAVE_IP $THREAD_STATUS_NAME status is $THREAD_STATUS!\n$TIME"
    echo "$STATUS" >> /data/mysql/check.log
        wx "$STATUS"
      fi
    done
  fi
}

Check_Mysql_Slave

最终报警效果如下:

以上就是监控MySQL主从状态的shell脚本的详细内容,更多关于监控MySQL主从状态的资料请关注脚本之家其它相关文章!

)
File: /www/wwwroot/outofmemory.cn/tmp/route_read.php, Line: 126, InsideLink()
File: /www/wwwroot/outofmemory.cn/tmp/index.inc.php, Line: 165, include(/www/wwwroot/outofmemory.cn/tmp/route_read.php)
File: /www/wwwroot/outofmemory.cn/index.php, Line: 30, include(/www/wwwroot/outofmemory.cn/tmp/index.inc.php)
监控MySQL主从状态的shell脚本_mysql_内存溢出

监控MySQL主从状态的shell脚本

监控MySQL主从状态的shell脚本,第1张

监控MySQL主从状态的shell脚本

分享一个Linux下,监控MySQL主从状态及配合企业微信机器人报警的Shell脚本

  • SLAVE_IP:为监控的主机IP
  • USER:为msyql用户
  • PASSWORD:为mysql密码
  • WHEREIS_MYSQL:为mysql命令路径
  • WEBHOOK:为企业微信机器人Webhook地址
  • wx():为企业微信机器人函数
  • Check_Mysql_Slave():为监控脚本主函数
#! /bin/bash
#
source /etc/profile
export PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"

SLAVE_IP=`ip add | grep inet | grep brd | awk -F / '{print }' | awk -F " " '{print }' | awk 'NR==1'`
USER=monitor
PASSWORD=xxxxxx
TIME=`date`
WHEREIS_MYSQL=/opt/mysql/bin/mysql
WEBHOOK='https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=bb09197b-5ff6-4928-9872-xxxxxx'

wx(){
cat > .msg << EOF
curl '$WEBHOOK' \
 -H 'Content-Type: application/json' \
 -d '
 {
  "msgtype": "text",
  "text": {
   "content": "",
  }
 }'
EOF
sh .msg && rm -rf .msg
}


Check_Mysql_Slave()
{
 $WHEREIS_MYSQL -u$USER -p$PASSWORD -h$SLAVE_IP -e "select version();" >/dev/null 2>&1
 if [ $? -ne 0 ];then
  echo "Mysql is stopped $DATE" >> /data/mysql/check.log
    ERROR="ERROR:Mysql-$SLAVE_IP cannot connect\n$TIME"
  wx "$ERROR"
 else
  #echo "1" >> /data/mysql/check.log
    IO_SQL_STATUS=`$WHEREIS_MYSQL -u$USER -p$PASSWORD -h$SLAVE_IP -e "show slave status \G" 2>/dev/null | awk '/Slave_.*_Running:/{print }'`
    for i in $IO_SQL_STATUS;do
      THREAD_STATUS_NAME=${i%:*}
      THREAD_STATUS=${i#*:}
      if [ "$THREAD_STATUS" != "Yes" ];then
        STATUS="ERROR:Mysql-$SLAVE_IP $THREAD_STATUS_NAME status is $THREAD_STATUS!\n$TIME"
    echo "$STATUS" >> /data/mysql/check.log
        wx "$STATUS"
      fi
    done
  fi
}

Check_Mysql_Slave

最终报警效果如下:

以上就是监控MySQL主从状态的shell脚本的详细内容,更多关于监控MySQL主从状态的资料请关注脚本之家其它相关文章!

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/sjk/888614.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-14
下一篇 2022-05-14

发表评论

登录后才能评论

评论列表(0条)

保存