MySQL Replication Lag Monitoring Script
Master-slave replication is widely used in production. Monitoring the replication lag is a common and critical task. Typically, we are able to get the real-time difference between the master and the slave by periodically checking the Seconds_Behind_Master variable.
According to link
Seconds_Behind_Master: this field shows an approximation for difference between the current timestamp on the slave against the timestamp on the master for the event currently being processed on the slave.
Get the Seconds_Behind_Master value is easy, just run show slave status on the slave node. However, this command displays too much information so that it’s hard to find the key info. If you want to select only Seconds_Behind_Master from mysql system table, it’s a nightmare to find a
worked solution
for your mysql version.
Here the simple script helps:
Sample output of the script: