Monitoring and Observability

Track ECS health with CloudWatch metrics, logs, and Container Insights.

Keep an eye on your services with the AWS observability stack.

What to watch

  • CloudWatch metrics — CPU and memory utilization per service and cluster.
  • CloudWatch Logs — container output via the awslogs driver.
  • Container Insights — richer per-task metrics and dashboards.
  • Service events — from describe-services, the first stop when tasks will not start.

Example

Example · bash
# Turn on Container Insights for a cluster
aws ecs update-cluster-settings \
  --cluster prod \
  --settings name=containerInsights,value=enabled

# Read recent service events when debugging
aws ecs describe-services --cluster prod --services web \
  --query 'services[0].events[0:5]'

When to use it

  • An SRE creates a CloudWatch dashboard with ECS CPUUtilization and MemoryUtilization metrics to spot resource saturation before tasks are OOM-killed.
  • A developer uses Container Insights to drill into per-task CPU and memory metrics during a load test to find which container is the bottleneck.
  • An ops team sets a CloudWatch alarm on ECS service RunningTaskCount to page on-call if fewer than the minimum number of tasks are healthy.

More examples

Enable Container Insights on Cluster

Turns on Container Insights for the cluster so per-task CPU, memory, network, and storage metrics are automatically published to CloudWatch.

Example · bash
aws ecs update-cluster-settings \
  --cluster prod \
  --settings name=containerInsights,value=enabled

Create Alarm on Running Task Count

Pages the ops team via SNS when the average running task count drops below 2 for two consecutive 1-minute periods.

Example · bash
aws cloudwatch put-metric-alarm \
  --alarm-name ecs-api-min-tasks \
  --namespace AWS/ECS \
  --metric-name RunningTaskCount \
  --dimensions Name=ClusterName,Value=prod Name=ServiceName,Value=api \
  --statistic Average \
  --period 60 \
  --evaluation-periods 2 \
  --threshold 2 \
  --comparison-operator LessThanThreshold \
  --alarm-actions arn:aws:sns:us-east-1:123456789012:ops-alerts

Query Container Insights Metrics

Fetches the average memory used by the api service over the last hour in 5-minute intervals from Container Insights.

Example · bash
aws cloudwatch get-metric-statistics \
  --namespace ECS/ContainerInsights \
  --metric-name MemoryUtilized \
  --dimensions Name=ClusterName,Value=prod Name=ServiceName,Value=api \
  --start-time $(date -u -d '-1 hour' +%FT%TZ) \
  --end-time $(date -u +%FT%TZ) \
  --period 300 \
  --statistics Average

Discussion

  • Be the first to comment on this lesson.