From 8803422e8851778b8057a238c12acb8a9d71a7cc Mon Sep 17 00:00:00 2001 From: Shu Lin Date: Mon, 24 Apr 2017 17:45:40 -0700 Subject: [PATCH] Issue #42 Add "Unit" in metric map report. --- 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 0fa8bc4..b4f35fb 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" @@ -47,6 +48,7 @@ def _build_metric_map(self, metric_list): metric_map[metric_prefix + self._TIMESTAMP_KEY] = metric.timestamp 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 @@ -67,3 +69,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 98e7cee..d66ae3e 100644 --- a/src/cloudwatch/modules/metricdata.py +++ b/src/cloudwatch/modules/metricdata.py @@ -84,7 +84,7 @@ def __init__(self, config_helper, vl): def build(self): """ Builds metric data object with name and dimensions but without value or statistics """ - return MetricDataStatistic(metric_name=self._build_metric_name(), dimensions=self._build_metric_dimensions()) + return MetricDataStatistic(metric_name=self._build_metric_name(), unit=self.vl.type_instance, dimensions=self._build_metric_dimensions()) def _build_metric_name(self): """