Created
August 10, 2011 05:37
-
-
Save admackin/1136206 to your computer and use it in GitHub Desktop.
Cron script to check for MySQL replication problems
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/python -Wignore::DeprecationWarning | |
""" | |
Call this as a cron script to check for replication problems | |
""" | |
import MySQLdb | |
DB_HOST = '127.0.0.1' | |
DB_USER = 'USERNAME' | |
DB_PASSWD = 'PASSWORD' | |
conn = MySQLdb.connect(host=DB_HOST, user=DB_USER, passwd=DB_PASSWD) | |
cursor = MySQLdb.cursors.DictCursor(conn) | |
cursor.execute("show slave status"); | |
row = cursor.fetchone() | |
if not (row["Slave_IO_Running"] == "Yes" and row["Slave_SQL_Running"] == "Yes" and | |
row["Last_Errno"] == 0 and row["Seconds_Behind_Master"] < 120): | |
print "MySQL replication error:" | |
for k, v in row.iteritems(): | |
print "%s:\t%r" % (k, v) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment