Skip to content

Instantly share code, notes, and snippets.

@admackin
Created August 10, 2011 05:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save admackin/1136206 to your computer and use it in GitHub Desktop.
Save admackin/1136206 to your computer and use it in GitHub Desktop.
Cron script to check for MySQL replication problems
#!/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