Projet

Général

Profil

Paste
Télécharger au format
Statistiques
| Branche: | Révision:

root / plugins / mysql / mysql_slave @ 868937c8

Historique | Voir | Annoter | Télécharger (2,64 ko)

1
#!/usr/bin/perl
2
#
3
# Copyright (C) 2008 - Nathan Haneysmith <nathan@hjksolutions.com>
4
# Copyright (C) 2007 - Rodolphe Quiedeville <rodolphe@quiedeville.org>
5
# Copyright (C) 2003-2004 - Andreas Buer
6
#
7
# This program is free software; you can redistribute it and/or
8
# modify it under the terms of the GNU General Public License
9
# as published by the Free Software Foundation; version 2 dated June,
10
# 1991.
11
#
12
# This program is distributed in the hope that it will be useful,
13
# but WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
# GNU General Public License for more details.
16
#
17
# You should have received a copy of the GNU General Public License
18
# along with this program; if not, write to the Free Software
19
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
20
#
21
# $Log$
22
# Revision 1.2 2008/06/18 Nathan Haneysmith
23
# Massive rewrite to check and graph MySQL Slave status
24
#
25
# Revision 1.1  2007/01/17 10:41:01  rodo
26
# Change incorrect family
27
#
28
# Revision 1.0  2007/01/16 15:57:01  rodo
29
# Created by Rodolphe Quiedeville
30
#
31
# Parameters:
32
#
33
#   config
34
#   autoconf
35
#
36
# Configuration variables
37
#
38
#   mysqlopts     - Options to pass to mysql
39
#   mysqladmin    - Override location of mysqladmin
40
#
41
#%# family=manual
42
#%# capabilities=autoconf
43

    
44
use strict;
45

    
46
my $MYSQLADMIN = $ENV{mysqladmin} || "mysql";
47
my $MYSQLOPTS = $ENV{mysqlopts} || "";
48
my $COMMAND = "$MYSQLADMIN $MYSQLOPTS -e 'show slave status\\G' | grep 'Seconds_Behind_Master'";
49

    
50
my $arg = shift();
51

    
52
if ($arg eq 'config') {
53
    print_config();
54
    exit();
55
} elsif ($arg eq 'autoconf') {
56
    unless (test_service() ) {
57
        print "yes\n";
58
    } else {
59
        print "no\n";
60
    }
61
    exit;
62
}
63

    
64
my $seconds = 0;
65
my (@infos,$info,$i_seconds);
66

    
67
my $info = `$COMMAND`;
68
if($info =~ /: (\d+)/) {
69
  print("seconds.value $1\n");
70
} else {
71
  print("seconds.value U\n");
72
}
73

    
74

    
75
sub print_config {
76

    
77
  print "graph_title MySQL Slave Status\n";
78
  print "graph_args --base 1000 -l 0\n";
79
  print "graph_vlabel Seconds\n";
80
  print "graph_category mysql\n";
81
  print "seconds.label Seconds behind master\n";
82
  print "seconds.min 0\n";
83
  print "seconds.draw LINE2\n";
84
  print "graph_info Plugin available at <a href='http://oss.hjksolutions.com/munin/'>http://oss.hjksolutions.com/munin/</a>\n";
85

    
86
}
87

    
88

    
89
sub test_service {
90

    
91
    my $return = 1;
92

    
93
    system ("$MYSQLADMIN --version >/dev/null 2>/dev/null");
94
    if ($? == 0)
95
    {
96
	system ("$COMMAND >/dev/null 2>/dev/null");
97
	if ($? == 0)
98
	{
99
	    print "yes\n";
100
	    $return = 0;
101
	}
102
	else
103
	{
104
	    print "no (could not connect to mysql)\n";
105
	}
106
    }
107
    else
108
    {
109
	print "no (mysqladmin not found)\n";
110
    }
111
    exit $return;
112
}