Command line stats

Tim Yardley liquid at haveheart.com
Sun Feb 4 20:52:53 UTC 2007


For those considering this solution, keep in mind that some distributions do
not include tcp/udp functionality in bash.  Debian's default package is an
example if I recall correctly.

One other gotcha to be aware of, on some (perhaps all) distributions, bash
uses file descriptors internally for certain operations.  It tends to start
at fd 10, so be careful if you use an fd higher than that for this solution
as you may overlap.

As Steven pointed out, -w1 is a better nc option than -i1 in this case.

/tmy

-----Original Message-----
From: memcached-bounces at lists.danga.com
[mailto:memcached-bounces at lists.danga.com] On Behalf Of Garth Webb
Sent: Sunday, February 04, 2007 12:30 PM
To: memcached at lists.danga.com
Subject: Command line stats

I've noticed a few people on the list pulling stats from memcached by
telneting to the memcached port.  The problem that you've probably found
(and what I found) was that something like this

  echo stats | nc memd-host 11211

doesn't work because the 'echo' sends "stats" a split second before the
connection is actually established.  So you have to cook thing up like:

  (sleep 1; echo stats) | nc memd-host 11211
  
  echo stats | nc -i1 memd-host 11211

This isn't ideal since you have to wait a full second to get any
information.  This isn't too bad with one memcached server, but with
several, the time to get a full report can be pretty long.

So, just as an FYI, here's some linux command line foo that we cooked up
that will return stats as quickly as memcached can be contacted and
return them:

  exec 9<>/dev/tcp/memd-host/11211 ; echo -e "stats\nquit" >&9; cat <&9

Obviously Perl/Python/Java will be able to do this for you, but this is
good for quick and dirty command line tools and simple monitoring
scripts.

Garth


More information about the memcached mailing list