Lesson 4 of 5 CloudWatch Metrics, Alarms and Dashboards

Designing CloudWatch Alarms and Notifications

An alarm turns a metric into an action: a notification, a scaling event or an automated remediation. Poorly designed alarms either miss incidents or fire so often that people ignore them. This lesson explains alarm evaluation, missing data handling, static and anomaly detection thresholds, metric math and Metrics Insights alarms, composite alarms, and the actions and notification paths alarms can trigger.

Learning outcomes

After completing this lesson, you will be able to:

  • Explain alarm states and how period, evaluation periods and datapoints to alarm determine when an alarm fires.
  • Describe the options for treating missing data and when each is appropriate.
  • Compare static threshold, anomaly detection, metric math and composite alarms.
  • Describe alarm actions, including SNS, Auto Scaling, EC2 actions, Lambda and Systems Manager, and notification routing.

Alarm Evaluation

A metric alarm watches one metric or one metric math expression and is in one of three states: OK, ALARM or INSUFFICIENT_DATA. Three settings decide when it changes state. The period is the length of time over which the statistic is computed for each data point, such as 60 seconds. Evaluation periods (N) is how many recent periods are considered. Datapoints to alarm (M) is how many of those must breach the threshold. An "M out of N" alarm, such as 3 out of 5, fires on sustained problems while tolerating isolated spikes, which reduces false alarms without much delay.

The time to detect a problem is roughly M periods. A one-minute period with three of five datapoints detects in about three minutes; high-resolution alarms with 10-second periods detect faster for critical metrics.

The following diagram shows a 3 out of 5 alarm evaluating two windows of datapoints.

How an M out of N alarm evaluates. Each period produces one datapoint, and the alarm looks at the last N periods. With 3 out of 5, an isolated spike above the threshold does not change the state, but three breaching datapoints within the last five move the alarm to ALARM. Detection takes roughly M periods, so a one-minute period with 3 of 5 detects a sustained problem in about three minutes.
M out of N tolerates isolated spikes without much delay.

Missing Data

Metrics sometimes have no data points, for example when an instance stops reporting or an error metric is only published when errors occur. The treat missing data setting decides how such periods are evaluated.

SettingMissing data is treated asAppropriate when
missing (default)Ignored; the alarm looks further back for enough data, and may move to INSUFFICIENT_DATAGeneral use
notBreachingWithin the threshold (good)The metric is only published when something happens, such as error counts
breachingOver the threshold (bad)Absence of data means failure, such as a heartbeat metric
ignoreThe alarm state is kept unchangedSparse metrics where state should persist

Silent failures

An alarm on a heartbeat metric with the default setting goes to INSUFFICIENT_DATA, not ALARM, when the process stops publishing, so nobody is notified. Treat missing data as breaching for heartbeats.

Sort into groups

Treat missing data

Exam skills 4.2.2 · 4.3.2

Choose how each alarm should treat periods with no data.

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

Types of Threshold

Alarms can compare a metric with different kinds of threshold.

Static thresholds

A fixed value, such as CPU above 80% or 5xx errors above 10 per minute. Simple and predictable, but they fit poorly for metrics with daily or weekly patterns, where a value normal at noon is abnormal at 3 a.m.

Anomaly detection

CloudWatch trains a model on up to two weeks of a metric's history, including hourly, daily and weekly seasonality and trends, and produces an expected band. An anomaly detection alarm fires when the metric goes above, below or outside the band, with the band width set in standard deviations. It suits metrics such as request counts and latency with regular patterns, and it is the recommended alternative to Amazon DevOps Guru, which is closed to new customers. Specific periods, such as a past incident, can be excluded from training.

Metric math and Metrics Insights alarms

Alarms can watch a metric math expression, such as an error rate percentage or the sum of a metric across several resources, or a Metrics Insights query, such as the maximum CPU across all instances with a tag, which automatically includes new resources.

Composite alarms

A composite alarm combines the states of other alarms with a rule expression using AND, OR and NOT, such as ALARM(HighLatency) AND ALARM(HighErrorRate). Composite alarms reduce noise by notifying only when several symptoms indicate a real problem, and they support action suppression: while a suppressor alarm, such as a maintenance-window or dependency-outage alarm, is in ALARM, the composite alarm's actions are suppressed. Typically, only the composite alarm has notification actions, and the underlying alarms have none.

Static
ThresholdFixed value
Best forHard limits such as disk full
Choose when The acceptable value is known and stable.
Anomaly detection
ThresholdLearned band
Best forSeasonal or trending metrics
Choose when Normal behaviour varies by time.
Composite
ThresholdRule over other alarms
Best forReducing noise, correlating symptoms
Choose when Many alarms create alert fatigue.

The following diagram shows how a composite alarm combines and suppresses other alarms.

A composite alarm. Child alarms, such as high latency and a high error rate, have no notification actions. The composite alarm combines their states with a rule such as ALARM(HighLatency) AND ALARM(HighErrorRate) and is the only alarm that notifies, so one incident produces one notification. While a suppressor alarm, such as a maintenance-window alarm, is in ALARM, the composite alarm's actions are suppressed.
Only the composite alarm has notification actions.

Alarm Actions and Notifications

Alarms can take several kinds of action when they change state, described below.

  • Amazon SNS: publish to a topic that delivers to email, SMS, HTTPS endpoints, SQS, Lambda or chat channels through Amazon Q Developer in chat applications (formerly AWS Chatbot) for Slack and Microsoft Teams.
  • Auto Scaling: run a step or simple scaling policy.
  • EC2 actions: stop, terminate, reboot or recover an instance.
  • AWS Lambda: invoke a function directly, without SNS, for remediation or enrichment.
  • Systems Manager: create an OpsCenter OpsItem for operational tracking.
  • Investigations: start a CloudWatch investigation, which uses AI to analyse related telemetry and suggest root causes and runbooks.

Every alarm state change is also published to EventBridge as a CloudWatch Alarm State Change event, which allows richer routing, for example to Step Functions workflows, to a central event bus or to incident management tools. Actions can be configured separately for ALARM, OK and INSUFFICIENT_DATA transitions, so that a recovery notification is sent when the alarm returns to OK.

Scenario questions

Design the alarms

Exam skills 4.2.2 · 4.3.2

Practise alarm types and actions.

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

Reducing Alert Fatigue

An on-call engineer receives about 200 alarm emails a week. Most are CPU spikes that resolve themselves, many alarms fire together during a single incident, and a payment heartbeat failure went unnoticed because its alarm sat in INSUFFICIENT_DATA.

  1. Tolerate spikes

    Change CPU alarms to 3 out of 5 one-minute datapoints, or remove them where CPU is not a customer-facing symptom.

  2. Seasonal metrics

    Replace static request-count thresholds with anomaly detection alarms.

  3. Correlate

    Create a composite alarm per service combining latency and error alarms, with only the composite sending notifications, suppressed during approved maintenance.

  4. Heartbeats

    Set the heartbeat alarm to treat missing data as breaching.

  5. Routing

    Send composite alarm notifications to the team's chat channel through SNS and Amazon Q Developer in chat applications, and create OpsItems for tracking.

Check yourself

An alarm should fire only if errors exceed the threshold in at least 3 of the last 5 minutes. Which settings achieve this?

Show answer

Period 60 seconds, evaluation periods 5 and datapoints to alarm 3.

Exam Tips

Remember for the exam

  • Datapoints to alarm (M) out of evaluation periods (N) tolerates isolated spikes; detection time is about M periods.
  • Treat missing data as breaching for heartbeats and notBreaching for metrics published only on events.
  • Anomaly detection alarms suit seasonal metrics; composite alarms combine alarms with AND/OR/NOT and support action suppression.
  • Alarm actions: SNS, Auto Scaling, EC2 stop/terminate/reboot/recover, Lambda, Systems Manager OpsItems; state changes are also EventBridge events.
  • Use CloudWatch anomaly detection rather than Amazon DevOps Guru, which is closed to new customers.