Skip to content

Instantly share code, notes, and snippets.

@edmorley
Created September 28, 2016 11:46
Show Gist options
  • Save edmorley/f8589f4d6fa84df4cce1a13cbac83d98 to your computer and use it in GitHub Desktop.
Save edmorley/f8589f4d6fa84df4cce1a13cbac83d98 to your computer and use it in GitHub Desktop.
MySQL replication catch-up stats script
#!/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