Skip to content

Instantly share code, notes, and snippets.

@zarnovican
Created August 3, 2016 09:31
Show Gist options
  • Save zarnovican/f2b268ffe19c5a0a69d275ac3f81a34b to your computer and use it in GitHub Desktop.
Save zarnovican/f2b268ffe19c5a0a69d275ac3f81a34b to your computer and use it in GitHub Desktop.
telegraf
from __future__ import print_function
import json
import re
import sys
def snake_case(name):
name = name.replace('/', '_')
s1 = re.sub('(.)([A-Z][a-z]+)', r'\1_\2', name)
return re.sub('([a-z0-9])([A-Z])', r'\1_\2', s1).lower()
j = json.load(sys.stdin)
for m in j['Metrics']:
print('cloudwatch_'+snake_case(m['Namespace']), end='')
d = [ snake_case(dim['Name'])+'='+dim['Value'] for dim in m['Dimensions'] ]
if len(d) > 0:
print(','+','.join(d), end='')
print(' ', end='')
print(snake_case(m['MetricName']+'_average'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment