Class: Aws::CloudWatch::Alarm
- Inherits:
-
Object
- Object
- Aws::CloudWatch::Alarm
- Defined in:
- gems/aws-sdk-cloudwatch/lib/aws-sdk-cloudwatch/alarm.rb
Defined Under Namespace
Classes: Collection
Read-Only Attributes collapse
-
#actions_enabled ⇒ Boolean
Indicates whether actions should be executed during any changes to the alarm state.
-
#alarm_actions ⇒ Array<String>
The actions to execute when this alarm transitions to the
ALARM
state from any other state. -
#alarm_arn ⇒ String
The Amazon Resource Name (ARN) of the alarm.
-
#alarm_configuration_updated_timestamp ⇒ Time
The time stamp of the last update to the alarm configuration.
-
#alarm_description ⇒ String
The description of the alarm.
-
#comparison_operator ⇒ String
The arithmetic operation to use when comparing the specified statistic and threshold.
-
#datapoints_to_alarm ⇒ Integer
The number of data points that must be breaching to trigger the alarm.
-
#dimensions ⇒ Array<Types::Dimension>
The dimensions for the metric associated with the alarm.
-
#evaluate_low_sample_count_percentile ⇒ String
Used only for alarms based on percentiles.
-
#evaluation_periods ⇒ Integer
The number of periods over which data is compared to the specified threshold.
-
#evaluation_state ⇒ String
If the value of this field is
PARTIAL_DATA
, the alarm is being evaluated based on only partial data. -
#extended_statistic ⇒ String
The percentile statistic for the metric associated with the alarm.
-
#insufficient_data_actions ⇒ Array<String>
The actions to execute when this alarm transitions to the
INSUFFICIENT_DATA
state from any other state. -
#metric_name ⇒ String
The name of the metric associated with the alarm, if this is an alarm based on a single metric.
-
#metrics ⇒ Array<Types::MetricDataQuery>
An array of MetricDataQuery structures, used in an alarm based on a metric math expression.
-
#name ⇒ String
(also: #alarm_name)
-
#namespace ⇒ String
The namespace of the metric associated with the alarm.
-
#ok_actions ⇒ Array<String>
The actions to execute when this alarm transitions to the
OK
state from any other state. -
#period ⇒ Integer
The period, in seconds, over which the statistic is applied.
-
#state_reason ⇒ String
An explanation for the alarm state, in text format.
-
#state_reason_data ⇒ String
An explanation for the alarm state, in JSON format.
-
#state_transitioned_timestamp ⇒ Time
The date and time that the alarm's
StateValue
most recently changed. -
#state_updated_timestamp ⇒ Time
The time stamp of the last update to the value of either the
StateValue
orEvaluationState
parameters. -
#state_value ⇒ String
The state value for the alarm.
-
#statistic ⇒ String
The statistic for the metric associated with the alarm, other than percentile.
-
#threshold ⇒ Float
The value to compare with the specified statistic.
-
#threshold_metric_id ⇒ String
In an alarm based on an anomaly detection model, this is the ID of the
ANOMALY_DETECTION_BAND
function used as the threshold for the alarm. -
#treat_missing_data ⇒ String
Sets how this alarm is to handle missing data points.
-
#unit ⇒ String
The unit of the metric associated with the alarm.
Actions collapse
-
#delete(options = {}) ⇒ EmptyStructure
-
#describe_history(options = {}) ⇒ Types::DescribeAlarmHistoryOutput
-
#disable_actions(options = {}) ⇒ EmptyStructure
-
#enable_actions(options = {}) ⇒ EmptyStructure
-
#set_state(options = {}) ⇒ EmptyStructure
Associations collapse
Instance Method Summary collapse
-
#client ⇒ Client
-
#data ⇒ Types::MetricAlarm
Returns the data for this Alarm.
-
#data_loaded? ⇒ Boolean
Returns
true
if this resource is loaded. -
#exists?(options = {}) ⇒ Boolean
Returns
true
if the Alarm exists. -
#initialize(*args) ⇒ Alarm
constructor
A new instance of Alarm.
- #load ⇒ self (also: #reload)
-
#wait_until(options = {}) {|resource| ... } ⇒ Resource
deprecated
Deprecated.
Use [Aws::CloudWatch::Client] #wait_until instead
-
#wait_until_exists(options = {}, &block) ⇒ Alarm
Constructor Details
#initialize(name, options = {}) ⇒ Alarm #initialize(options = {}) ⇒ Alarm
Returns a new instance of Alarm.
22 23 24 25 26 27 28 |
# File 'gems/aws-sdk-cloudwatch/lib/aws-sdk-cloudwatch/alarm.rb', line 22 def initialize(*args) = Hash === args.last ? args.pop.dup : {} @name = extract_name(args, ) @data = .delete(:data) @client = .delete(:client) || Client.new() @waiter_block_warned = false end |
Instance Method Details
#actions_enabled ⇒ Boolean
Indicates whether actions should be executed during any changes to the alarm state.
59 60 61 |
# File 'gems/aws-sdk-cloudwatch/lib/aws-sdk-cloudwatch/alarm.rb', line 59 def actions_enabled data[:actions_enabled] end |
#alarm_actions ⇒ Array<String>
The actions to execute when this alarm transitions to the ALARM
state from any other state. Each action is specified as an Amazon
Resource Name (ARN).
75 76 77 |
# File 'gems/aws-sdk-cloudwatch/lib/aws-sdk-cloudwatch/alarm.rb', line 75 def alarm_actions data[:alarm_actions] end |
#alarm_arn ⇒ String
The Amazon Resource Name (ARN) of the alarm.
40 41 42 |
# File 'gems/aws-sdk-cloudwatch/lib/aws-sdk-cloudwatch/alarm.rb', line 40 def alarm_arn data[:alarm_arn] end |
#alarm_configuration_updated_timestamp ⇒ Time
The time stamp of the last update to the alarm configuration.
52 53 54 |
# File 'gems/aws-sdk-cloudwatch/lib/aws-sdk-cloudwatch/alarm.rb', line 52 def data[:alarm_configuration_updated_timestamp] end |
#alarm_description ⇒ String
The description of the alarm.
46 47 48 |
# File 'gems/aws-sdk-cloudwatch/lib/aws-sdk-cloudwatch/alarm.rb', line 46 def alarm_description data[:alarm_description] end |
#client ⇒ Client
250 251 252 |
# File 'gems/aws-sdk-cloudwatch/lib/aws-sdk-cloudwatch/alarm.rb', line 250 def client @client end |
#comparison_operator ⇒ String
The arithmetic operation to use when comparing the specified statistic and threshold. The specified statistic value is used as the first operand.
180 181 182 |
# File 'gems/aws-sdk-cloudwatch/lib/aws-sdk-cloudwatch/alarm.rb', line 180 def comparison_operator data[:comparison_operator] end |
#data ⇒ Types::MetricAlarm
Returns the data for this Aws::CloudWatch::Alarm. Calls
Client#describe_alarms if #data_loaded? is false
.
272 273 274 275 |
# File 'gems/aws-sdk-cloudwatch/lib/aws-sdk-cloudwatch/alarm.rb', line 272 def data load unless @data @data end |
#data_loaded? ⇒ Boolean
280 281 282 |
# File 'gems/aws-sdk-cloudwatch/lib/aws-sdk-cloudwatch/alarm.rb', line 280 def data_loaded? !!@data end |
#datapoints_to_alarm ⇒ Integer
The number of data points that must be breaching to trigger the alarm.
166 167 168 |
# File 'gems/aws-sdk-cloudwatch/lib/aws-sdk-cloudwatch/alarm.rb', line 166 def datapoints_to_alarm data[:datapoints_to_alarm] end |
#delete(options = {}) ⇒ EmptyStructure
423 424 425 426 427 428 429 |
# File 'gems/aws-sdk-cloudwatch/lib/aws-sdk-cloudwatch/alarm.rb', line 423 def delete( = {}) = Aws::Util.deep_merge(, alarm_names: [@name]) resp = Aws::Plugins::UserAgent.metric('RESOURCE_MODEL') do @client.delete_alarms() end resp.data end |
#describe_history(options = {}) ⇒ Types::DescribeAlarmHistoryOutput
464 465 466 467 468 469 470 |
# File 'gems/aws-sdk-cloudwatch/lib/aws-sdk-cloudwatch/alarm.rb', line 464 def describe_history( = {}) = .merge(alarm_name: @name) resp = Aws::Plugins::UserAgent.metric('RESOURCE_MODEL') do @client.describe_alarm_history() end resp.data end |
#dimensions ⇒ Array<Types::Dimension>
The dimensions for the metric associated with the alarm.
141 142 143 |
# File 'gems/aws-sdk-cloudwatch/lib/aws-sdk-cloudwatch/alarm.rb', line 141 def dimensions data[:dimensions] end |
#disable_actions(options = {}) ⇒ EmptyStructure
477 478 479 480 481 482 483 |
# File 'gems/aws-sdk-cloudwatch/lib/aws-sdk-cloudwatch/alarm.rb', line 477 def disable_actions( = {}) = Aws::Util.deep_merge(, alarm_names: [@name]) resp = Aws::Plugins::UserAgent.metric('RESOURCE_MODEL') do @client.disable_alarm_actions() end resp.data end |
#enable_actions(options = {}) ⇒ EmptyStructure
490 491 492 493 494 495 496 |
# File 'gems/aws-sdk-cloudwatch/lib/aws-sdk-cloudwatch/alarm.rb', line 490 def enable_actions( = {}) = Aws::Util.deep_merge(, alarm_names: [@name]) resp = Aws::Plugins::UserAgent.metric('RESOURCE_MODEL') do @client.enable_alarm_actions() end resp.data end |
#evaluate_low_sample_count_percentile ⇒ String
Used only for alarms based on percentiles. If ignore
, the alarm
state does not change during periods with too few data points to be
statistically significant. If evaluate
or this parameter is not
used, the alarm is always evaluated and possibly changes state no
matter how many data points are available.
206 207 208 |
# File 'gems/aws-sdk-cloudwatch/lib/aws-sdk-cloudwatch/alarm.rb', line 206 def evaluate_low_sample_count_percentile data[:evaluate_low_sample_count_percentile] end |
#evaluation_periods ⇒ Integer
The number of periods over which data is compared to the specified threshold.
160 161 162 |
# File 'gems/aws-sdk-cloudwatch/lib/aws-sdk-cloudwatch/alarm.rb', line 160 def evaluation_periods data[:evaluation_periods] end |
#evaluation_state ⇒ String
If the value of this field is PARTIAL_DATA
, the alarm is being
evaluated based on only partial data. This happens if the query used
for the alarm returns more than 10,000 metrics. For more information,
see Create alarms on Metrics Insights queries.
236 237 238 |
# File 'gems/aws-sdk-cloudwatch/lib/aws-sdk-cloudwatch/alarm.rb', line 236 def evaluation_state data[:evaluation_state] end |
#exists?(options = {}) ⇒ Boolean
Returns true
if the Alarm exists.
287 288 289 290 291 292 293 294 295 296 |
# File 'gems/aws-sdk-cloudwatch/lib/aws-sdk-cloudwatch/alarm.rb', line 287 def exists?( = {}) begin wait_until_exists(.merge(max_attempts: 1)) true rescue Aws::Waiters::Errors::UnexpectedError => e raise e.error rescue Aws::Waiters::Errors::WaiterFailed false end end |
#extended_statistic ⇒ String
The percentile statistic for the metric associated with the alarm. Specify a value between p0.0 and p100.
135 136 137 |
# File 'gems/aws-sdk-cloudwatch/lib/aws-sdk-cloudwatch/alarm.rb', line 135 def extended_statistic data[:extended_statistic] end |
#insufficient_data_actions ⇒ Array<String>
The actions to execute when this alarm transitions to the
INSUFFICIENT_DATA
state from any other state. Each action is
specified as an Amazon Resource Name (ARN).
83 84 85 |
# File 'gems/aws-sdk-cloudwatch/lib/aws-sdk-cloudwatch/alarm.rb', line 83 def insufficient_data_actions data[:insufficient_data_actions] end |
#load ⇒ self Also known as: reload
Loads, or reloads #data for the current Aws::CloudWatch::Alarm.
Returns self
making it possible to chain methods.
alarm.reload.data
260 261 262 263 264 265 266 |
# File 'gems/aws-sdk-cloudwatch/lib/aws-sdk-cloudwatch/alarm.rb', line 260 def load resp = Aws::Plugins::UserAgent.metric('RESOURCE_MODEL') do @client.describe_alarms(alarm_names: [@name]) end @data = resp.metric_alarms[0] self end |
#metric ⇒ Metric?
531 532 533 534 535 536 537 538 539 540 541 |
# File 'gems/aws-sdk-cloudwatch/lib/aws-sdk-cloudwatch/alarm.rb', line 531 def metric if data[:namespace] && data[:metric_name] Metric.new( namespace: data[:namespace], name: data[:metric_name], client: @client ) else nil end end |
#metric_name ⇒ String
The name of the metric associated with the alarm, if this is an alarm based on a single metric.
115 116 117 |
# File 'gems/aws-sdk-cloudwatch/lib/aws-sdk-cloudwatch/alarm.rb', line 115 def metric_name data[:metric_name] end |
#metrics ⇒ Array<Types::MetricDataQuery>
An array of MetricDataQuery structures, used in an alarm based on a
metric math expression. Each structure either retrieves a metric or
performs a math expression. One item in the Metrics array is the math
expression that the alarm watches. This expression by designated by
having ReturnData
set to true.
216 217 218 |
# File 'gems/aws-sdk-cloudwatch/lib/aws-sdk-cloudwatch/alarm.rb', line 216 def metrics data[:metrics] end |
#name ⇒ String Also known as: alarm_name
33 34 35 |
# File 'gems/aws-sdk-cloudwatch/lib/aws-sdk-cloudwatch/alarm.rb', line 33 def name @name end |
#namespace ⇒ String
The namespace of the metric associated with the alarm.
121 122 123 |
# File 'gems/aws-sdk-cloudwatch/lib/aws-sdk-cloudwatch/alarm.rb', line 121 def namespace data[:namespace] end |
#ok_actions ⇒ Array<String>
The actions to execute when this alarm transitions to the OK
state
from any other state. Each action is specified as an Amazon Resource
Name (ARN).
67 68 69 |
# File 'gems/aws-sdk-cloudwatch/lib/aws-sdk-cloudwatch/alarm.rb', line 67 def ok_actions data[:ok_actions] end |
#period ⇒ Integer
The period, in seconds, over which the statistic is applied.
147 148 149 |
# File 'gems/aws-sdk-cloudwatch/lib/aws-sdk-cloudwatch/alarm.rb', line 147 def period data[:period] end |
#set_state(options = {}) ⇒ EmptyStructure
520 521 522 523 524 525 526 |
# File 'gems/aws-sdk-cloudwatch/lib/aws-sdk-cloudwatch/alarm.rb', line 520 def set_state( = {}) = .merge(alarm_name: @name) resp = Aws::Plugins::UserAgent.metric('RESOURCE_MODEL') do @client.set_alarm_state() end resp.data end |
#state_reason ⇒ String
An explanation for the alarm state, in text format.
95 96 97 |
# File 'gems/aws-sdk-cloudwatch/lib/aws-sdk-cloudwatch/alarm.rb', line 95 def state_reason data[:state_reason] end |
#state_reason_data ⇒ String
An explanation for the alarm state, in JSON format.
101 102 103 |
# File 'gems/aws-sdk-cloudwatch/lib/aws-sdk-cloudwatch/alarm.rb', line 101 def state_reason_data data[:state_reason_data] end |
#state_transitioned_timestamp ⇒ Time
The date and time that the alarm's StateValue
most recently
changed.
243 244 245 |
# File 'gems/aws-sdk-cloudwatch/lib/aws-sdk-cloudwatch/alarm.rb', line 243 def data[:state_transitioned_timestamp] end |
#state_updated_timestamp ⇒ Time
The time stamp of the last update to the value of either the
StateValue
or EvaluationState
parameters.
108 109 110 |
# File 'gems/aws-sdk-cloudwatch/lib/aws-sdk-cloudwatch/alarm.rb', line 108 def data[:state_updated_timestamp] end |
#state_value ⇒ String
The state value for the alarm.
89 90 91 |
# File 'gems/aws-sdk-cloudwatch/lib/aws-sdk-cloudwatch/alarm.rb', line 89 def state_value data[:state_value] end |
#statistic ⇒ String
The statistic for the metric associated with the alarm, other than
percentile. For percentile statistics, use ExtendedStatistic
.
128 129 130 |
# File 'gems/aws-sdk-cloudwatch/lib/aws-sdk-cloudwatch/alarm.rb', line 128 def statistic data[:statistic] end |
#threshold ⇒ Float
The value to compare with the specified statistic.
172 173 174 |
# File 'gems/aws-sdk-cloudwatch/lib/aws-sdk-cloudwatch/alarm.rb', line 172 def threshold data[:threshold] end |
#threshold_metric_id ⇒ String
In an alarm based on an anomaly detection model, this is the ID of the
ANOMALY_DETECTION_BAND
function used as the threshold for the alarm.
223 224 225 |
# File 'gems/aws-sdk-cloudwatch/lib/aws-sdk-cloudwatch/alarm.rb', line 223 def threshold_metric_id data[:threshold_metric_id] end |
#treat_missing_data ⇒ String
Sets how this alarm is to handle missing data points. The valid values
are breaching
, notBreaching
, ignore
, and missing
. For more
information, see Configuring how CloudWatch alarms treat missing
data.
If this parameter is omitted, the default behavior of missing
is
used.
196 197 198 |
# File 'gems/aws-sdk-cloudwatch/lib/aws-sdk-cloudwatch/alarm.rb', line 196 def treat_missing_data data[:treat_missing_data] end |
#unit ⇒ String
The unit of the metric associated with the alarm.
153 154 155 |
# File 'gems/aws-sdk-cloudwatch/lib/aws-sdk-cloudwatch/alarm.rb', line 153 def unit data[:unit] end |
#wait_until(options = {}) {|resource| ... } ⇒ Resource
Use [Aws::CloudWatch::Client] #wait_until instead
The waiting operation is performed on a copy. The original resource remains unchanged.
Waiter polls an API operation until a resource enters a desired state.
Basic Usage
Waiter will polls until it is successful, it fails by entering a terminal state, or until a maximum number of attempts are made.
# polls in a loop until condition is true
resource.wait_until() {|resource| condition}
Example
instance.wait_until(max_attempts:10, delay:5) do |instance|
instance.state.name == 'running'
end
Configuration
You can configure the maximum number of polling attempts, and the delay (in seconds) between each polling attempt. The waiting condition is set by passing a block to #wait_until:
# poll for ~25 seconds
resource.wait_until(max_attempts:5,delay:5) {|resource|...}
Callbacks
You can be notified before each polling attempt and before each
delay. If you throw :success
or :failure
from these callbacks,
it will terminate the waiter.
started_at = Time.now
# poll for 1 hour, instead of a number of attempts
proc = Proc.new do |attempts, response|
throw :failure if Time.now - started_at > 3600
end
# disable max attempts
instance.wait_until(before_wait:proc, max_attempts:nil) {...}
Handling Errors
When a waiter is successful, it returns the Resource. When a waiter fails, it raises an error.
begin
resource.wait_until(...)
rescue Aws::Waiters::Errors::WaiterFailed
# resource did not enter the desired state in time
end
attempts attempt in seconds invoked before each attempt invoked before each wait
397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 |
# File 'gems/aws-sdk-cloudwatch/lib/aws-sdk-cloudwatch/alarm.rb', line 397 def wait_until( = {}, &block) self_copy = self.dup attempts = 0 [:max_attempts] = 10 unless .key?(:max_attempts) [:delay] ||= 10 [:poller] = Proc.new do attempts += 1 if block.call(self_copy) [:success, self_copy] else self_copy.reload unless attempts == [:max_attempts] :retry end end Aws::Plugins::UserAgent.metric('RESOURCE_MODEL') do Aws::Waiters::Waiter.new().wait({}) end end |
#wait_until_exists(options = {}, &block) ⇒ Alarm
304 305 306 307 308 309 310 311 312 313 314 315 |
# File 'gems/aws-sdk-cloudwatch/lib/aws-sdk-cloudwatch/alarm.rb', line 304 def wait_until_exists( = {}, &block) , params = () waiter = Waiters::AlarmExists.new() yield_waiter_and_warn(waiter, &block) if block_given? Aws::Plugins::UserAgent.metric('RESOURCE_MODEL') do waiter.wait(params.merge(alarm_names: [@name])) end Alarm.new({ name: @name, client: @client }) end |