MySQL replication Environment check script

Source: Internet
Author: User

Author: skate
Time: 2013/05/13

 

MySQL replication Environment check script

 

This script is deployed on the slave side. You can monitor the mysqld health, replication Environment Health, and replication latency of slave by text message or email.

 

Script: mysql_rep_moni.sh

#! /Bin/bash
### Author: skate
### Time: 2013-05-14
### Function: This script detects the mysqld health, replicaton health, replication latency

# VARIABLES
Pwd = pwd
Dir =/MySQL/script/
Ipaddr = 1.1.1.1

### Determine whether there is connection
Mysql_status = 'netstat-nl | awk' Nr> 2 {if ($4 ~ /. *: 3306/) {print "yes"; exit 0 }}''
If ["$ mysql_status" = "yes"]; then
Slave_status = 'mysql-uroot-p $ PWD-e "show slave status \ G" | grep "running" | awk '{if ($2! = "Yes") {print "no"; Exit 1 }}''
Slave_delay = 'mysql-uroot-p $ PWD-e "show slave status \ G" | grep "seconds_behind_master" | awk '{if ($2> = 0) {print $2; exit
0 }}''
Echo "delay" $ slave_delay
Echo "status" $ slave_status
### Replication is not working
If ["$ slave_status" = "no"]; then
Echo "slave is not working! "
Sh "$ dir" Y. Sh "phone" "$ ipaddr" "_ warn_zxg_rep" "$ ipaddr" "_ mysql_replication_is_not_working" "dba"
Sh "$ dir" Notify. Sh "email" "$ ipaddr" "_ error_zxg_rep" "mysql_replication_is_not_working" "dba"
### Replication is working, but replication have delay
Elif ["$ slave_status "! = "No"] & [$ slave_delay-ge 10]; then
Echo "slave is working, but replication have delay! "
Sh "$ dir" Y. Sh "phone" "$ ipaddr" "_ warn_zxg_rep" "$ ipaddr" "_ mysql_replication_is_delay: $ slave_delay" "dba"
Sh "$ dir" Notify. Sh "email" "$ ipaddr" "_ warn_zxg_rep" "mysql_replication_is_delay: $ slave_delay" "dba"
Else
Echo "slave is working ."
Fi
Else
Echo "mysqld is down! "
Sh "$ dir" Notify. Sh "email" "$ ipaddr" "_ error_zxg_mysqld" "$ ipaddr" "_ mysqld_is_down" "dba"

Sh "$ dir" Notify. Sh "phone" "$ ipaddr" "_ error_zxg_mysqld" "mysqld_is_down" "dba"
Fi

Create a scheduled crontab
*/5 * su-mysql-c "sh/MySQL/script/mysql_rep_moni.sh>/dev/null 2> & 1"

Note:
The preceding alarm API (notify. Sh) can be modified based on your usage.

 

------ End ------

 

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.