Command line stats

Steven Grimm sgrimm at facebook.com
Sun Feb 4 19:31:50 UTC 2007


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.

-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