I really thought this was going to solve it.
I
- created user:group gmond:gmond.
- granted gmond sudo NOPASSWD on /usr/sbin/rndc
- edited the Popen to prepend a 'sudo' to the '/usr/sbin/rndc' call
To test, I su - gmond and ran the script as a unit test successfully.
Just to prove that these were valid steps, I removed the 'sudo' prefix
to the Popen call which caused the script to crash -readded, and was
able to run as a test as gmond once again.
Just to reiterate too, the metric_init is definitely being callled.
I've even combed through the strace a few times
After doing lots of python things like reads and mmaps on python
modules and builtins, it parses named.stats via a read call....then a
few brk's(can't remember what this syscall is) and then it's off doing
it's own built-in metrics seemingly never to return to my python
things.
brk(0x9a08000) = 0x9a08000
read(5, "+++ Statistics Dump +++ (1228912"..., 139264) = 139264
read(5, "4)\n+++ Statistics Dump +++ (1229"..., 4096) = 1089
read(5, "", 4096) = 0
close(5) = 0
munmap(0xb7ce3000, 4096) = 0
brk(0x9a29000) = 0x9a29000
brk(0x9a4a000) = 0x9a4a000
brk(0x9a6b000) = 0x9a6b000
gettimeofday({1229082545, 192223}, NULL) = 0
fstat64(4, {st_mode=S_IFREG|0644, st_size=0, ...}) = 0
mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1,
0) = 0xb7ce3000
write(4, "LastRecord (1229082545.1922231, "..., 213) = 213
getdents(3, /* 0 entries */, 4096) = 0
close(3) = 0
gettimeofday({1229082545, 195632}, NULL) = 0
open("/proc/stat", O_RDONLY)
On Fri, Dec 12, 2008 at 6:07 AM, Brad Nicholes <[email protected]> wrote:
> I haven't tried to actually run your module yet, but can this be a
> permissions problem. What user are you running gmond as? Does that user
> have permissions to run rndc and access named.stats? All modules run by
> gmond will be run as the same user as gmond. Therefore you have to make sure
> that the user that gmond is running as, has sufficient permissions to perform
> any work being done by the modules.
>
> Brad
>
>
>>>> On 12/12/2008 at 4:24 AM, in message
> <[email protected]>, "David
> Birdsong"
> <[email protected]> wrote:
>> 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
>
>
>
------------------------------------------------------------------------------
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