Class: AWS::CloudWatch::MetricAlarmCollection
- Inherits:
-
AlarmCollection
- Object
- AlarmCollection
- AWS::CloudWatch::MetricAlarmCollection
- Includes:
- AWS::Core::Collection::Simple
- Defined in:
- lib/aws/cloud_watch/metric_alarm_collection.rb
Overview
MetricAlarmCollection
Represents all alarms for a single metric.
Getting an alarm by name
If you know the name of the alarm, you can get a reference using the #[] method.
metric.alarms['alarm-name']
Enumerating Alarms
You can enumerate all alarms for a metric using each (or any of the methods defined in AWS::Core::Collection).
metric.alarms.each do |alarm|
puts alarm.name
end
Filtering Alarms
Use one of the filtering methods to reduce the number of alarms returned.
metric.alarms.with_unit('Seconds').each {|alarm| ... }
Instance Attribute Summary collapse
- #metric ⇒ Metric readonly
Instance Method Summary collapse
- #[](alarm_name) ⇒ Alarm
-
#create(alarm_name, options = {}) ⇒ Alarm
Creates an alarm for this metric.
-
#filter(name, value) ⇒ MetricAlarmCollection
Returns a new collection that will filter results when enumerated.
-
#with_period(period) ⇒ MetricAlarmCollection
Returns a new collection that filters alarms by a period.
-
#with_statistic(statistic) ⇒ MetricAlarmCollection
Returns a new collection that filters alarms by a statistic.
-
#with_unit(unit) ⇒ MetricAlarmCollection
Returns a new collection that filters alarms by a unit.
Methods included from AWS::Core::Collection
#each, #each_batch, #enum, #first, #in_groups_of, #page
Methods inherited from AlarmCollection
#delete, #with_action_prefix, #with_name, #with_name_prefix, #with_state_value
Instance Attribute Details
#metric ⇒ Metric (readonly)
55 56 57 |
# File 'lib/aws/cloud_watch/metric_alarm_collection.rb', line 55 def metric @metric end |
Instance Method Details
#[](alarm_name) ⇒ Alarm
59 60 61 62 63 64 65 66 |
# File 'lib/aws/cloud_watch/metric_alarm_collection.rb', line 59 def [] alarm_name = {} [:namespace] = metric.namespace [:metric_name] = metric.name [:dimensions] = metric.dimensions unless metric.dimensions.empty? [:config] = config Alarm.new(alarm_name, ) end |
#create(alarm_name, options = {}) ⇒ Alarm
Creates an alarm for this metric.
72 73 74 75 76 77 |
# File 'lib/aws/cloud_watch/metric_alarm_collection.rb', line 72 def create alarm_name, = {} [:namespace] = metric.namespace [:metric_name] = metric.metric_name [:dimensions] = metric.dimensions unless metric.dimensions.empty? super(alarm_name, ) end |
#filter(name, value) ⇒ MetricAlarmCollection
Returns a new collection that will filter results when enumerated.
96 97 98 99 |
# File 'lib/aws/cloud_watch/metric_alarm_collection.rb', line 96 def filter name, value filters = @filters.merge(name.to_s.to_sym => value) MetricAlarmCollection.new(metric, :filters => filters) end |
#with_period(period) ⇒ MetricAlarmCollection
Returns a new collection that filters alarms by a period.
metric.alarms.with_period(3600).each {|alarm| ... }
107 108 109 |
# File 'lib/aws/cloud_watch/metric_alarm_collection.rb', line 107 def with_period period filter(:period, period) end |
#with_statistic(statistic) ⇒ MetricAlarmCollection
Returns a new collection that filters alarms by a statistic.
metric.alarms.with_statistic('Average').each {|alarm| ... }
117 118 119 |
# File 'lib/aws/cloud_watch/metric_alarm_collection.rb', line 117 def with_statistic statistic filter(:statistic, statistic) end |
#with_unit(unit) ⇒ MetricAlarmCollection
Returns a new collection that filters alarms by a unit.
metric.alarms.with_unit('Percent').each {|alarm| ... }
127 128 129 |
# File 'lib/aws/cloud_watch/metric_alarm_collection.rb', line 127 def with_unit unit filter(:unit, unit) end |