mirror of
https://github.com/munin-monitoring/contrib.git
synced 2018-11-08 00:59:34 +01:00
17f784270a
* remove trailing whitespace * remove empty lines at the end of files
158 lines
3.3 KiB
Perl
Executable File
158 lines
3.3 KiB
Perl
Executable File
#!/usr/bin/perl
|
|
#
|
|
# 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.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;
|
|
|
|
unless ($0 =~ /mysql_size(?:_([^_]+)|)_(.+)\s*$/)
|
|
{
|
|
die "Could not parse name $0.\n";
|
|
}
|
|
my $db = $2;
|
|
|
|
my $MYSQLADMIN = $ENV{mysqladmin} || "mysql";
|
|
|
|
my %WANTED = ( "Index" => "index",
|
|
"Datas" => "datas",
|
|
);
|
|
|
|
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 $datas = 0;
|
|
my $indexes = 0;
|
|
my (@infos,$info,$i_data,$i_index);
|
|
|
|
my $COMMAND = "$MYSQLADMIN $ENV{mysqlopts} $db -e 'show table status;' | grep 'Data'";
|
|
|
|
open(SERVICE, "$COMMAND |")
|
|
or die("Coult not execute '$COMMAND': $!");
|
|
|
|
while (<SERVICE>) {
|
|
(@infos) = split;
|
|
}
|
|
close(SERVICE);
|
|
|
|
my $i = 0;
|
|
foreach $info (@infos) {
|
|
$i++;
|
|
if ($info eq 'Data_length') {
|
|
$i_data = $i;
|
|
next;
|
|
}
|
|
if ($info eq 'Index_length') {
|
|
$i_index = $i;
|
|
last;
|
|
}
|
|
}
|
|
|
|
$COMMAND = "$MYSQLADMIN $ENV{mysqlopts} $db -e 'show table status;' | cut -f $i_data,$i_index | grep -v leng";
|
|
|
|
open(SERVICE, "$COMMAND |")
|
|
or die("Coult not execute '$COMMAND': $!");
|
|
|
|
while (<SERVICE>) {
|
|
(m/(\d+).*?(\d+(?:\.\d+)?)/);
|
|
$datas += $1;
|
|
$indexes += $2;
|
|
}
|
|
close(SERVICE);
|
|
|
|
print("datas.value $datas\n");
|
|
print("index.value $indexes\n");
|
|
|
|
|
|
sub print_config {
|
|
|
|
my $num = 0;
|
|
|
|
print("graph_title MySQL database $db size\n");
|
|
print ('graph_args --base 1024 -l 0
|
|
graph_vlabel bytes
|
|
graph_category db
|
|
graph_info Plugin available at <a href="http://rodolphe.quiedeville.org/hack/munin/">http://rodolphe.quiedeville.org/hack/munin/</a>
|
|
');
|
|
|
|
for my $key (keys %WANTED) {
|
|
my $title = $WANTED{$key};
|
|
print("$title.label ${title}\n",
|
|
"$title.min 0\n",
|
|
"$title.type GAUGE\n",
|
|
"$title.draw ", ($num) ? "STACK" : "AREA" , "\n",
|
|
);
|
|
$num++;
|
|
}
|
|
}
|
|
|
|
|
|
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;
|
|
}
|