Skip to content

Instantly share code, notes, and snippets.

@0xAB41
Created October 4, 2013 15:37
Show Gist options
  • Save 0xAB41/6827960 to your computer and use it in GitHub Desktop.
Save 0xAB41/6827960 to your computer and use it in GitHub Desktop.
quick script to calculate hit ratio of memcached servers
#!/usr/bin/env python
#run the following bash one liner to gather statistics first followed by python script to calculate hit ratio & average hit ratio
#for i in mem-node{1..30}; do (echo "stats"; sleep 2 ) | telnet $i 11211 | grep get_ ; done > stats; python avg.py stats
import sys
from __future__ import division
x = [int(i.strip().split()[2]) for i in open(sys.argv[1]).readlines()]
hitratios=[x[2*i]/(x[2*i]+x[2*i+1]) for i in range(len(x)/2)]
for hr in hitratios:
print hr
print "average: "+str(sum(hitratios)/len(hitratios))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment