Lesson 3 of 5 Amazon CloudWatch Metrics and Alarms

Configuring and Troubleshooting Alarm Evaluation

This lesson explains exactly when a CloudWatch alarm changes state, watching a metric, a metric math expression or an anomaly band, which is essential for configuring and troubleshooting alarms.

Learning outcomes

After completing this lesson, you will be able to:

  • Distinguish the OK, ALARM and INSUFFICIENT_DATA states.
  • Configure period, evaluation periods and datapoints to alarm.
  • Choose how missing data is treated.
  • Diagnose an alarm that never fires.

Alarm states

An alarm is always in one of three states. OK means the metric is within the threshold. ALARM means it has breached the threshold for the required number of datapoints. INSUFFICIENT_DATA means the alarm has just started, the metric is not available, or not enough data exists to decide. Actions can be attached to each state, so an alarm can notify when it enters ALARM and again when it returns to OK.

Period, evaluation periods and datapoints to alarm

Three settings control sensitivity. The period is the length of time over which the statistic is calculated for each datapoint. Evaluation periods (N) is how many recent datapoints are considered. Datapoints to alarm (M) is how many of those N must breach. A setting of 3 out of 3 with a 1-minute period requires three consecutive breaching minutes; 3 out of 5 tolerates brief recoveries and reduces flapping on noisy metrics. The time before an alarm can fire is roughly the period multiplied by M, plus metric publishing delay.

The following diagram applies two settings to the same five datapoints.

How datapoints to alarm and evaluation periods work. With 3 out of 3, three consecutive breaching one-minute datapoints are needed. With 3 out of 5, any three breaching datapoints within the last five trigger the alarm, so a brief recovery does not reset it and the alarm flaps less on a noisy metric.
The values are illustrative. Only the third datapoint is below the threshold, which resets a 3 out of 3 alarm but not a 3 out of 5 one.
Scenario questions

M out of N

Exam skills 1.1.3

Work out when an alarm changes state from its evaluation settings.

Log in to try this activity Interactive activities are free with an account.

Missing data treatment

Metrics sometimes stop reporting: an instance is stopped, a Lambda function is not invoked, or an error-count metric publishes nothing when there are no errors. The treat missing data setting decides how the alarm interprets gaps. The following table describes the four options.

SettingEffectUse when
missing (default)Gaps are ignored when evaluating; if all datapoints are missing the alarm goes to INSUFFICIENT_DATAThe metric should always report
notBreachingGaps count as within the thresholdSparse metrics such as error counts, where no data means no errors
breachingGaps count as breachingMissing data itself signals failure, such as a heartbeat metric
ignoreThe alarm keeps its current stateIntermittent metrics where state should not change on gaps

The following diagram shows how each setting interprets the same gaps.

How the treat missing data setting interprets the same gaps. With missing, gaps are ignored and an alarm whose datapoints are all missing goes to INSUFFICIENT_DATA. notBreaching counts gaps as within the threshold, which suits error counts. breaching counts gaps as failures, which suits heartbeats. ignore keeps the current state.
The datapoints are illustrative. Choosing the setting is a statement about what silence means for the metric.
Match the pairs

Missing data options

Exam skills 1.1.3

Match each missing data treatment with what it does.

Log in to try this activity Interactive activities are free with an account.
Worked example

An alarm that never fires

A team creates an alarm on Errors for a Lambda function with Statistic Average, threshold 5, period 5 minutes and 1 of 1 datapoints. During an incident the function returns 40 errors out of 4,000 invocations in five minutes, yet the alarm stays OK. Each invocation contributes a value of 1 (failed) or 0 (succeeded) to the Errors series, so the Average over the period is the error rate, here 40 / 4,000 = 0.01, which can never exceed 5. The fix is to use the Sum statistic (40 breaches 5) or to alarm on an error rate computed with metric math. Because the metric publishes nothing when the function is not invoked, missing data should be treated as notBreaching to avoid INSUFFICIENT_DATA overnight.

Check yourself

How should missing data be treated for a heartbeat metric?

Show answer

As breaching, because a missing heartbeat means the sender has stopped.

Exam Tips

Remember for the exam

  • Alarm states are OK, ALARM and INSUFFICIENT_DATA; actions can be attached to each.
  • M out of N datapoints reduces false alarms on noisy metrics.
  • Treat missing data as notBreaching for sparse error metrics and breaching for heartbeats.
  • Use the Sum statistic for counts; Average of a count metric is a frequent mistake.