Google
 
Web unafbapune.blogspot.com

Friday, November 18, 2011

 

Scriptfu comparing memcached hit counts

If we have a text file "hosts" that contains all the host names in a memcached fleet, we can readily capture a snapshot of the memcached's "get_hits" counts of the entire fleet to a file "hits", like so:

for i in `cat hosts`
do
echo -ne 'stats\r\n' | nc -i1 $i:11211 | grep get_hits | cut -d ' ' -f3 | sed 's/[^0-9]//'
done | tee hits

(Do you see why we need to do the sed at the end ?) Anyhow, here is the fun part:

Given we have captured two files "hits.1" and "hits.2" at T1 and T2, how can we show the increments of the "get_hits" count of every host ? With a one-liner, that is :)

Solution:
paste -d '-' hits.2 hits.1 | xargs -I {} echo {} | bc -iq | paste hosts -
Neat, huh ?

Comments: Post a Comment

<< Home

This page is powered by Blogger. Isn't yours?