Command line stats

Garth Webb garth at sixapart.com
Mon Feb 5 02:18:31 UTC 2007


On Sun, 2007-02-04 at 11:31 -0800, Steven Grimm wrote:
> The problem here is not that echo sends the command early (after all, it 
> will just sit in nc's input buffer until nc is ready to read it) or a 
> bug in memcached, but rather that nc exits as soon as it gets 
> end-of-file on its standard input, before it has had a chance to read 
> memcached's response.
> 
> echo -e "stats\nquit" | nc -w1 memcached-host 11211
> 
> works fine. That tells nc to wait (1 second) for input before exiting.

Maybe I have a different version of 'nc'.  The man page for v1.10 says
thats '-w' tells nc to wait around for input up to a second before
quiting with the default being no timeout.  Indeed, on testing, I got
the same results as I did without it; sometimes I would be lucky and get
results, often I would get nothing.  The command prompt returned
immediately on all tests using '-w1' so it doesn't seem to be waiting
for anything.

Like I said originally, there are better ways to do this for real world
applications using Perl/Python/Java/etc, but for simple hacks ON linux
USING bach WITH caveats, the file descriptor foo works every time for
me.

If you can figure out a better, more portable method using 'nc', I'd
love to hear it!

Garth

> -Steve
> 
> 
> Brad Fitzpatrick wrote:
> > Hmm... I'd thought this was fixed awhile back.  I at least remember seeing
> > a patch for it?  Steven?
> >
> > Garth, what version is this?
> >
> >
> > On Sun, 4 Feb 2007, Garth Webb wrote:
> >
> >   
> >> 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