Monitoring Resources with Amazon CloudWatch
This lesson explains how CloudWatch collects metrics and logs, raises alarms and triggers automated actions.
Learning outcomes
After completing this lesson, you will be able to:
- Distinguish basic and detailed monitoring and custom metrics.
- Describe alarms and their actions.
- Explain CloudWatch Logs retention, metric filters and subscription filters.
- Identify wider observability features.
Metrics
AWS services publish metrics to CloudWatch automatically. For EC2, basic monitoring publishes metrics every five minutes, and detailed monitoring, which is charged, every minute. Some measures are invisible to AWS: EC2 cannot see inside an instance's operating system, so memory and disk space usage require the CloudWatch agent installed on the instance.
Applications can publish custom metrics, at standard resolution or at high resolution down to one second. CloudWatch keeps metrics for 15 months, with lower resolution for older data.
Alarms
A CloudWatch alarm watches a metric, or a metric math expression that combines metrics, and changes state when it crosses a threshold for a set number of periods. An alarm can then send an Amazon SNS notification, trigger an Auto Scaling policy, perform an EC2 action, such as stopping, terminating, rebooting or recovering an instance, or start a Systems Manager action.
Composite alarms combine several alarms with logical conditions, so that one incident produces one notification instead of many, which reduces alert fatigue.
The following diagram shows an alarm and the actions it can take.

Alarms and observability
CloudWatch Logs
CloudWatch Logs stores log data from AWS services, applications and the CloudWatch agent in log groups. By default, log groups never expire, so a retention period should be set on each to control cost.
Metric filters turn patterns in logs into metrics that alarms can watch, for example counting ERROR lines in application logs or failed console sign-ins in CloudTrail logs. Logs Insights runs interactive queries over logs. Subscription filters stream log events in near real time to Lambda, Kinesis or Firehose, and logs can be exported to Amazon S3 for long-term storage.
CloudWatch Logs features
Wider observability
Beyond metrics, alarms and logs, CloudWatch includes several observability features. Dashboards display metrics and alarms from many services on one screen. Synthetics canaries run scripts on a schedule that test endpoints and user journeys, detecting problems before users do. Real User Monitoring (RUM) measures the experience of actual users in their browsers, Application Signals tracks service health and objectives, and Container Insights collects metrics from containers.
In multi-account organisations, cross-account observability lets a central monitoring account see metrics, logs and traces from many source accounts, so operations teams work from one place.
CloudWatch metrics
Monitoring a web application
Monitoring a web application involves several distinct needs. The following table identifies the CloudWatch feature that addresses each.
| Need | CloudWatch feature |
|---|---|
| Alert when the error rate rises | Alarm on ALB 5xx metrics, notifying SNS |
| Memory and disk usage of EC2 instances | CloudWatch agent (not collected by default) |
| Search application logs during an incident | CloudWatch Logs with Logs Insights |
| Recover an instance on hardware failure | Alarm on StatusCheckFailed_System with the recover action |
| Scale on demand | Alarms driving Auto Scaling policies |
| Check the login page works every 5 minutes | CloudWatch Synthetics canary |
Memory metrics are a classic exam point: EC2's default metrics cover CPU, network and disk operations seen by the hypervisor, but not memory or file system usage inside the instance.
How can memory utilisation of EC2 instances be monitored?
Show answer
By installing the CloudWatch agent, which publishes memory and disk metrics. EC2 does not report them by default, because they are inside the operating system.
Exam Tips
Remember for the exam
- To monitor EC2 memory usage, install the CloudWatch agent.
- To recover an impaired instance automatically, use a CloudWatch alarm with the recover action.
- To stream logs to OpenSearch or S3 in near real time, use a subscription filter to Firehose.
- Set log retention periods to control costs.
- To alarm on a pattern in log files, use a metric filter with an alarm.
- To monitor many accounts from one place, use CloudWatch cross-account observability.