collectd-memcached-bucket

Grab stats for individual buckets in the NorthMemCouchScaleBase bucket engine and shove them into collectd
git clone https://code.literati.org/collectd-memcached-bucket.git
Log | Files | Refs

commit 99fa3973ed3e04a9213d1b79d9481f83a36d6b12
parent 49c03d992bbe06293c4ba5c7cb78f47fc7ab677d
Author: Sean Lynch <seanl@literati.org>
Date:   Wed, 27 Jan 2010 22:03:52 +0000

Add aggregate stats

Diffstat:
Mcollectd_memcached_buckets.py | 68+++++++++++++++++++++++++++++++++++++++++++-------------------------
1 file changed, 43 insertions(+), 25 deletions(-)

diff --git a/collectd_memcached_buckets.py b/collectd_memcached_buckets.py @@ -1,5 +1,5 @@ #!/usr/bin/python -import sys, time +import sys, time, re sys.path = ['/usr/local/lib/python2.6/site-packages'] + sys.path import mc_bin_client @@ -32,32 +32,16 @@ APPEND_STAT("bytes_written", "%"PRIu64, thread_stats.bytes_written); """ +MASK = 134217727 + def get_hostname_from_collectd_config(fn): - import re data = open(fn).read() r = re.compile('^Hostname\s*"([^"]+)"$', re.IGNORECASE|re.MULTILINE) m = r.search(data) return m.group(1) if m is not None else None -def main(): - from optparse import OptionParser - - parser = OptionParser() - parser.add_option('-H', '--hostname', dest='hostname') - parser.add_option('-m', '--memcached-host', dest='memcached_host') - parser.add_option('-u', '--memcached-username', dest='memcached_username') - parser.add_option('-p', '--memcached-password', dest='memcached_password') - - options, args = parser.parse_args() - - mc = mc_bin_client.MemcachedClient(options.memcached_host or '127.0.0.1') - if options.memcached_username: - mc.sasl_auth_cram_md5(options.memcached_username, options.memcached_password) - hostname = options.hostname or get_hostname_from_collectd_config('/etc/collectd/collectd.conf') - assert hostname - plugin = 'memcached_bucket' - type = 'memcached_bucket' +def get_bucket_stats(mc): ops = ['cmd_get', 'cmd_set', 'cmd_flush', @@ -77,15 +61,49 @@ def main(): 'evictions', ] + stats = mc.stats() + return [ int(stats[op]) & MASK for op in ops ] + + +def put_values(c, hostname, bucket, now, values): + identifier = pycollectd.Identifier(hostname, 'memcached_bucket', None, 'memcached_bucket', bucket) + c.putval(identifier, now, values) + + +def main(): + from optparse import OptionParser + + parser = OptionParser() + parser.add_option('-H', '--hostname', dest='hostname') + parser.add_option('-m', '--memcached-host', dest='memcached_host') + parser.add_option('-u', '--memcached-username', dest='memcached_username') + parser.add_option('-p', '--memcached-password', dest='memcached_password') + + options, args = parser.parse_args() + + mc = mc_bin_client.MemcachedClient(options.memcached_host or '127.0.0.1') + if options.memcached_username: + mc.sasl_auth_cram_md5(options.memcached_username, options.memcached_password) + + hostname = options.hostname or get_hostname_from_collectd_config('/etc/collectd/collectd.conf') + assert hostname c = pycollectd.Exec() l = mc.bucket_list() now = time.time() - for bucket in sorted(l): - identifier = pycollectd.Identifier(hostname, plugin, None, type, bucket) + totals = None + for bucket in l: mc.bucket_select(bucket) - stats = mc.stats() - values = [ stats[op] for op in ops ] - c.putval(identifier, now, values) + values = get_bucket_stats(mc) + if totals is None: + totals = values[:] + else: + for i in xrange(len(totals)): + totals[i] += values[i] + totals[i] &= MASK + + put_values(c, hostname, bucket, now, values) + + put_values(c, hostname, 'ALL', now, totals) if __name__ == '__main__':