From 01e5fd7e7ca4a13371c9faf10a24cf34ec90019c Mon Sep 17 00:00:00 2001 From: Rodolphe Quiedeville Date: Wed, 17 Jan 2007 10:23:31 +0100 Subject: [PATCH] Initial version --- plugins/other/mysql_qcache_mem | 129 +++++++++++++++++++++++++++++++++ 1 file changed, 129 insertions(+) create mode 100755 plugins/other/mysql_qcache_mem diff --git a/plugins/other/mysql_qcache_mem b/plugins/other/mysql_qcache_mem new file mode 100755 index 00000000..0fe06c31 --- /dev/null +++ b/plugins/other/mysql_qcache_mem @@ -0,0 +1,129 @@ +#!/usr/bin/perl +# +# Copyright (C) 2006 - Rodolphe Quiedeville +# 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.0 2006/04/28 09:04:01 rodo +# Add lower limit fixed to 0 +# +# Revision 1.0 2006/04/26 16:04:01 rodo +# Created by Rodolphe Quiedeville +# +# Parameters: +# +# config +# autoconf +# +# Configuration variables +# +# mysqlopts - Options to pass to mysql +# mysqladmin - Override location of mysqladmin +# +#%# family=auto +#%# capabilities=autoconf + +use strict; + +my $MYSQLADMIN = $ENV{mysqladmin} || "mysqladmin"; +my $COMMAND = "$MYSQLADMIN $ENV{mysqlopts} extended-status"; +my $COMMANDSIZE = "$MYSQLADMIN $ENV{mysqlopts} variables"; + +my %WANTED = ( "Qcache_free_memory" => "free" ); + +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 ($free, $used) = (0,0); + +open(SERVICE, "$COMMAND |") + or die("Coult not execute '$COMMAND': $!"); + +while () { + my ($k, $v) = (m/(\w+).*?(\d+(?:\.\d+)?)/); + next unless ($k); + if (exists $WANTED{$k} ) { + $free = $v; + print("$WANTED{$k}.value $v\n"); + } +} +close(SERVICE); + +open(SERVICE, "$COMMANDSIZE |") + or die("Coult not execute '$COMMANDSIZE': $!"); + +while () { + my ($k, $v) = (m/(\w+).*?(\d+(?:\.\d+)?)/); + + next unless ($k); + if ($k eq "query_cache_size" ) { + print("used.value ",($v-$free),"\n"); + } +} +close(SERVICE); + +sub print_config { + + print('graph_title MySQL Queries Cache Size +graph_args --base 1024 -l 0 +graph_vlabel bytes +graph_category mysql +graph_order used free +graph_total Total +graph_info Plugin available at http://rodolphe.quiedeville.org/hack/munin/ +used.label Used +used.draw AREA +free.label Free +free.draw STACK +'); +} + +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; +}