-
-
Save moos3/be4f0a26951cbda07e90fd4080da587e to your computer and use it in GitHub Desktop.
MySQL replication catch-up stats script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# Updated/fixed version of the script from: | |
# https://www.percona.com/blog/2012/08/29/heres-a-quick-way-to-foresee-if-replication-slave-is-ever-going-to-catch-up-and-when/ | |
delay=60 | |
echo -e "Stats will be output every ${delay}s...\n" | |
cmd="mysql -e 'show slave status\G' | awk '/Seconds_Behind_Master/ { print \$2 }'" | |
while sleep $delay; do | |
eval $cmd | |
done | awk -v delay=$delay ' | |
{ | |
passed += delay; | |
if (count%10==0) | |
printf("s_behind h_behind | c_sec_s eta_h | O_c_sec_s O_eta_h\n"); | |
if (prev==NULL){ | |
prev = $1; | |
start = $1; | |
} | |
speed = (prev-$1)/delay; | |
o_speed = (start-$1)/passed | |
eta_h = (speed > 0) ? sprintf("%7.1f", $1/(speed*3600)) : "Inf"; | |
o_eta_h = (o_speed > 0) ? sprintf("%7.1f", $1/(o_speed*3600)) : "Inf"; | |
printf("%8d %8.2f | %7.3f %7s | %9.3f %7s\n", | |
$1, $1/3600, speed, eta_h, o_speed, o_eta_h); | |
prev=$1; | |
count++; | |
fflush(); | |
}' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment