Memcache statistics from the command line
To help debug memcache issues it's really useful to be able to see the output of the stats
command. I got bored of using telnet to talk to the memcache daemon so I whipped up this simple Ruby script to spit out the statistics without all that fuss.
#! /usr/bin/env ruby
require 'socket'
socket = TCPSocket.open('localhost', '11211')
socket.send("stats\r\n", 0)
statistics = []
loop do
data = socket.recv(4096)
if !data || data.length == 0
break
end
statistics << data
if statistics.join.split(/\n/)[-1] =~ /END/
break
end
end
puts statistics.join()
You can verify that I've written this post by following the verification instructions:
curl -LO http://barkingiguana.com/2009/03/04/memcache-statistics-from-the-command-line.html.orig
curl -LO http://barkingiguana.com/2009/03/04/memcache-statistics-from-the-command-line.html.orig.asc
gpg --verify memcache-statistics-from-the-command-line.html.orig{.asc,}
If you'd like to have a conversation about this post, email craig@barkingiguana.com. I don't bite.