-
-
Save rentalcustard/1261846 to your computer and use it in GitHub Desktop.
Ganglia Python module to graph results from a SQL query
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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): | |
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'} | |
return [d1] | |
def metric_cleanup(): | |
'''Clean up the metric module.''' | |
pass | |
#This code is for debugging and unit testing | |
if __name__ == '__main__': | |
descriptors = metric_init({}) | |
for d in descriptors: | |
v = d['call_back'](d['name']) | |
print 'value for %s is %s' % (d['name'], v) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment