I used several different approaches, the simplest of which is using a PHP web page to check the status of the slave, and then getting standard monitoring tools to monitor the page. This is a good approach, as it means that existing monitoring tools can be used for alerts by checking the web page.
Example: checking the status of a database server on the db1.internal node
http://mywebserver.com/replicationtest.php?host=db1.internal
Always need to return "Yes"
replicationtest.php:
<?php $username="myrepadmin"; $password=""; $database="database"; mysql_connect($_REQUEST['host'],$username,$password); @mysql_select_db($database) or die( "Unable to select database"); $query="show slave status;"; $result=mysql_query($query); $arr = mysql_fetch_assoc($result); echo $arr['Slave_SQL_Running'] ; mysql_close(); ?>
You can also control Seconds_Behind_Master, Last_IO_Errno, Last_SQL_Errno, etc. You can control this web page from the outside or add it to many standard monitoring tools that can check the web page. I used the free service http://monitor.us
Alternatively, if you do not mind running third-party code in your internal http://newrelic.com infrastructure, we offer excellent server monitoring tools using the network interface and include the MySQL plugin, which provides a lot of great information, such as Query Analysis, InnoDB metrics and replication status using delay monitors. The new Relic specializes in monitoring web applications, but the free service allows you to track an unlimited number of servers.
I am currently using a combination of these tools with the above web page used to launch emergency alerts and NewRelic tools to view long-term performance and trend analysis.
source share