MySQL Replication Slave Monitoring Script for Zenoss
To monitor a slave you need to check if
- Slave IO Thread is running (Alert when not running)
- Slave SQL Thread is running (Alert when not running)
- Seconds behind master (Alert when passes a certain threshold)
Zenoss expects the output of the script in format
property_name1:property_value1 property_name2:property_value2
Basically key value pairs separated by spaces. Here’s the python script:
#!/usr/bin/env python
import MySQLdb as mdb
import sys
host = sys.argv[1]
user = sys.argv[2]
password = 'some_password'
con = mdb.connect(host, user, password);
cur = con.cursor(mdb.cursors.DictCursor)
cur.execute('show slave status')
slave_status = cur.fetchone()
slave_file = slave_status["Seconds_Behind_Master"]
slave_sql_running = "1" if slave_status["Slave_SQL_Running"] == "Yes" else "0"
slave_io_running = "1" if slave_status["Slave_IO_Running"] == "Yes" else "0"
print "seconds:" + str(slave_file) + " slave_io_running:" + slave_io_running + " slave_sql_running:" + slave_sql_running