Skip to content

Instantly share code, notes, and snippets.

@bastos
Created October 14, 2008 12:51
Show Gist options
  • Save bastos/16708 to your computer and use it in GitHub Desktop.
Save bastos/16708 to your computer and use it in GitHub Desktop.
Some scripts to get memcached statistics. Choose your flavor! Usage: memcached.script ip port
#!/usr/bin/perl
# Thanks to http://lists.danga.com/pipermail/memcached/2003-October/000354.html
use IO::Socket;
my $socket = IO::Socket::INET->new( PeerAddr => $ARGV[0],
PeerPort => $ARGV[1],
Proto => "tcp",
Type => SOCK_STREAM)
or die($@);
print $socket "stats\n";
$out = <$socket>
while ($out ne "END\r\n") {
if ($out =~ m/STAT (\w+) ([0-9.]+)/) {
print "$1 $2\n";
}
$out = <$socket>
}
close($socket);
#!/usr/bin/ruby
require 'socket'
out = TCPSocket.open($*[0],$*[1]) do |socket|
socket.puts 'stats'
socket.puts 'quit'
socket.read
end
out.each { |line| print line.gsub(/STAT /,"") if line =~ /STAT (\w+) ([0-9.]+)/ }
#!/bin/sh
# Thanks to Matela, "usa netcat cara!" ;)
echo -e 'stats\nquit' | netcat $1 $2 | grep STAT | sed -e "s/STAT //" -e "s/ /\\t/"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment