Actual combat: MySQL 5.6 Replication latency Monitoring

Source: Internet
Author: User

#repdelay. sh#!/bin/sh#[email protected] #查看复制延迟具体多少event #set mysql evnmysql_user_master=root mysql_pass_ master= ' password ' mysql_host_master=192.168.2.188mysql_user_slave=root mysql_pass_slave= ' password ' MYSQL_HOST_ Slave=192.168.2.14tmpfile_01= "tmp01. ' Date +%y%m%d%h%m%s '. txt" tmpfile_02= "tmp02. ' Date +%y%m%d%h%m%s '. txt ' mysql-h$ {mysql_host_master}-u${mysql_user_master}-p${mysql_pass_master}-e "SHOW BINARY LOGS;" >${tmpfile_01}mysql-h${ Mysql_host_slave}-u${mysql_user_slave}-p${mysql_pass_slave}-e "SHOW SLAVE status\g;" >${tmpfile_02} #tail-1 ${ TMPFILE_01} | Grep-v "Log_name" #cat ${tmpfile_02} | Grep-e ' master_log_file| read_master_log_pos| Exec_master_log_pos ' | Grep-v "Relay_master_log_file" |sed ' s/^[]*//g ' a= ' tail-1 ${tmpfile_01} | Grep-v "Log_name" |awk ' {print '} ' |awk-f '. "  ' {print $} ' b= ' sed-n '/\<master_log_file\>/p ' ${tmpfile_02} |sed ' s/^[]*//g ' |awk-f ': ' {print $} ' |awk-f '. " ' {print $} ' bhtime= ' sed-n '/\<seconds_behind_master\>/p ' ${tmpfile_02} |sed ' s/^[]*//g ' |awk-f ': ' {print $ {} ' if [' $b ' = ' $a '];thenc= ' tail-1 ${tmpfile_01} |  Grep-v "Log_name" |awk ' {print $} ' d= ' sed-n '/\<read_master_log_pos\>/p ' ${tmpfile_02} |sed ' s/^[]*//g ' |awk-f ":" ' {print $} ' e= ' expr $c-$d ' If ["${e}"-eq 0-a "${bhtime}"-eq 0]; Thenecho "*****************************************************************************" Echo-e "\e[1;31m & &&&&&&synchronization has been completed!&&&&&&& \e[0m "echo" * * "Elif [" ${e} "-eq 0-o" ${bhtime} "-eq 0]; Thenecho "*****************************************************************************" Echo-e "\e[1;31m has been Synchronized to the same log file! Wait a moment \e[0m "echo-e" \e[1;31m not synchronized Binlog events Is:${e},behind Master Tims is ${bhtime} \e[0m "echo" * *****************************************************************"Fielif [${b}-lt ${a}];thenf= ' Sed-n"/\<read_master_log_pos\>/p "${tmpfile_02} |sed ' s/^[]*//g ' |a Wk-f ":" ' {print $} ' g= ' awk ' >= ' $b ' {print $} ' ${tmpfile_01} |awk ' Begin{total=0}{total+=$1}end{print total} ' r E= ' expr $g-$f ' echo-e ' \e[1;31m there is multiple log files is not synchronized,the events Is:${re} \e[0m "Fir M-RF ${TMPFILE_01}RM-RF ${tmpfile_02}


Actual combat: MySQL 5.6 Replication latency Monitoring

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.