Hi,

I have written a small Python metric module that contains one metric,
CacheHits. When the module is included in the configuration, gmond spits out
the following error message,

Unable to collect metric 'CacheHits' on this platform. Exiting.

As far as I can tell, gmond is parsing the configuration file and accepting
the data in it, but cannot seem to find/run the handler for the metric. I
have compiled and run the Python module and it works standalone. Is there
any way to get gmond to provide more detail on what is failing?

The configuration file and the python module are included below,

#
#  Ganglia module configuration for Memcached
#

modules {
  module {
    name = "memcached"
    language = "python"
  }
}


collection_group {
  collect_every = 10
  time_threshold = 50
  metric {
    name = "CacheHits"
    title = "Memcached Hit Percentage"
    value_threshold = 1
  }
}



cat memcached.py
#/****************************
***************************************************
#    Memcached Ganglia Module
#    Sid Stuart 6/24/2008
#   Copyright Kongregate.com
#   License to use, modiy, and distribute under the GPL
#   http://www.gnu.org/licenses/gpl.txt
#
#   This module has two handlers,
#        slab_handler
#        statistics_handler
#
#******************************************************************************/

import os

statsTool = "/usr/bin/memcached-tool localhost:11211 stats"
slabTool = "/usr/bin/memcached-tool localhost:11211 display"

#
#    Run the memcached-tool command, parse the output and format it for
rrdtool
#
def slab_handler (name):
    return

#
#    Run the memcached-tool command, parse the output and format it for
rrdtool
def statistics_handler (name):
    if name == "CacheHits":
        return cacheHits ()

_descriptors = [{'name': 'CacheHits',
        'call_back': statistics_handler,
        'time-max': 30,
        'value_type': 'uint',
        'units': 'Percentage',
        'slope': 'both',
        'format': '%u',
        'description': 'Cache hit rate',
        'groups': 'memcached',
        }]
#
#    Part of the Ganglia Module template
#
def metric_init(params):

    return _descriptors

#
# Part of the Ganglia Module template
#
def metric_cleanup():
    '''Clean up the metric module.'''
    pass

###
#    Calculate and return the hit rate of the cache.
def cacheHits ():
    handle = os.popen (statsTool)
    for eachLine in handle:
        eachLine.strip ()
        words = eachLine.split ()
        if (words[0] == "get_hits"):
            hits = words[1]
        elif (words[0] == "get_misses"):
            misses = words [1]
    if (hits.isdigit() & misses.isdigit()):
        hits = float(hits)
        misses = float (misses)
    hitrate = (hits/(hits+misses)) * 100  # Percentage
        hitrage = int (hitrate)  # Convert to int to truncate the value.
    return hitrate

#This code is for debugging and unit testing
if __name__ == '__main__':
    metric_init('void')
    for d in _descriptors:
        v = d['call_back'](d['name'])
        print 'value for %s is %u' % (d['name'],  v)
-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Ganglia-general mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ganglia-general

Reply via email to