2008-07-01 01:09:27 +02:00
|
|
|
#!/usr/bin/perl
|
|
|
|
#
|
|
|
|
# Copyright (C) 2008 - Nathan Haneysmith <nathan@hjksolutions.com>
|
|
|
|
# Copyright (C) 2007 - Rodolphe Quiedeville <rodolphe@quiedeville.org>
|
|
|
|
# Copyright (C) 2003-2004 - Andreas Buer
|
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or
|
|
|
|
# modify it under the terms of the GNU General Public License
|
|
|
|
# as published by the Free Software Foundation; version 2 dated June,
|
|
|
|
# 1991.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program; if not, write to the Free Software
|
|
|
|
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
#
|
|
|
|
# $Log$
|
|
|
|
# Revision 1.2 2008/06/18 Nathan Haneysmith
|
|
|
|
# Massive rewrite to check and graph MySQL Slave status
|
|
|
|
#
|
|
|
|
# Revision 1.1 2007/01/17 10:41:01 rodo
|
|
|
|
# Change incorrect family
|
|
|
|
#
|
|
|
|
# Revision 1.0 2007/01/16 15:57:01 rodo
|
|
|
|
# Created by Rodolphe Quiedeville
|
|
|
|
#
|
|
|
|
# Parameters:
|
|
|
|
#
|
|
|
|
# config
|
|
|
|
# autoconf
|
|
|
|
#
|
|
|
|
# Configuration variables
|
|
|
|
#
|
|
|
|
# mysqlopts - Options to pass to mysql
|
|
|
|
# mysqladmin - Override location of mysqladmin
|
|
|
|
#
|
|
|
|
#%# family=manual
|
|
|
|
#%# capabilities=autoconf
|
|
|
|
|
|
|
|
use strict;
|
|
|
|
|
|
|
|
my $MYSQLADMIN = $ENV{mysqladmin} || "mysql";
|
|
|
|
my $MYSQLOPTS = $ENV{mysqlopts} || "";
|
2014-10-15 23:11:35 +02:00
|
|
|
my $COMMAND = "$MYSQLADMIN $MYSQLOPTS -e 'show slave status\\G' | grep 'Seconds_Behind_Master'";
|
2015-02-11 16:06:28 +01:00
|
|
|
my $WARNING = $ENV{mysql_slave_warning} || "60";
|
|
|
|
my $CRITICAL = $ENV{mysql_slave_warning} || "600";
|
2008-07-01 01:09:27 +02:00
|
|
|
|
|
|
|
my $arg = shift();
|
|
|
|
|
|
|
|
if ($arg eq 'config') {
|
|
|
|
print_config();
|
|
|
|
exit();
|
|
|
|
} elsif ($arg eq 'autoconf') {
|
|
|
|
unless (test_service() ) {
|
|
|
|
print "yes\n";
|
|
|
|
} else {
|
|
|
|
print "no\n";
|
|
|
|
}
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
my $seconds = 0;
|
|
|
|
my (@infos,$info,$i_seconds);
|
|
|
|
|
2014-10-15 23:11:35 +02:00
|
|
|
my $info = `$COMMAND`;
|
2014-10-16 20:34:50 +02:00
|
|
|
if($info =~ /: (\d+)/) {
|
|
|
|
print("seconds.value $1\n");
|
|
|
|
} else {
|
|
|
|
print("seconds.value U\n");
|
|
|
|
}
|
2008-07-01 01:09:27 +02:00
|
|
|
|
|
|
|
|
|
|
|
sub print_config {
|
|
|
|
|
|
|
|
print "graph_title MySQL Slave Status\n";
|
|
|
|
print "graph_args --base 1000 -l 0\n";
|
|
|
|
print "graph_vlabel Seconds\n";
|
2017-02-21 00:41:40 +01:00
|
|
|
print "graph_category db\n";
|
2008-07-01 01:09:27 +02:00
|
|
|
print "seconds.label Seconds behind master\n";
|
|
|
|
print "seconds.min 0\n";
|
|
|
|
print "seconds.draw LINE2\n";
|
2015-02-11 16:06:28 +01:00
|
|
|
print "seconds.warning $WARNING\n";
|
|
|
|
print "seconds.critical $CRITICAL\n";
|
2008-07-01 01:09:27 +02:00
|
|
|
print "graph_info Plugin available at <a href='http://oss.hjksolutions.com/munin/'>http://oss.hjksolutions.com/munin/</a>\n";
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
sub test_service {
|
|
|
|
|
|
|
|
my $return = 1;
|
|
|
|
|
|
|
|
system ("$MYSQLADMIN --version >/dev/null 2>/dev/null");
|
|
|
|
if ($? == 0)
|
|
|
|
{
|
|
|
|
system ("$COMMAND >/dev/null 2>/dev/null");
|
|
|
|
if ($? == 0)
|
|
|
|
{
|
|
|
|
print "yes\n";
|
|
|
|
$return = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
print "no (could not connect to mysql)\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
print "no (mysqladmin not found)\n";
|
|
|
|
}
|
|
|
|
exit $return;
|
|
|
|
}
|