| Index: boto/ec2/cloudwatch/metric.py
|
| diff --git a/boto/ec2/cloudwatch/metric.py b/boto/ec2/cloudwatch/metric.py
|
| index cd8c4bc92598701f122ab305da6b4a29377437ce..cda02d876ff945af907db8dd0f32f1ef338191b7 100644
|
| --- a/boto/ec2/cloudwatch/metric.py
|
| +++ b/boto/ec2/cloudwatch/metric.py
|
| @@ -20,7 +20,9 @@
|
| # IN THE SOFTWARE.
|
| #
|
|
|
| -class Dimensions(dict):
|
| +from boto.ec2.cloudwatch.alarm import MetricAlarm
|
| +
|
| +class Dimension(dict):
|
|
|
| def startElement(self, name, attrs, connection):
|
| pass
|
| @@ -29,15 +31,23 @@ class Dimensions(dict):
|
| if name == 'Name':
|
| self._name = value
|
| elif name == 'Value':
|
| - self[self._name] = value
|
| - elif name != 'Dimensions' and name != 'member':
|
| - self[name] = value
|
| + if self._name in self:
|
| + self[self._name].append(value)
|
| + else:
|
| + self[self._name] = [value]
|
| + else:
|
| + setattr(self, name, value)
|
|
|
| class Metric(object):
|
|
|
| Statistics = ['Minimum', 'Maximum', 'Sum', 'Average', 'SampleCount']
|
| - Units = ['Seconds', 'Percent', 'Bytes', 'Bits', 'Count',
|
| - 'Bytes/Second', 'Bits/Second', 'Count/Second']
|
| + Units = ['Seconds', 'Microseconds', 'Milliseconds', 'Bytes', 'Kilobytes',
|
| + 'Megabytes', 'Gigabytes', 'Terabytes', 'Bits', 'Kilobits',
|
| + 'Megabits', 'Gigabits', 'Terabits', 'Percent', 'Count',
|
| + 'Bytes/Second', 'Kilobytes/Second', 'Megabytes/Second',
|
| + 'Gigabytes/Second', 'Terabytes/Second', 'Bits/Second',
|
| + 'Kilobits/Second', 'Megabits/Second', 'Gigabits/Second',
|
| + 'Terabits/Second', 'Count/Second', None]
|
|
|
| def __init__(self, connection=None):
|
| self.connection = connection
|
| @@ -46,15 +56,11 @@ class Metric(object):
|
| self.dimensions = None
|
|
|
| def __repr__(self):
|
| - s = 'Metric:%s' % self.name
|
| - if self.dimensions:
|
| - for name,value in self.dimensions.items():
|
| - s += '(%s,%s)' % (name, value)
|
| - return s
|
| + return 'Metric:%s' % self.name
|
|
|
| def startElement(self, name, attrs, connection):
|
| if name == 'Dimensions':
|
| - self.dimensions = Dimensions()
|
| + self.dimensions = Dimension()
|
| return self.dimensions
|
|
|
| def endElement(self, name, value, connection):
|
| @@ -65,12 +71,36 @@ class Metric(object):
|
| else:
|
| setattr(self, name, value)
|
|
|
| - def query(self, start_time, end_time, statistic, unit=None, period=60):
|
| - return self.connection.get_metric_statistics(period, start_time, end_time,
|
| - self.name, self.namespace, [statistic],
|
| - self.dimensions, unit)
|
| + def query(self, start_time, end_time, statistics, unit=None, period=60):
|
| + if not isinstance(statistics, list):
|
| + statistics = [statistics]
|
| + return self.connection.get_metric_statistics(period,
|
| + start_time,
|
| + end_time,
|
| + self.name,
|
| + self.namespace,
|
| + statistics,
|
| + self.dimensions,
|
| + unit)
|
|
|
| - def describe_alarms(self, period=None, statistic=None, dimensions=None, unit=None):
|
| + def create_alarm(self, name, comparison, threshold,
|
| + period, evaluation_periods,
|
| + statistic, enabled=True, description=None,
|
| + dimensions=None, alarm_actions=None, ok_actions=None,
|
| + insufficient_data_actions=None, unit=None):
|
| + if not dimensions:
|
| + dimensions = self.dimensions
|
| + alarm = MetricAlarm(self.connection, name, self.name,
|
| + self.namespace, statistic, comparison,
|
| + threshold, period, evaluation_periods,
|
| + unit, description, dimensions,
|
| + alarm_actions, insufficient_data_actions,
|
| + ok_actions)
|
| + if self.connection.put_metric_alarm(alarm):
|
| + return alarm
|
| +
|
| + def describe_alarms(self, period=None, statistic=None,
|
| + dimensions=None, unit=None):
|
| return self.connection.describe_alarms_for_metric(self.name,
|
| self.namespace,
|
| period,
|
| @@ -78,3 +108,5 @@ class Metric(object):
|
| dimensions,
|
| unit)
|
|
|
| +
|
| +
|
|
|