Skip to content

Instantly share code, notes, and snippets.

@tjstein
Created May 16, 2010 20:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tjstein/403143 to your computer and use it in GitHub Desktop.
Save tjstein/403143 to your computer and use it in GitHub Desktop.
memcached
#!/usr/bin/perl -w
#
# Copyright (C) 2008 Rodolphe Quiedeville <rodolphe@quiedeville.org>
#
# 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/02 21:04: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\n";
print "graph_args --base 1000 -l 0\n";
print "graph_vlabel nb\n";
print "graph_category memcached\n";
print 'graph_info Plugin available at <a href="http://rodolphe.quiedeville.org/hack/munin/">http://rodolphe.quiedeville.org/hack/munin/</a>'."\n";
print "items.draw AREA\n";
print "items.label items\n";
print "conx.draw LINE\n";
print "conx.label conx\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 cleanly
$pop->print("quit");
## output values
printf "items.value %d\n",$stats->{curr_items};
printf "conx.value %d\n",$stats->{curr_connections};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment