Sub topic 1
What CloudWatch does: metrics, logs, alarms, and dashboards
Prerequisites
This chapter assumes you have the following:
- An AWS account, and an understanding of regions and IAM permissions.
- Working knowledge of EC2 or another AWS compute service.
- Comfort running AWS CLI commands.
- A basic idea of what logs and metrics are.
The working model
Amazon CloudWatch is the AWS service that collects telemetry from your resources and applications, stores it, and lets you act on it. Four features cover most daily use:
- Metrics are time-ordered numbers, such as CPU utilization or request count.
- Logs are text events written by applications and services, grouped for storage and search.
- Alarms watch a metric and change state or trigger an action when it crosses a threshold.
- Dashboards are customizable pages that show metrics, alarms, and log query results together.
Many AWS services publish metrics to CloudWatch automatically, with no setup. EC2, RDS, Lambda, and Application Load Balancer all do this. Logs usually need an explicit step, such as enabling logging on a service or installing an agent.
Metrics and logs are different signals
A metric is cheap to store and fast to graph, and it answers "how much, and how often." A log event carries detail, and it answers "what exactly happened." You usually use both. A metric shows that errors rose at 18:40, and the logs show which request failed and why.
The two signals connect in both directions. A metric filter turns matching log events into a metric. A Logs Insights query reads logs on demand and can be placed on a dashboard.
Seeing what already exists
You can list the metrics your account already publishes. This command lists the EC2 CPU metrics in the current region:
aws cloudwatch list-metrics \
--namespace AWS/EC2 \
--metric-name CPUUtilizationEach result identifies a metric by namespace, name, and dimensions. Later chapters explain these parts in detail.
Scope and common surprises
- CloudWatch data is regional. A dashboard or alarm works with data in a region, so check the region first when something seems missing. Cross-region and cross-account views are a separate feature.
- Default EC2 metrics arrive at 5-minute granularity. Detailed monitoring gives 1-minute data.
- EC2 does not report memory or disk usage by default. The CloudWatch agent collects those.
- Log groups keep data forever unless you set a retention period. This is a common source of unexpected cost.
Exercise
A teammate says an EC2 instance's memory usage is missing from CloudWatch, though CPU shows up. What is the likely reason, and what fixes it?
Show answer
EC2 publishes CPU, network, and disk I/O metrics automatically, but it cannot see inside the operating system for memory usage. Install and configure the CloudWatch agent on the instance so it publishes memory as a custom metric.