Lesson 1 of 5 Amazon CloudWatch Metrics and Alarms

Identifying and Aggregating CloudWatch Metrics

This lesson explains how Amazon CloudWatch, the central monitoring service in AWS, identifies, stores and aggregates metrics, since almost every operational question on the exam starts with a metric.

Learning outcomes

After completing this lesson, you will be able to:

  • Identify a metric by namespace, name and dimensions.
  • Identify which metrics common services publish by default.
  • Choose statistics, periods and percentiles.
  • Find the right metric with the CLI.

How a metric is identified

A metric is a time-ordered set of data points. It is identified by a namespace, which groups metrics from one source (for example AWS/EC2, AWS/ApplicationELB or a custom namespace such as MyApp/Orders), a metric name (for example CPUUtilization) and up to 30 dimensions, which are name and value pairs that describe the data (for example InstanceId=i-0abc or AutoScalingGroupName=web-asg). Every unique combination of these is a separate metric. A query for CPUUtilization with the dimension AutoScalingGroupName returns a different metric from the same name with InstanceId; a common cause of an alarm stuck in INSUFFICIENT_DATA is a dimension that does not exist.

Metrics are Regional. They are created automatically when data is first published and cannot be deleted; they expire when no new data arrives for 15 months. Metrics are retained at decreasing resolution: data points with a period below 60 seconds are kept for 3 hours, 1-minute data for 15 days, 5-minute data for 63 days and 1-hour data for 15 months.

The following diagram shows how dimensions turn one metric name into separate metrics.

How a CloudWatch metric is identified. The namespace, metric name and dimensions together identify one metric, so CPUUtilization with the dimension AutoScalingGroupName is a different metric from CPUUtilization with InstanceId. An alarm that names a dimension that does not exist finds no data and stays in INSUFFICIENT_DATA.
The names and IDs are illustrative. list-metrics shows the exact dimensions a metric is published with.

3hours

Retention of data points with a period below 60 seconds

15days

Retention of 1-minute data

63days

Retention of 5-minute data

15months

Retention of 1-hour data

True or false

Metric identity

Exam skills 1.1.1

Check how CloudWatch identifies a metric.

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

Default metrics for common services

Each service publishes its own set of metrics free of charge. Knowing which metrics exist by default, and which do not, answers many questions. EC2 publishes CPU, network, disk (instance store only) and status check metrics at 5-minute intervals with basic monitoring, or 1-minute intervals with detailed monitoring (charged). EC2 does not publish memory, swap or file system utilisation because the hypervisor cannot see inside the guest operating system; the CloudWatch agent provides those. The following table lists metrics that appear frequently in exam scenarios.

ServiceImportant metrics
EC2CPUUtilization, NetworkIn/Out, StatusCheckFailed_System, StatusCheckFailed_Instance, CPUCreditBalance (T family)
EBSVolumeReadOps, VolumeWriteOps, VolumeQueueLength, BurstBalance, VolumeIOPSExceededCheck
Application Load BalancerRequestCount, TargetResponseTime, HTTPCode_Target_5XX_Count, HTTPCode_ELB_5XX_Count, UnHealthyHostCount
RDSCPUUtilization, FreeableMemory, FreeStorageSpace, DatabaseConnections, ReadLatency, ReplicaLag
LambdaInvocations, Errors, Duration, Throttles, ConcurrentExecutions, IteratorAge
SQSApproximateNumberOfMessagesVisible, ApproximateAgeOfOldestMessage, NumberOfMessagesSent
DynamoDBConsumedReadCapacityUnits, ThrottledRequests, ReadThrottleEvents, SuccessfulRequestLatency

Statistics, periods and percentiles

CloudWatch aggregates data points over a period using a statistic. Average suits utilisation, Sum suits counts such as errors or requests, Maximum and Minimum show extremes, and SampleCount counts data points. Percentiles such as p90 or p99 show the experience of the slowest requests, which an average hides: an average latency of 120 ms can coexist with a p99 of 4 seconds. Choose the statistic that matches the question. An alarm on the Average of HTTPCode_Target_5XX_Count is almost always wrong, because Sum is the count of errors in the period.

Scenario questions

Choose the statistic

Exam skills 1.1.1 · 1.2.1

Choose the statistic that answers each monitoring question.

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

Finding the right metric with the CLI

An engineer wants to alarm on CPU for an Auto Scaling group but is not sure which dimensions exist. list-metrics shows the published combinations, and get-metric-statistics confirms that data is flowing.

aws cloudwatch list-metrics --namespace AWS/EC2 --metric-name CPUUtilization \
  --dimensions Name=AutoScalingGroupName,Value=web-asg

aws cloudwatch get-metric-statistics --namespace AWS/EC2 --metric-name CPUUtilization \
  --dimensions Name=AutoScalingGroupName,Value=web-asg \
  --start-time $(date -u -d '-1 hour' +%FT%TZ) --end-time $(date -u +%FT%TZ) \
  --period 300 --statistics Average Maximum

If list-metrics returns nothing for the group dimension, the group name is misspelt, the command is running in the wrong Region, or no instances in the group have reported data recently. Correcting the dimension, rather than changing the alarm threshold, is what moves an alarm out of INSUFFICIENT_DATA.

Check yourself

Which common EC2 measurements are not published by default?

Show answer

Memory and disk space usage. They are inside the operating system, so the CloudWatch agent must collect them.

Exam Tips

Remember for the exam

  • A metric is namespace + name + dimensions; a wrong dimension gives INSUFFICIENT_DATA.
  • EC2 basic monitoring is 5-minute; detailed monitoring is 1-minute and charged.
  • Memory and disk space are not default EC2 metrics.
  • Use Sum for counts and percentiles for latency experience.
  • Metrics cannot be deleted; they expire after 15 months without data.