Practice Questions
Amazon CloudWatch
CloudWatch is AWS's monitoring and observability service. It collects metrics, logs, and events from AWS resources and custom applications, and enables alarms and automated responses.
Metrics
- AWS services publish metrics to CloudWatch automatically (e.g., EC2 CPU utilization, RDS FreeStorageSpace, Lambda Duration)
- Standard (basic) monitoring: 5-minute granularity; free
- Detailed monitoring: 1-minute granularity; additional cost; required for fast-reacting Auto Scaling or alarms
- Custom metrics: published by your application code using the PutMetricData API; can be at 1-second (high-resolution) granularity
- Important EC2 default metrics: CPUUtilization, NetworkIn/Out, DiskReadOps/WriteOps. Not available by default: memory utilization, disk space, and swap — these require the CloudWatch Agent
CloudWatch Agent
The CloudWatch Agent runs on EC2 instances (or on-premises servers) to collect system-level metrics (RAM, disk usage) and send application logs to CloudWatch Logs. Required for any memory or disk metric.
CloudWatch Alarms
Alarms monitor a metric and trigger actions when the metric crosses a threshold for a specified number of evaluation periods.
- States: OK, ALARM, INSUFFICIENT_DATA
- Actions: send an SNS notification, trigger an EC2 action (stop, terminate, reboot, recover), or trigger an Auto Scaling policy
- Composite alarms: combine multiple alarms with AND/OR logic to reduce alarm noise
CloudWatch Logs
CloudWatch Logs stores log data from Lambda, EC2, API Gateway, CloudTrail, and custom sources.
- Log group: container for log streams from the same source
- Log stream: sequence of log events from a single source instance