Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Ships metrics from Redis to graphite
import graphitesend
import redis
import os
import time
import sys
pattern = '%Y-%m-%d %H:%M:%S'
g = graphitesend.init(prefix='devops.dotshipper',graphite_server='dograph2.docl.nic')
r = redis.StrictRedis(host='dotshipper2.docl.nic', port=6379, db=0)
counter = r.get('counter')
try:
keystring = sys.argv[1]
klist = keystring.split('-')
int(klist[1])
except:
keystring = 'run-%07d' % int(counter)
print("Got current keystring of " + str(keystring))
epochdate_from = None
epochdate_to = None
resultscount_counts = None
resultscount_rows = None
total_runtime = None
timedelta_seconds = None
keys = r.hgetall(keystring)
for key in keys:
if key == 'from':
epochdate_from = int(time.mktime(time.strptime(r.hget(keystring,key),pattern)))
if key == 'to':
epochdate_to = int(time.mktime(time.strptime(r.hget(keystring,key),pattern)))
if key == 'resultscount_counts':
resultscount_counts = r.hget(keystring,key)
if key == 'resultscount_rows':
resultscount_rows = r.hget(keystring,key)
if key == 'total_runtime':
total_runtime = r.hget(keystring,key)
if key == 'timedelta_seconds':
timedelta_seconds = r.hget(keystring,key)
# first push from/to with counts count
g.send('total_offerserved_counts',resultscount_counts,timestamp=epochdate_from)
g.send('total_offerserved_counts',resultscount_counts,timestamp=epochdate_to)
g.send('resultscount_rows', resultscount_rows, timestamp=epochdate_to)
g.send('resultscount_counts', resultscount_counts, timestamp=epochdate_to)
g.send('total_runtime', total_runtime, timestamp=epochdate_to)
g.send('timedelta_seconds', timedelta_seconds, timestamp=epochdate_to)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.