From 88222b094ef339e5556aa9cb7f4d3cc4c955e588 Mon Sep 17 00:00:00 2001 From: Berend de Boer Date: Fri, 10 Apr 2020 14:31:24 +1200 Subject: [PATCH] Add "Unit" in metric map report (as per pull request #44) --- src/cloudwatch/modules/client/querystringbuilder.py | 5 +++++ src/cloudwatch/modules/metricdata.py | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/cloudwatch/modules/client/querystringbuilder.py b/src/cloudwatch/modules/client/querystringbuilder.py index 13d9472..0a25f31 100644 --- a/src/cloudwatch/modules/client/querystringbuilder.py +++ b/src/cloudwatch/modules/client/querystringbuilder.py @@ -15,6 +15,7 @@ class QuerystringBuilder(object): _METRIC_NAME_KEY = "MetricName" _NAME_KEY = "Name" _VALUE_KEY = "Value" + _UNIT_KEY = "Unit" _TIMESTAMP_KEY = "Timestamp" _STATISTICS_KEY = "StatisticValues." _STAT_MAX = _STATISTICS_KEY + "Maximum" @@ -60,6 +61,7 @@ def _build_metric_map(self, metric_list): metric_map[metric_prefix + self._STORAGE_RESOLUTION] = "1" self._add_dimensions(metric, metric_map, metric_prefix) self._add_values(metric, metric_map, metric_prefix) + self._add_unit(metric, metric_map, metric_prefix) metric_index += 1 return metric_map @@ -80,3 +82,6 @@ def _add_values(self, metric, metric_map, metric_prefix): metric_map[metric_prefix + self._STAT_MIN] = metric.statistics.min metric_map[metric_prefix + self._STAT_SUM] = metric.statistics.sum metric_map[metric_prefix + self._STAT_SAMPLE] = metric.statistics.sample_count + + def _add_unit(self, metric, metric_map, metric_prefix): + metric_map[metric_prefix + self._UNIT_KEY] = metric.unit diff --git a/src/cloudwatch/modules/metricdata.py b/src/cloudwatch/modules/metricdata.py index 1669e66..cc4880e 100644 --- a/src/cloudwatch/modules/metricdata.py +++ b/src/cloudwatch/modules/metricdata.py @@ -86,7 +86,7 @@ def __init__(self, config_helper, vl, adjusted_time=None): def build(self): """ Builds metric data object with name and dimensions but without value or statistics """ - metric_array = [MetricDataStatistic(metric_name=self._build_metric_name(), dimensions=self._build_metric_dimensions(), timestamp=self._build_timestamp())] + metric_array = [MetricDataStatistic(metric_name=self._build_metric_name(), unit=self.vl.type_instance, dimensions=self._build_metric_dimensions(), timestamp=self._build_timestamp())] if self.config.push_asg: metric_array.append(MetricDataStatistic(metric_name=self._build_metric_name(), dimensions=self._build_asg_dimension(), timestamp=self._build_timestamp())) if self.config.push_constant: