Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Provide support for custom dimensions for each rule (metric) by suppo…
…rting a nested section called "dimensions".
  • Loading branch information
Jacob D'Onofrio committed May 4, 2018
commit b3a5c65c9baf23684ddf73784f07e19e71eabac2
15 changes: 11 additions & 4 deletions src/diamond/handler/cloudwatch.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@
name = Avg05
namespace = MachineLoad
unit = None
[[[[dimensions]]]]
environment = dev

"""

import sys
Expand Down Expand Up @@ -87,7 +90,7 @@ def __init__(self, config=None):

self.valid_config = ('region', 'collector', 'metric', 'namespace',
'name', 'unit', 'collect_by_instance',
'collect_without_dimension')
'collect_without_dimension', 'dimensions')

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

Expand All @@ -136,7 +140,8 @@ def get_default_config_help(self):
'unit': 'CloudWatch metric unit',
'collector': 'Diamond collector name',
'collect_by_instance': 'Collect metrics for instances separately',
'collect_without_dimension': 'Collect metrics without dimension'
'collect_without_dimension': 'Collect metrics without dimension',
'dimensions': 'Additional dimensions to pass (Up to 10)'
})

return config
Expand Down Expand Up @@ -212,10 +217,12 @@ def process(self, metric):
str(rule['metric']) == metricname)):

if rule['collect_by_instance'] and self.instance_id:
dimensions = rule['dimensions']
dimensions['InstanceId'] = self.instance_id
self.send_metrics_to_cloudwatch(
rule,
metric,
{'InstanceId': self.instance_id})
dimensions)

if rule['collect_without_dimension']:
self.send_metrics_to_cloudwatch(
Expand Down