Wednesday, February 16, 2011

A simple munin graphing script that uses mk-heartbeat to monitor replication lag between two MySQL servers. Place it in your /etc/munin/plugins/ directory and configure your environment.
/etc/munin/plugin-conf.d//mysql
[mysql_*]
env.mysqlconnection DBI:mysql:mysql
env.mysqluser Reporter
env.mysqlpassword Blah


/etc/munin/plugins/mysql_replication_lag

#!/bin/sh
#
# Plugin to monitor the mysql replication lag
#
# Parameters:
#
# config (required)
# autoconf (optional - used by munin-config)
#
# $Log$
# Revision 1: Tue Feb 15 17:04:59 MUT 2011
# Initial writeup and testing
#
#
#
# Magic markers (Used by munin-config and some installation scripts.
# Optional):
#
#%# family=auto
#%# capabilities=autoconf

if [ "$1" = "autoconf" ]; then
echo yes
exit 0
fi

if [ "$1" = "config" ]; then

echo 'graph_title Replication Lag'
echo 'graph_args --base 1000 -l 0'
echo 'graph_vlabel Replication lag in seconds'
echo 'graph_category mysql'
echo 'graph_info This graph monitors the replication lag using mk-heartbeat.'
echo 'lag.label Lag in seconds'
echo 'lag.warning :300'
echo 'lag.warning :3600'
echo 'lag.info The number of currently open files.'
exit 0
fi
echo -n "lag.value "
mysql -u ${mysqluser} -p${mysqlpassword} -B -N -e "select now()-ts as replication_lag from maatkit.heartbeat;"

No comments:

Post a Comment