MySQL Replication Slave Monitoring Script for Zenoss

To monitor a slave you need to check if

  1. Slave IO Thread is running (Alert when not running)
  2. Slave SQL Thread is running (Alert when not running)
  3. 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
 
79
Kudos
 
79
Kudos

Now read this

Creating Presentations with Reveal.js

Late last year, I gave a talk at the Sift Science office in San Francisco on “Hadoop at Lookout - how Lookout uses the hadoop infrastructure to power internal analytics”. I used Reveal.js to present the talk in my browser! Reveal.js is a... Continue →