commit
3df3b5b963
@ -229,8 +229,13 @@ class CloudWatchBackend(BaseBackend):
|
|||||||
|
|
||||||
def put_metric_data(self, namespace, metric_data):
|
def put_metric_data(self, namespace, metric_data):
|
||||||
for metric_member in metric_data:
|
for metric_member in metric_data:
|
||||||
|
# Preserve "datetime" for get_metric_statistics comparisons
|
||||||
|
timestamp = metric_member.get('Timestamp')
|
||||||
|
if timestamp is not None and type(timestamp) != datetime:
|
||||||
|
timestamp = datetime.strptime(timestamp, '%Y-%m-%dT%H:%M:%S.%fZ')
|
||||||
|
timestamp = timestamp.replace(tzinfo=tzutc())
|
||||||
self.metric_data.append(MetricDatum(
|
self.metric_data.append(MetricDatum(
|
||||||
namespace, metric_member['MetricName'], float(metric_member['Value']), metric_member.get('Dimensions.member', _EMPTY_LIST), metric_member.get('Timestamp')))
|
namespace, metric_member['MetricName'], float(metric_member['Value']), metric_member.get('Dimensions.member', _EMPTY_LIST), timestamp))
|
||||||
|
|
||||||
def get_metric_statistics(self, namespace, metric_name, start_time, end_time, period, stats):
|
def get_metric_statistics(self, namespace, metric_name, start_time, end_time, period, stats):
|
||||||
period_delta = timedelta(seconds=period)
|
period_delta = timedelta(seconds=period)
|
||||||
|
@ -272,7 +272,7 @@ GET_METRIC_STATISTICS_TEMPLATE = """<GetMetricStatisticsResponse xmlns="http://m
|
|||||||
</ResponseMetadata>
|
</ResponseMetadata>
|
||||||
|
|
||||||
<GetMetricStatisticsResult>
|
<GetMetricStatisticsResult>
|
||||||
<Label> {{ label }} </Label>
|
<Label>{{ label }}</Label>
|
||||||
<Datapoints>
|
<Datapoints>
|
||||||
{% for datapoint in datapoints %}
|
{% for datapoint in datapoints %}
|
||||||
<Datapoint>
|
<Datapoint>
|
||||||
|
@ -173,6 +173,7 @@ def test_get_metric_statistics():
|
|||||||
dict(
|
dict(
|
||||||
MetricName='metric',
|
MetricName='metric',
|
||||||
Value=1.5,
|
Value=1.5,
|
||||||
|
Timestamp=utc_now
|
||||||
)
|
)
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
@ -180,7 +181,7 @@ def test_get_metric_statistics():
|
|||||||
stats = conn.get_metric_statistics(
|
stats = conn.get_metric_statistics(
|
||||||
Namespace='tester',
|
Namespace='tester',
|
||||||
MetricName='metric',
|
MetricName='metric',
|
||||||
StartTime=utc_now,
|
StartTime=utc_now - timedelta(seconds=60),
|
||||||
EndTime=utc_now + timedelta(seconds=60),
|
EndTime=utc_now + timedelta(seconds=60),
|
||||||
Period=60,
|
Period=60,
|
||||||
Statistics=['SampleCount', 'Sum']
|
Statistics=['SampleCount', 'Sum']
|
||||||
|
Loading…
Reference in New Issue
Block a user