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()
Leave feedback...
Commenting is closed for this article.

Very useful, thanks! I’m sure I have seen a command line tool come with memcached but I can’t remember which distribution.