root / plugins / mysql / mysql_size_ @ 17f78427
Historique | Voir | Annoter | Télécharger (3,34 ko)
| 1 |
#!/usr/bin/perl |
|---|---|
| 2 |
# |
| 3 |
# Copyright (C) 2007 - Rodolphe Quiedeville <rodolphe@quiedeville.org> |
| 4 |
# Copyright (C) 2003-2004 - Andreas Buer |
| 5 |
# |
| 6 |
# This program is free software; you can redistribute it and/or |
| 7 |
# modify it under the terms of the GNU General Public License |
| 8 |
# as published by the Free Software Foundation; version 2 dated June, |
| 9 |
# 1991. |
| 10 |
# |
| 11 |
# This program is distributed in the hope that it will be useful, |
| 12 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 |
# GNU General Public License for more details. |
| 15 |
# |
| 16 |
# You should have received a copy of the GNU General Public License |
| 17 |
# along with this program; if not, write to the Free Software |
| 18 |
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 19 |
# |
| 20 |
# $Log$ |
| 21 |
# Revision 1.1 2007/01/17 10:41:01 rodo |
| 22 |
# Change incorrect family |
| 23 |
# |
| 24 |
# Revision 1.0 2007/01/16 15:57:01 rodo |
| 25 |
# Created by Rodolphe Quiedeville |
| 26 |
# |
| 27 |
# Parameters: |
| 28 |
# |
| 29 |
# config |
| 30 |
# autoconf |
| 31 |
# |
| 32 |
# Configuration variables |
| 33 |
# |
| 34 |
# mysqlopts - Options to pass to mysql |
| 35 |
# mysqladmin - Override location of mysqladmin |
| 36 |
# |
| 37 |
#%# family=manual |
| 38 |
#%# capabilities=autoconf |
| 39 |
|
| 40 |
use strict; |
| 41 |
|
| 42 |
unless ($0 =~ /mysql_size(?:_([^_]+)|)_(.+)\s*$/) |
| 43 |
{
|
| 44 |
die "Could not parse name $0.\n"; |
| 45 |
} |
| 46 |
my $db = $2; |
| 47 |
|
| 48 |
my $MYSQLADMIN = $ENV{mysqladmin} || "mysql";
|
| 49 |
|
| 50 |
my %WANTED = ( "Index" => "index", |
| 51 |
"Datas" => "datas", |
| 52 |
); |
| 53 |
|
| 54 |
my $arg = shift(); |
| 55 |
|
| 56 |
if ($arg eq 'config') {
|
| 57 |
print_config(); |
| 58 |
exit(); |
| 59 |
} elsif ($arg eq 'autoconf') {
|
| 60 |
unless (test_service() ) {
|
| 61 |
print "yes\n"; |
| 62 |
} else {
|
| 63 |
print "no\n"; |
| 64 |
} |
| 65 |
exit; |
| 66 |
} |
| 67 |
|
| 68 |
my $datas = 0; |
| 69 |
my $indexes = 0; |
| 70 |
my (@infos,$info,$i_data,$i_index); |
| 71 |
|
| 72 |
my $COMMAND = "$MYSQLADMIN $ENV{mysqlopts} $db -e 'show table status;' | grep 'Data'";
|
| 73 |
|
| 74 |
open(SERVICE, "$COMMAND |") |
| 75 |
or die("Coult not execute '$COMMAND': $!");
|
| 76 |
|
| 77 |
while (<SERVICE>) {
|
| 78 |
(@infos) = split; |
| 79 |
} |
| 80 |
close(SERVICE); |
| 81 |
|
| 82 |
my $i = 0; |
| 83 |
foreach $info (@infos) {
|
| 84 |
$i++; |
| 85 |
if ($info eq 'Data_length') {
|
| 86 |
$i_data = $i; |
| 87 |
next; |
| 88 |
} |
| 89 |
if ($info eq 'Index_length') {
|
| 90 |
$i_index = $i; |
| 91 |
last; |
| 92 |
} |
| 93 |
} |
| 94 |
|
| 95 |
$COMMAND = "$MYSQLADMIN $ENV{mysqlopts} $db -e 'show table status;' | cut -f $i_data,$i_index | grep -v leng";
|
| 96 |
|
| 97 |
open(SERVICE, "$COMMAND |") |
| 98 |
or die("Coult not execute '$COMMAND': $!");
|
| 99 |
|
| 100 |
while (<SERVICE>) {
|
| 101 |
(m/(\d+).*?(\d+(?:\.\d+)?)/); |
| 102 |
$datas += $1; |
| 103 |
$indexes += $2; |
| 104 |
} |
| 105 |
close(SERVICE); |
| 106 |
|
| 107 |
print("datas.value $datas\n");
|
| 108 |
print("index.value $indexes\n");
|
| 109 |
|
| 110 |
|
| 111 |
sub print_config {
|
| 112 |
|
| 113 |
my $num = 0; |
| 114 |
|
| 115 |
print("graph_title MySQL database $db size\n");
|
| 116 |
print ('graph_args --base 1024 -l 0
|
| 117 |
graph_vlabel bytes |
| 118 |
graph_category db |
| 119 |
graph_info Plugin available at <a href="http://rodolphe.quiedeville.org/hack/munin/">http://rodolphe.quiedeville.org/hack/munin/</a> |
| 120 |
'); |
| 121 |
|
| 122 |
for my $key (keys %WANTED) {
|
| 123 |
my $title = $WANTED{$key};
|
| 124 |
print("$title.label ${title}\n",
|
| 125 |
"$title.min 0\n", |
| 126 |
"$title.type GAUGE\n", |
| 127 |
"$title.draw ", ($num) ? "STACK" : "AREA" , "\n", |
| 128 |
); |
| 129 |
$num++; |
| 130 |
} |
| 131 |
} |
| 132 |
|
| 133 |
|
| 134 |
sub test_service {
|
| 135 |
|
| 136 |
my $return = 1; |
| 137 |
|
| 138 |
system ("$MYSQLADMIN --version >/dev/null 2>/dev/null");
|
| 139 |
if ($? == 0) |
| 140 |
{
|
| 141 |
system ("$COMMAND >/dev/null 2>/dev/null");
|
| 142 |
if ($? == 0) |
| 143 |
{
|
| 144 |
print "yes\n"; |
| 145 |
$return = 0; |
| 146 |
} |
| 147 |
else |
| 148 |
{
|
| 149 |
print "no (could not connect to mysql)\n"; |
| 150 |
} |
| 151 |
} |
| 152 |
else |
| 153 |
{
|
| 154 |
print "no (mysqladmin not found)\n"; |
| 155 |
} |
| 156 |
exit $return; |
| 157 |
} |
