Projet

Général

Profil

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

root / plugins / other / mysql_qcache_mem @ ba2f09ff

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

1 01e5fd7e 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/28 09:04:01  rodo
22
# Add lower limit fixed to 0
23
#
24
# Revision 1.0  2006/04/26 16:04: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=auto
38
#%# capabilities=autoconf
39
40
use strict;
41
42
my $MYSQLADMIN = $ENV{mysqladmin} || "mysqladmin";
43
my $COMMAND    = "$MYSQLADMIN $ENV{mysqlopts} extended-status";
44
my $COMMANDSIZE = "$MYSQLADMIN $ENV{mysqlopts} variables";
45
46
my %WANTED = ( "Qcache_free_memory" => "free" );
47
48
my $arg = shift();
49
50
if ($arg eq 'config') {
51
    print_config();
52
    exit();
53
} elsif ($arg eq 'autoconf') {
54
    unless (test_service() ) {
55
        print "yes\n";
56
    } else {
57
        print "no\n";
58
    }
59
    exit;
60
}
61
62
my ($free, $used) = (0,0);
63
64
open(SERVICE, "$COMMAND |")
65
  or die("Coult not execute '$COMMAND': $!");
66
67
while (<SERVICE>) {
68
    my ($k, $v) = (m/(\w+).*?(\d+(?:\.\d+)?)/);
69
    next unless ($k);
70
    if (exists $WANTED{$k} ) {
71
	$free = $v;
72
	print("$WANTED{$k}.value $v\n");
73
    }
74
}
75
close(SERVICE);
76
77
open(SERVICE, "$COMMANDSIZE |")
78
  or die("Coult not execute '$COMMANDSIZE': $!");
79
80
while (<SERVICE>) {
81
    my ($k, $v) = (m/(\w+).*?(\d+(?:\.\d+)?)/);
82
83
    next unless ($k);
84
    if ($k eq "query_cache_size" ) {
85
	print("used.value ",($v-$free),"\n");
86
    }
87
}
88
close(SERVICE);
89
90
sub print_config {
91
92
    print('graph_title MySQL Queries Cache Size
93
graph_args --base 1024 -l 0
94
graph_vlabel bytes
95
graph_category mysql
96
graph_order used free
97
graph_total Total
98
graph_info Plugin available at <a href="http://rodolphe.quiedeville.org/hack/munin/">http://rodolphe.quiedeville.org/hack/munin/</a>
99
used.label Used
100
used.draw AREA
101
free.label Free
102
free.draw STACK
103
');
104
}
105
106
sub test_service {
107
108
    my $return = 1;
109
110
    system ("$MYSQLADMIN --version >/dev/null 2>/dev/null");
111
    if ($? == 0)
112
    {
113
	system ("$COMMAND >/dev/null 2>/dev/null");
114
	if ($? == 0)
115
	{
116
	    print "yes\n";
117
	    $return = 0;
118
	}
119
	else
120
	{
121
	    print "no (could not connect to mysql)\n";
122
	}
123
    }
124
    else
125
    {
126
	print "no (mysqladmin not found)\n";
127
    }
128
    exit $return;
129
}