Munin: Plugin to monitor the Seconds_Behind_Master on mysql slave

ln -s /path/to/script /etc/munin/plugins/
/etc/init.d/munin-node restart

#!/bin/sh
# 
# Plugin to monitor the Seconds_Behind_Master of replication on a mysql slave
#
# Parameters:
# 
#       configure
#       autoconf
#
# Configuration variables
#
#       mysqlopts     - Options to pass to mysql
#
#
#%# family=auto
#%# capabilities=autoconf
 
MYSQLOPTS="$mysqlopts"
MYSQL=${mysql:-mysql}
 
if [ "$1" = "autoconf" ]; then
        $MYSQL --version 2>/dev/null >/dev/null
        if [ $? -eq 0 ]
        then
                $MYSQL $MYSQLOPTS -e '' 2>/dev/null >/dev/null
                if [ $? -eq 0 ]
                then
                        echo yes
                        exit 0
                else
                        echo "no (could not connect to mysql)"
                fi
        else
                echo "no (mysql not found)"
        fi
        exit 1
fi
 
if [ "$1" = "config" ]; then
        echo 'graph_title Replication lag'
        echo 'graph_args --base 1000 -l 0'
        echo 'graph_vlabel lag in secs'
        echo 'graph_category mysql'
        echo 'lag.label lag'
        exit 0
fi
 
/usr/bin/printf "lag.value "
mysql $MYSQLOPTS -e 'show slave status\G' | grep Seconds_Behind_Master | awk '{print $2}'