Skip to content

Monitoring guide

ECS and Fargate monitoring

On ECS and Fargate, services restart tasks for you, which hides crashes. Watch utilization against task limits, stopped-task reasons and the load balancer’s view.

4 min read13 sectionsUpdated

On this page

Key points

  • CPU and memory utilization per service against task size.
  • Stopped tasks and their reasons reveal crashes and OOM kills.
  • Running vs desired count shows failing deployments.
  • A sidecar Collector receives traces from the app container.

What to watch

SignalSourceWorry when
CPUUtilization, MemoryUtilizationAWS/ECS (per service)Sustained above 80%
Running vs desired tasksECS service eventsRunning below desired
Stopped reasondescribe-tasks"OutOfMemoryError", "Essential container exited"
Target health, 5xxAWS/ApplicationELBUnhealthy targets, rising 5xx
Request latency and errorsTracesAbove target

Why did a task stop?

bash
aws ecs list-tasks --cluster prod --service-name api --desired-status STOPPED
aws ecs describe-tasks --cluster prod --tasks <task-arn> \
  --query 'tasks[].{stopped:stoppedReason, containers:containers[].{name:name,exit:exitCode,reason:reason}}'

A sidecar Collector for traces

Add an OpenTelemetry Collector container to the task definition; the app sends OTLP to localhost:4318, and the Collector forwards to your backend (for VitalRix, over OTLP/HTTP with the API key from Secrets Manager). Mark the app container as essential and give the Collector a small CPU and memory share.

ECS monitoring with VitalRix

Pull AWS/ECS and AWS/ApplicationELB metrics with the CloudWatch integration, send traces through the sidecar for APM, ship container logs to log management, and check the public endpoints with uptime monitoring.

Watching deployments

ECS rolling deployments replace tasks gradually and, with the deployment circuit breaker enabled, roll back when new tasks keep failing health checks. Watch running versus desired count and the service's event messages during each deploy. Tag telemetry with the image version as service.version, so APM can compare the new tasks with the old ones while both serve traffic.

Alerts to start with

  • Running tasks below desired for 10 minutes.
  • Any task stopped with OutOfMemoryError.
  • Memory utilization above 90% of the task size.
  • ALB unhealthy targets above 0, or target 5xx rising.
  • Service p95 latency above target from traces.

Right-sizing tasks

Fargate bills by task CPU and memory. If a service sits at 15% CPU and 30% memory all day, the tasks are oversized; if it regularly hits 90%, latency suffers. Review utilization percentiles monthly and adjust task sizes and autoscaling targets together.

What to watch on ECS and Fargate

MetricSourceStarting alert
Service CPU and memory utilisationCloudWatch AWS/ECSMemory above 85% (tasks are killed at the hard limit)
Running vs desired task countCloudWatch Container InsightsRunning below desired for 5 minutes
Task stop reasonsECS events and stoppedReasonOutOfMemory (exit code 137), essential container exited, failed health checks
Target health behind the load balancerHealthyHostCount, UnHealthyHostCountAny unhealthy target for 5 minutes
Load balancer 5xxHTTPCode_Target_5XX_Count, HTTPCode_ELB_5XX_CountAbove 1% of requests
Deployment stateECS deployment events, circuit breakerA deployment rolled back or stuck
bash
# why did tasks stop recently?
aws ecs list-tasks --cluster prod --service-name api --desired-status STOPPED --query 'taskArns' --output text \
  | xargs -n 10 aws ecs describe-tasks --cluster prod --tasks --query 'tasks[].{stopped:stoppedReason,exit:containers[0].exitCode}'

What the incidents look like

  • Exit code 137 in a loop: the container exceeded its memory limit and was killed, then restarted, then killed again. Raise the limit or fix the leak; see Node.js memory leaks and Java OutOfMemoryError.
  • Health check grace period too short: slow-starting tasks are killed before they are ready and the service never stabilises.
  • A deployment that never finishes because new tasks fail their health check; the circuit breaker rolls it back if you enabled it.
  • Logs lost on crash when the application buffers them; log to stdout without buffering so the awslogs or FireLens driver captures the last lines.

Run an OpenTelemetry Collector as a sidecar (for example the AWS Distro for OpenTelemetry) to send traces and metrics from every task, and pair it with an external uptime check on the public endpoint.

Frequently asked questions

Where do Fargate container logs go?

Usually to CloudWatch Logs through the awslogs driver, or to any destination through FireLens (Fluent Bit). FireLens can forward to a log platform directly.

How do I catch OOM kills on Fargate?

Check stopped reasons for OutOfMemoryError and alert on memory utilization near 100% of the task’s memory.

  • What is a span in tracing?: What a span is in distributed tracing: its fields, parent and child spans, span kinds, attributes and status, with an annotated example you can read.
  • How to monitor a Next.js app: How to monitor a Next.js app in production: uptime checks, Core Web Vitals, server and edge errors, OpenTelemetry traces for SSR and API routes, and alerts.
  • OpenTelemetry for FastAPI: Trace a FastAPI service with OpenTelemetry: instrument the app, async database drivers and httpx, run uvicorn workers correctly and export.
  • OpenTelemetry for Go: Instrument a Go service with OpenTelemetry: set up the tracer provider, wrap net/http with otelhttp, pass context everywhere and export the spans.
  • OpenTelemetry for PHP and Laravel: Trace a Laravel app with OpenTelemetry: install the PHP extension and auto-instrumentation packages, configure PHP-FPM and trace queries.
  • OpenTelemetry for NestJS: Trace a NestJS service with OpenTelemetry: load the SDK before Nest boots, instrument HTTP, Express and NestJS core, and export JSON to VitalRix.

Watch your own site and services with VitalRix

Uptime checks, APM, logs, real-user monitoring, alerts and status pages in one place. Every product has a free tier and no credit card is needed.