Projet

Général

Profil

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

root / plugins / other / mysql_qcache @ 2578e754

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

1 6f148b7c Rodolphe Quiedeville
#!/usr/bin/perl
2
#
3
# Copyright (C) 2006 - 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.0  2006/04/26 16:04:01  rodo
22
# Created by Rodolphe Quiedeville
23
#
24
# Parameters:
25
#
26
#   config
27
#   autoconf
28
#
29
# Configuration variables
30
#
31
#   mysqlopts     - Options to pass to mysql
32
#   mysqladmin    - Override location of mysqladmin
33
#
34
#%# family=auto
35
#%# capabilities=autoconf
36
37
use strict;
38
39
my $MYSQLADMIN = $ENV{mysqladmin} || "mysqladmin";
40
my $COMMAND    =      "$MYSQLADMIN $ENV{mysqlopts} extended-status";
41
42
my %WANTED = ( "Qcache_queries_in_cache" => "queries");
43
44
my %WANTEDTYPE = ( "Qcache_queries_in_cache" => "GAUGE");
45
46
my $arg = shift();
47
48
if ($arg eq 'config') {
49
    print_config();
50
    exit();
51
} elsif ($arg eq 'autoconf') {
52
    unless (test_service() ) {
53
        print "yes\n";
54
    } else {
55
        print "no\n";
56
    }
57
    exit;
58
}
59
60
61
open(SERVICE, "$COMMAND |")
62
  or die("Coult not execute '$COMMAND': $!");
63
64
while (<SERVICE>) {
65
    my ($k, $v) = (m/(\w+).*?(\d+(?:\.\d+)?)/);
66
    next unless ($k);
67
    if (exists $WANTED{$k} ) {
68
	print("$WANTED{$k}.value $v\n");
69
    }
70
}
71
72
close(SERVICE);
73
74
75
sub print_config {
76
77
    my $num = 0;
78
79
    print('graph_title MySQL Queries in cache
80
graph_args --base 1000
81
graph_vlabel queries
82
graph_category mysql
83
graph_info Plugin available at <a href="http://rodolphe.quiedeville.org/hack/munin/">http://rodolphe.quiedeville.org/hack/munin/</a>
84
');
85
86
    for my $key (keys %WANTED) {
87
        my $title = $WANTED{$key};
88
        print("$title.label ${title}\n",
89
              "$title.min 0\n",
90
              "$title.type ".$WANTEDTYPE{$key}."\n",
91
              "$title.max 500000\n",
92
              "$title.draw ", ($num) ? "STACK" : "AREA" ,  "\n",
93
             );
94
        $num++;
95
    }
96
    
97
}
98
99
100
sub test_service {
101
102
    my $return = 1;
103
104
    system ("$MYSQLADMIN --version >/dev/null 2>/dev/null");
105
    if ($? == 0)
106
    {
107
	system ("$COMMAND >/dev/null 2>/dev/null");
108
	if ($? == 0)
109
	{
110
	    print "yes\n";
111
	    $return = 0;
112
	}
113
	else
114
	{
115
	    print "no (could not connect to mysql)\n";
116
	}
117
    }
118
    else
119
    {
120
	print "no (mysqladmin not found)\n";
121
    }
122
    exit $return;
123
}