Created
September 28, 2011 22:25
-
-
Save hoffrocket/1249424 to your computer and use it in GitHub Desktop.
ganglia kestrel plugin
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import memcache | |
import re | |
import subprocess | |
import sys | |
KESTREL_HOST = 'localhost:22133' | |
def record(name, value): | |
name = re.sub(r'\+', '-', name) | |
cmd = ('/usr/bin/gmetric', '--name=%s' % name, '--type=uint32', | |
'--value=%s' % value,) | |
print cmd | |
return subprocess.call(cmd) | |
def main(): | |
mcd = memcache.Client((KESTREL_HOST,)) | |
try: | |
stats = mcd.get_stats() | |
if not stats: | |
return -1 | |
stats = stats[0][1] | |
for k, v in stats.iteritems(): | |
if not k.startswith('queue_'): | |
continue | |
pieces = k.split('_') | |
if not pieces[-1] == 'items': | |
continue | |
if pieces[-2] in ('total', 'mem', 'expired'): | |
continue | |
record(k, v) | |
finally: | |
mcd.disconnect_all() | |
return 0 | |
if __name__ == '__main__': | |
sys.exit(main()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment