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
| Signal | Source | Worry when |
|---|---|---|
| CPUUtilization, MemoryUtilization | AWS/ECS (per service) | Sustained above 80% |
| Running vs desired tasks | ECS service events | Running below desired |
| Stopped reason | describe-tasks | "OutOfMemoryError", "Essential container exited" |
| Target health, 5xx | AWS/ApplicationELB | Unhealthy targets, rising 5xx |
| Request latency and errors | Traces | Above target |
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.
| Metric | Source | Starting alert |
|---|---|---|
| Service CPU and memory utilisation | CloudWatch AWS/ECS | Memory above 85% (tasks are killed at the hard limit) |
| Running vs desired task count | CloudWatch Container Insights | Running below desired for 5 minutes |
| Task stop reasons | ECS events and stoppedReason | OutOfMemory (exit code 137), essential container exited, failed health checks |
| Target health behind the load balancer | HealthyHostCount, UnHealthyHostCount | Any unhealthy target for 5 minutes |
| Load balancer 5xx | HTTPCode_Target_5XX_Count, HTTPCode_ELB_5XX_Count | Above 1% of requests |
| Deployment state | ECS deployment events, circuit breaker | A deployment rolled back or stuck |
# 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.
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.
Related reading
- 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.