Skip to content

Instantly share code, notes, and snippets.

@MrPink
Created October 4, 2011 14:31
Show Gist options
  • Save MrPink/1261778 to your computer and use it in GitHub Desktop.
Save MrPink/1261778 to your computer and use it in GitHub Desktop.
Ganglia Python module to graph results from a SQL query
import sys
import _mysql
import time
import re
def blank_logger(name):
db=_mysql.connect(user="user",passwd="password",db="hitstats")
db.query(""" SELECT sum(if(filename='nginx_timeout',totalhits,0)) blanks
FROM `hitstats`.`serverhits` """)
r = db.use_result()
results = r.fetch_row()
sort_results = [results]
restr = str(sort_results)
res = re.sub("[^^0-9]", "", restr)
return res
def metric_init(params):
global descriptors
d1 = {'name': 'blanks',
'call_back': blank_logger,
'time_max': 900,
'value_type': 'uint',
'units': 'blanks',
'slope': 'both',
'format': '1',
'description': 'Amount of blanks served',
'groups': 'health'}
descriptors = [d1]
return descriptors
def metric_cleanup():
'''Clean up the metric module.'''
pass
#This code is for debugging and unit testing
if __name__ == '__main__':
metric_init({})
for d in descriptors:
v = d['call_back'](d['name'])
print 'value for %s is %s' % (d['name'], v)
@rentalcustard
Copy link

@MrPink
Copy link
Author

MrPink commented Oct 4, 2011 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment