0Pricing
AWS Solutions Architect · Lesson

CloudWatch Metrics, Namespaces, and Dimensions

Understand built-in AWS service metrics, publish custom metrics from your application, and filter by dimensions to drill into specific resources.

CloudWatch Metrics, Namespaces, and Dimensions is a free AWS Solutions Architect lesson on CoddyKit — lesson 1 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the AWS Solutions Architect learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

What Is Amazon CloudWatch?

Amazon CloudWatch is AWS's unified observability service that collects metrics, logs, and traces from your AWS resources and applications. It gives you a complete picture of your infrastructure health, enabling you to detect anomalies, set alarms, and automatically react to operational changes. CloudWatch is deeply integrated with almost every AWS service and is the primary monitoring tool tested in the SAA-C03 exam.

Understanding CloudWatch Metrics

A CloudWatch metric is a time-ordered set of data points representing the value of a measurable aspect of a resource over time — for example, CPUUtilization for an EC2 instance measured every minute. Metrics are identified by their namespace, name, and dimensions. AWS publishes hundreds of built-in metrics automatically, and you can publish your own custom metrics from your application code or scripts.

Namespaces: Organising Metrics

A namespace is a container for CloudWatch metrics that prevents name collisions between metrics from different sources. AWS services use namespaces like AWS/EC2, AWS/RDS, AWS/Lambda, and AWS/S3. When you publish custom metrics, you choose your own namespace — for example MyApp/OrderService. Metrics in different namespaces are completely isolated from each other even if they share the same metric name.

# List all namespaces in your account
aws cloudwatch list-metrics \
  --query 'Metrics[].Namespace' \
  --output text | tr '\t' '\n' | sort -u

# List metrics in the AWS/EC2 namespace
aws cloudwatch list-metrics \
  --namespace AWS/EC2 \
  --query 'Metrics[].MetricName' \
  --output text | tr '\t' '\n' | sort -u

Dimensions: Filtering Metrics

Dimensions are key-value pairs that uniquely identify a metric within a namespace. For example, in the AWS/EC2 namespace, CPUUtilization can be filtered by the dimension InstanceId=i-0123456789abcdef0 to see one specific instance, or by AutoScalingGroupName=my-asg to see the aggregated metric across a fleet. A single metric can have up to 30 dimensions and AWS pre-defines which dimensions are available for each service metric.

# Get CPU utilization for a specific EC2 instance
aws cloudwatch get-metric-statistics \
  --namespace AWS/EC2 \
  --metric-name CPUUtilization \
  --dimensions Name=InstanceId,Value=i-0123456789abcdef0 \
  --start-time 2024-01-01T00:00:00Z \
  --end-time 2024-01-01T01:00:00Z \
  --period 300 \
  --statistics Average

Standard vs Detailed Monitoring

By default, AWS services publish metrics at 5-minute intervals (standard monitoring) to CloudWatch at no extra charge. For time-sensitive workloads you can enable detailed monitoring to get 1-minute granularity. Detailed monitoring is available for EC2, Auto Scaling, ELB, RDS, and other services — it incurs additional CloudWatch charges. For SAA-C03, remember that Auto Scaling policies using step scaling rely on CloudWatch alarms that work better with 1-minute metrics.

# Enable detailed (1-minute) monitoring for an EC2 instance
aws ec2 monitor-instances \
  --instance-ids i-0123456789abcdef0

# Verify monitoring state
aws ec2 describe-instance-status \
  --instance-ids i-0123456789abcdef0 \
  --query 'InstanceStatuses[].Monitoring'

Publishing Custom Metrics

You can push custom metrics to CloudWatch from any application using the put-metric-data API or the CloudWatch Agent. Common custom metrics include business KPIs (orders per minute), application-level latency, queue depth, and error rates. Custom metrics are retained for 15 months with variable resolution, costing per metric per month. High-resolution custom metrics (1-second granularity) are also supported at higher cost.

# Publish a custom metric from the CLI
aws cloudwatch put-metric-data \
  --namespace 'MyApp/OrderService' \
  --metric-name 'OrdersProcessedPerMinute' \
  --value 47 \
  --unit Count \
  --dimensions Environment=Production,Region=us-east-1

# Publish from application code (Python boto3)
# cloudwatch.put_metric_data(
#   Namespace='MyApp/OrderService',
#   MetricData=[{'MetricName': 'ErrorRate', 'Value': 0.5, 'Unit': 'Percent'}]
# )

CloudWatch Agent for EC2 Metrics

The CloudWatch Agent is a software agent you install on EC2 instances (and on-premises servers) to collect metrics not available via the built-in EC2 hypervisor, such as memory utilisation, disk space, and network connections. The agent also collects logs and sends them to CloudWatch Logs. Memory utilisation is a common exam scenario — it is NOT a default EC2 metric and MUST be collected via the CloudWatch Agent.

# Install and start the CloudWatch Agent on Amazon Linux 2
sudo yum install -y amazon-cloudwatch-agent

# Use the wizard to generate a config
sudo /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-config-wizard

# Start the agent with the generated config
sudo /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl \
  -a fetch-config \
  -m ec2 \
  -s \
  -c ssm:/AmazonCloudWatch-linux

Metric Math and Anomaly Detection

Metric math lets you create new time series by performing arithmetic on existing metrics without storing the result as a separate metric. For example, you can compute error rate as Errors / Requests * 100 directly in a CloudWatch dashboard expression. Anomaly detection applies machine learning to historical metric data to create expected value bands, and you can create alarms that fire when a metric deviates outside those bands — even if there is no fixed threshold.

# Get metric data using metric math
aws cloudwatch get-metric-data \
  --metric-data-queries '[
    {"Id":"e1","Expression":"m1/m2*100","Label":"ErrorRate%"},
    {"Id":"m1","MetricStat":{"Metric":{"Namespace":"MyApp","MetricName":"Errors"},"Period":60,"Stat":"Sum"}},
    {"Id":"m2","MetricStat":{"Metric":{"Namespace":"MyApp","MetricName":"Requests"},"Period":60,"Stat":"Sum"}}
  ]' \
  --start-time 2024-01-01T00:00:00Z \
  --end-time 2024-01-01T01:00:00Z

Metric Retention Periods

CloudWatch stores metrics with varying retention based on their resolution: data points at 1-second resolution are retained for 3 hours, 1-minute data for 15 days, 5-minute data for 63 days, and 1-hour data for 15 months. CloudWatch automatically aggregates high-resolution data into lower-resolution data over time. This means if you need to analyse long-term trends you will see 1-hour averages — not the original 1-minute readings from months ago.

Viewing Metrics in the CloudWatch Console

The CloudWatch console provides a Metrics Explorer and Metrics browser where you can select any namespace, metric, and dimension combination and visualise data over time. You can overlay multiple metrics on a single graph, change aggregation periods, and add them to dashboards. For programmatic access, the GetMetricStatistics and GetMetricData APIs return raw data points or aggregate statistics (Average, Sum, Minimum, Maximum, SampleCount).

# Get average CPU for all instances in an ASG over the last hour
aws cloudwatch get-metric-statistics \
  --namespace AWS/EC2 \
  --metric-name CPUUtilization \
  --dimensions Name=AutoScalingGroupName,Value=my-asg \
  --start-time $(date -u -d '1 hour ago' +%Y-%m-%dT%H:%M:%SZ) \
  --end-time $(date -u +%Y-%m-%dT%H:%M:%SZ) \
  --period 300 \
  --statistics Average Maximum

Key EC2 and RDS Metrics

For the SAA-C03 exam, know these critical metrics: EC2CPUUtilization, NetworkIn/Out, DiskReadOps/WriteOps (instance store only); missing from EC2 by default: memory, disk space (use CloudWatch Agent). RDSDatabaseConnections, FreeStorageSpace, ReadLatency, WriteLatency, ReplicaLag. ELBRequestCount, TargetResponseTime, UnHealthyHostCount. LambdaInvocations, Errors, Duration, Throttles, ConcurrentExecutions.

Quick Check

Test your understanding of AWS Solutions Architect (SAA-C03) concepts from this lesson.

Lesson Recap

In this lesson you learned: namespaces organise metrics by service and prevent name collisions, dimensions filter metrics to specific resources like a single EC2 instance or ASG, and memory utilisation is not a default EC2 metric — you need the CloudWatch Agent for that. Next up we explore CloudWatch Alarms and Composite Alarms for automated alerting.

Frequently asked questions

Is the “CloudWatch Metrics, Namespaces, and Dimensions” lesson free?

Yes — the full text of “CloudWatch Metrics, Namespaces, and Dimensions” is free to read here on the web, and the AWS Solutions Architect course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the AWS Solutions Architect course, upgrade to CoddyKit PRO.

What will I learn in “CloudWatch Metrics, Namespaces, and Dimensions”?

Understand built-in AWS service metrics, publish custom metrics from your application, and filter by dimensions to drill into specific resources. You practise AWS Solutions Architect with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start AWS Solutions Architect?

No prior experience is required. AWS Solutions Architect on CoddyKit is structured for beginners through advanced learners; this is — lesson 1 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “CloudWatch Metrics, Namespaces, and Dimensions” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this AWS Solutions Architect lesson?

Yes. Every AWS Solutions Architect lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. CloudWatch Metrics, Namespaces, and Dimensions
  2. CloudWatch Alarms and Composite Alarms
  3. CloudWatch Logs and Log Insights
  4. CloudWatch Dashboards and Container Insights
← Back to AWS Solutions Architect