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

Hive doesn’t like the carriage return character

Have you ever run in to a situation where you count the number of rows for a table in a database, then dump it to CSV and then load it to HIVE only to find that number has changed? Well, you probably have carriage returns in your fields.... Continue →