Skip to content

Instantly share code, notes, and snippets.

@hoffrocket
Created September 28, 2011 22:25
Show Gist options
  • Save hoffrocket/1249424 to your computer and use it in GitHub Desktop.
Save hoffrocket/1249424 to your computer and use it in GitHub Desktop.
ganglia kestrel plugin
#!/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