Skip to content

Instantly share code, notes, and snippets.

@Raboo
Last active August 29, 2015 14:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Raboo/01d4dd9bc125efd4f9c5 to your computer and use it in GitHub Desktop.
Save Raboo/01d4dd9bc125efd4f9c5 to your computer and use it in GitHub Desktop.
import pprint
import httplib
try:
import json
except ImportError:
json = None
import sys
descriptors = list()
metrics = {}
def poll_metrics():
'''Poll @metrics and return them'''
con = httplib.HTTPConnection('localhost', 80)
con.connect()
con.request('GET', '/@metrics/metrics')
resp = con.getresponse()
data = json.loads(resp.read())
for metric,value in data['meters'].items():
metrics[metric] = [value['count'], 'meters']
for metric,value in data['histograms'].items():
metrics[metric] = [value['count'], 'histograms']
return metrics
def get_value(name):
# will when this crap works implement a last check timer so it doesn't re-poll for every single metric
metrics = poll_metrics()
return metrics[name][0]
def metric_init(params):
global descriptors
data = poll_metrics()
#print data
#print '[at_metrics] Received the following parameters'
#print params
for metric, value in data.items():
descriptors.append({'name': str(metric),
'call_back': get_value,
'time_max': 90,
'value_type': 'double',
'units': '',
'slope': 'both',
'format': '%u',
'description': '%s metric' %str(metric),
'groups': 'at_metrics,%s' %value[1]})
#pprint.pprint(descriptors)
return descriptors
def metric_cleanup():
'''Clean up the metric module.'''
pass
if __name__ == '__main__':
metric_init(0)
for d in descriptors:
v = d['call_back'](d['name'])
print 'value for %s is %u' % (d['name'], v)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment