root / plugins / mysql / mysql_slave @ c6f88968
Historique | Voir | Annoter | Télécharger (2,81 ko)
| 1 | 7445b9d4 | Andreas Buer/Rodolphe Quiedeville/Nathan Haneysmith | #!/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 | e9bda2ba | Colin Mollenhour | my $COMMAND = "$MYSQLADMIN $MYSQLOPTS -e 'show slave status\\G' | grep 'Seconds_Behind_Master'"; |
| 49 | 11971e9f | Ilia Kondrashov | my $WARNING = $ENV{mysql_slave_warning} || "60";
|
| 50 | my $CRITICAL = $ENV{mysql_slave_warning} || "600";
|
||
| 51 | 7445b9d4 | Andreas Buer/Rodolphe Quiedeville/Nathan Haneysmith | |
| 52 | my $arg = shift(); |
||
| 53 | |||
| 54 | if ($arg eq 'config') {
|
||
| 55 | print_config(); |
||
| 56 | exit(); |
||
| 57 | } elsif ($arg eq 'autoconf') {
|
||
| 58 | unless (test_service() ) {
|
||
| 59 | print "yes\n"; |
||
| 60 | } else {
|
||
| 61 | print "no\n"; |
||
| 62 | } |
||
| 63 | exit; |
||
| 64 | } |
||
| 65 | |||
| 66 | my $seconds = 0; |
||
| 67 | my (@infos,$info,$i_seconds); |
||
| 68 | |||
| 69 | e9bda2ba | Colin Mollenhour | my $info = `$COMMAND`; |
| 70 | 868937c8 | Colin Mollenhour | if($info =~ /: (\d+)/) {
|
| 71 | print("seconds.value $1\n");
|
||
| 72 | } else {
|
||
| 73 | print("seconds.value U\n");
|
||
| 74 | } |
||
| 75 | 7445b9d4 | Andreas Buer/Rodolphe Quiedeville/Nathan Haneysmith | |
| 76 | |||
| 77 | sub print_config {
|
||
| 78 | |||
| 79 | print "graph_title MySQL Slave Status\n"; |
||
| 80 | print "graph_args --base 1000 -l 0\n"; |
||
| 81 | print "graph_vlabel Seconds\n"; |
||
| 82 | 8af93fce | dipohl | print "graph_category db\n"; |
| 83 | 7445b9d4 | Andreas Buer/Rodolphe Quiedeville/Nathan Haneysmith | print "seconds.label Seconds behind master\n"; |
| 84 | print "seconds.min 0\n"; |
||
| 85 | print "seconds.draw LINE2\n"; |
||
| 86 | 11971e9f | Ilia Kondrashov | print "seconds.warning $WARNING\n"; |
| 87 | print "seconds.critical $CRITICAL\n"; |
||
| 88 | 7445b9d4 | Andreas Buer/Rodolphe Quiedeville/Nathan Haneysmith | print "graph_info Plugin available at <a href='http://oss.hjksolutions.com/munin/'>http://oss.hjksolutions.com/munin/</a>\n"; |
| 89 | |||
| 90 | } |
||
| 91 | |||
| 92 | |||
| 93 | sub test_service {
|
||
| 94 | |||
| 95 | my $return = 1; |
||
| 96 | |||
| 97 | system ("$MYSQLADMIN --version >/dev/null 2>/dev/null");
|
||
| 98 | if ($? == 0) |
||
| 99 | {
|
||
| 100 | system ("$COMMAND >/dev/null 2>/dev/null");
|
||
| 101 | if ($? == 0) |
||
| 102 | {
|
||
| 103 | print "yes\n"; |
||
| 104 | $return = 0; |
||
| 105 | } |
||
| 106 | else |
||
| 107 | {
|
||
| 108 | print "no (could not connect to mysql)\n"; |
||
| 109 | } |
||
| 110 | } |
||
| 111 | else |
||
| 112 | {
|
||
| 113 | print "no (mysqladmin not found)\n"; |
||
| 114 | } |
||
| 115 | exit $return; |
||
| 116 | } |
