I'm having the same exact problem. I can run the if __name__ ==
'__main__' test and have the script define and execute the callbacks
via the descriptor list, but when running from gmond, all that gets
called is the metric_init()
I put an open in the init and set the open filename to global as a
test because I thought maybe I couldn't rely on STDOUT from inside the
hanlder. Only the metric_init writes to it depite my putting a file
write in the handler.
Any clue on why it's gmond's initializing but not calling the handler
in the module?
Heres' my pyconf:
modules {
module {
name = "dns"
language = "python"
}
}
collection_group {
collect_every = 20
time_threshold = 45
metric {
name = "zDNS_success"
title = "Temperature"
value_threshold = 10
}
metric {
name = "zDNS_nxrrset"
title = "Temperature"
value_threshold = 10
}
metric {
name = "zDNS_referral"
title = "Temperature"
value_threshold = 10
}
metric {
name = "zDNS_nxdomain"
title = "Temperature"
value_threshold = 10
}
metric {
name = "zDNS_recursion"
title = "Temperature"
value_threshold = 10
}
metric {
name = "zDNS_failure"
title = "Temperature"
value_threshold = 10
}
metric {
name = "zDNS_duplicate"
title = "Temperature"
value_threshold = 10
}
metric {
name = "zDNS_dropped"
title = "Temperature"
value_threshold = 10
}
}
###### Here's my python module:
#!/usr/bin/python
import re
import sys
import time
import subprocess
NamePrefix = 'zDNS'
LastRecord = {}
MaxAge = 30
descriptors = []
out_file = ''
def return_collection_data(collection_string):
global NamePrefix
collection_date_re = re.compile(r'^.*\(([0-9]+)\)$')
collection = filter(lambda x: x, collection_string.split('\n'))
collection_date = collection_date_re.search(collection.pop()).group(1)
collection_map = {}
for record in collection:
name, value = record.split()
name = '%s_%s' % (NamePrefix, name)
collection_map[name] = int(value)
return (int(collection_date), collection_map)
def return_latest_record():
collections_splitter_re =
re.compile(r'^\+\+\+\sStat.*Dump\s\+\+\+\s\([0-9]+\)$', re.MULTILINE)
cmd = ['/usr/sbin/rndc', 'stats']
x = subprocess.Popen(cmd)
r_code = x.wait()
if r_code != 0 :
print >> sys.stderr, 'bad things happened calling %s ' % cmd
print >> sys.stderr, 'need to throw and catch an exception'
f = '/var/named/named.stats'
collections = collections_splitter_re.split(open(f).read())
collections = map(lambda x: x.strip(), collections)
foo = {}
for collection in collections:
collection = collection.strip()
if not collection: continue
collection_date, collection_data = return_collection_data(collection)
foo[collection_date] = collection_data
k = foo.keys()
k.sort()
return (time.time(), foo[k.pop()])
def named_stats_handler(value):
global LastRecord
global MaxAge
global out_file
out_file.write('in handler name %s \n' % value)
timestamp, data = LastRecord
if time.time() - timestamp > MaxAge: timestamp, data = return_latest_record()
LastRecord = (timestamp, data)
out_file.write('Current Record %s\n' % LastRecord.__str__())
out_file.flush()
return data[value]
def metric_init(params):
global descriptors
global NamePrefix
global LastRecord
global out_file
out_file = open('/tmp/ganglia_david', 'w')
LastRecord = return_latest_record()
out_file.write('LastRecord %s\n' % LastRecord.__str__())
out_file.flush()
descriptors = [
{ 'name' : '%s_success' % NamePrefix,
'call_back': named_stats_handler,
'time_max': 60,
'value_type': 'uint32',
'units': 'ticks',
'slope': 'positive',
'format': '%u',
'description': 'Successful Queries',
'groups': NamePrefix
},
{ 'name' : '%s_nxrrset' % NamePrefix,
'call_back': named_stats_handler,
'time_max': 60,
'value_type': 'uint32',
'units': 'ticks',
'slope': 'positive',
'format': '%u',
'description': 'Dunno',
'groups': NamePrefix
},
{ 'name' : '%s_referral' % NamePrefix,
'call_back': named_stats_handler,
'time_max': 60,
'value_type': 'uint32',
'units': 'ticks',
'slope': 'positive',
'format': '%u',
'description': 'DNS Forwards',
'groups': NamePrefix
},
{ 'name' : '%s_nxdomain' % NamePrefix,
'call_back': named_stats_handler,
'time_max': 60,
'value_type': 'uint32',
'units': 'ticks',
'slope': 'positive',
'format': '%u',
'description': 'No RR in Zones',
'groups': NamePrefix
},
{ 'name' : '%s_recursion' % NamePrefix,
'call_back': named_stats_handler,
'time_max': 60,
'value_type': 'uint32',
'units': 'ticks',
'slope': 'positive',
'format': '%u',
'description': 'Recursive Queries',
'groups': NamePrefix
},
{ 'name' : '%s_failure' % NamePrefix,
'call_back': named_stats_handler,
'time_max': 60,
'value_type': 'uint32',
'units': 'ticks',
'slope': 'positive',
'format': '%u',
'description': 'SERV Fail',
'groups': NamePrefix
},
{ 'name' : '%s_duplicate' % NamePrefix,
'call_back': named_stats_handler,
'time_max': 60,
'value_type': 'uint32',
'units': 'ticks',
'slope': 'positive',
'format': '%u',
'description': 'dunno',
'groups': NamePrefix
},
{ 'name' : '%s_dropped' % NamePrefix,
'call_back': named_stats_handler,
'time_max': 60,
'value_type': 'uint32',
'units': 'ticks',
'slope': 'positive',
'format': '%u',
'description': 'Client went away',
'groups': NamePrefix
}
]
return descriptors
def metric_cleanup():
'''Clean up the metric module.'''
global out_file
out_file.close()
# pass
#This code is for debugging and unit testing
if __name__ == '__main__':
metric_init(None)
for d in descriptors:
v = d['call_back'](d['name'])
print 'value for %s is %u' % (d['name'], v)
On Thu, Dec 11, 2008 at 10:58 PM, Bernard Li <[email protected]> wrote:
> Hi Guolin:
>
> On Thu, Dec 11, 2008 at 4:46 PM, Guolin Cheng <[email protected]> wrote:
>
>> Then I setup the config mytest.pyconf and copy it to under
>> /etc/ganglia/conf.d/, and copy the python script to under
>> /usr/lib64/ganglia/python_modules/ as well. At last I fire up gmond
>> again.
>
> It might help for us to have a look at your mytest.pyconf and mytest.py.
>
> Which version of Ganglia are you using?
>
> Cheers,
>
> Bernard
>
> ------------------------------------------------------------------------------
> SF.Net email is Sponsored by MIX09, March 18-20, 2009 in Las Vegas, Nevada.
> The future of the web can't happen without you. Join us at MIX09 to help
> pave the way to the Next Web now. Learn more and register at
> http://ad.doubleclick.net/clk;208669438;13503038;i?http://2009.visitmix.com/
> _______________________________________________
> Ganglia-general mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/ganglia-general
>
------------------------------------------------------------------------------
SF.Net email is Sponsored by MIX09, March 18-20, 2009 in Las Vegas, Nevada.
The future of the web can't happen without you. Join us at MIX09 to help
pave the way to the Next Web now. Learn more and register at
http://ad.doubleclick.net/clk;208669438;13503038;i?http://2009.visitmix.com/
_______________________________________________
Ganglia-general mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ganglia-general