Skip to content

Instantly share code, notes, and snippets.

@farshidce
Created August 21, 2012 16:49
Show Gist options
  • Save farshidce/3417197 to your computer and use it in GitHub Desktop.
Save farshidce/3417197 to your computer and use it in GitHub Desktop.
tapstatspoller
#!/usr/bin/python
# example ./poller.py localhost bucketname bucketpassword
from mc_bin_client import MemcachedClient
import time
import sys
from threading import Thread
stopped = False
def poller(ip,bucket,password):
mc = MemcachedClient(ip,11210)
mc.sasl_auth_plain(bucket,password)
count_fast = 0
tot_counter = 0
fast = 3
count_slow = 0
slow = 10
count_slower = 0
slower = 60
count_terrible = 0
terrible = 600
counter = 0
while tot_counter < 100000:
start = time.time()
mc.stats("tap")
end = time.time()
latency = end - start
if latency < fast:
count_fast = count_fast + 1
elif latency < slow:
count_slow = count_slow + 1
elif latency < slower:
count_slower = count_slower + 1
else:
count_terrible = counter_terrible + 1
counter = counter + 1
if counter == 1000:
counter = 0
print("***********************")
print("%s calls < %s seconds" %(count_fast, fast))
print("%s calls < %s seconds" %(count_slow,slow))
print("%s calls < %s seconds" %(count_slower,slower))
print("%s calls < %s seconds" %(count_terrible,terrible))
print("***********************")
if stopped:
break
tot_counter = tot_counter + 1
mc.close()
def main():
# print command line arguments
for arg in sys.argv[1:]:
print arg
try:
ip = sys.argv[1]
bucket = sys.argv[2]
if bucket == "default":
password = ""
else:
password = sys.argv[3]
threads = []
for i in range(4):
t = Thread(target=poller,args=(ip,bucket,password))
t.start()
threads.append(t)
except KeyboardInterrupt as ex:
print ex
stopped = True
print "Bye"
sys.exit()
except Exception as ex:
print ex
stopped = True
sys.exit()
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment