Created
October 4, 2011 14:31
-
-
Save MrPink/1261778 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): | |
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) |
global? zomg. https://gist.github.com/1261846
?
…On Tue, Oct 4, 2011 at 3:57 PM, Tom Stuart < ***@***.***>wrote:
global? zomg. https://gist.github.com/1261846
##
Reply to this email directly or view it on GitHub:
https://gist.github.com/1261778
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
it has a description