Created
January 11, 2017 20:19
-
-
Save rendicott/5eda76086b40336ee516bc84c39420e3 to your computer and use it in GitHub Desktop.
Ships metrics from Redis to graphite
This file contains hidden or 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 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