#!/usr/bin/perl -w # # Copyright (C) 2008 Rodolphe Quiedeville # # 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. # # If you improve this script please send your version to my email address # with the copyright notice upgrade with your name. # # # $Log$ # Revision 1.1 2008/08/08 10:40:01 rodo # Created by Rodolphe Quiedeville # #%# family=memcached #%# capabilities=autoconf use strict; my $ret = undef; if (! eval "require Net::Telnet;") { $ret = "Net::Telnet not found"; } my $host = exists $ENV{'host'} ? $ENV{'host'} : "127.0.0.1"; my $port = exists $ENV{'port'} ? $ENV{'port'} : "11211"; if ($ARGV[0] and $ARGV[0] eq "autoconf") { my $pop = new Net::Telnet (Timeout => 5, Telnetmode => 0, Errmode => "return"); if ($pop->open(Host => $host, Port => $port)) { print "yes\n"; } else { print "no\n"; } exit 0; } if ($ARGV[0] and $ARGV[0] eq "config") { print "graph_title Memcached size used\n"; print "graph_args --base 1000 -l 0\n"; print "graph_vlabel bytes\n"; print "graph_category memcached\n"; print 'graph_info Plugin available at http://rodolphe.quiedeville.org/hack/munin/'."\n"; print "size.draw AREA\n"; print "size.label size\n"; exit 0; } my $pop = new Net::Telnet (Telnetmode => 0); $pop->open(Host => $host, Port => $port); ## Send command. $pop->print("stats"); my ($result,$line,$stats); while (($line = $pop->getline) and ($line !~ /END/o)) { $result = $line if $line =~ /STAT/; my $nb = (split ' ',$result)[2]; my $data = (split ' ',$result)[1]; $stats->{$data} = $nb; } ## Closing connection properly $pop->print("quit"); ## output values printf "size.value %d\n",$stats->{bytes};