Skip to content

Commit

Permalink
cloudwatch - additional dimensions should be a separate metric send
Browse files Browse the repository at this point in the history
  • Loading branch information
jantman committed Oct 1, 2017
1 parent 5ac5c43 commit 19d136f
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions src/diamond/handler/cloudwatch.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
name = Uptime
namespace = Diamond
unit = None
[[[[additional_dimensions]]]]
[[[[collect_with_dimensions]]]]
Hostname = foo
"""
Expand Down Expand Up @@ -102,7 +102,7 @@ def __init__(self, config=None):
self.valid_config = ('region', 'collector', 'metric', 'namespace',
'name', 'unit', 'collect_by_instance',
'collect_without_dimension',
'additional_dimensions')
'collect_with_dimensions')

self.rules = []
for key_name, section in self.config.items():
Expand Down Expand Up @@ -134,7 +134,7 @@ def get_default_rule_config(self):
'unit': 'None',
'collect_by_instance': True,
'collect_without_dimension': False,
'additional_dimensions': {}
'collect_with_dimensions': {}
})
return config

Expand All @@ -153,8 +153,8 @@ def get_default_config_help(self):
'collector': 'Diamond collector name',
'collect_by_instance': 'Send metric with InstanceId dimension',
'collect_without_dimension': 'Send metric with no dimension',
'additional_dimensions': 'Name/Value additional dimensions to '
'send with metric'
'collect_with_dimensions': 'Name/Value additional dimensions to '
'send metric with'
})

return config
Expand All @@ -174,7 +174,7 @@ def get_default_config(self):
'unit': 'None',
'collect_by_instance': True,
'collect_without_dimension': False,
'additional_dimensions': {}
'collect_with_dimensions': {}
})

return config
Expand Down Expand Up @@ -242,15 +242,19 @@ def process(self, metric):
metric,
{})

if len(rule['collect_with_dimensions']) > 0:
self.send_metrics_to_cloudwatch(
rule,
metric,
rule['collect_with_dimensions'])

def send_metrics_to_cloudwatch(self, rule, metric, dimensions):
"""
Send metrics to CloudWatch for the given dimensions
"""

timestamp = datetime.datetime.utcfromtimestamp(metric.timestamp)

dimensions.update(rule['additional_dimensions'])

self.log.debug(
"CloudWatch: Attempting to publish metric: %s to %s "
"with value (%s) for dimensions %s @%s",
Expand Down

0 comments on commit 19d136f

Please sign in to comment.