I want to monitor high memory utilization for Amazon Elastic Container Service (Amazon ECS) tasks that run on AWS Fargate.
Resolution
Set up a CloudWatch alarm
Complete the following steps:
- Open the Amazon CloudWatch console.
- Choose Alarms, and then choose All alarms.
- Choose Create alarm.
- Set an alarm condition with a statistic, period, and threshold.
Note: CloudWatch automatically turns on memory and CPU utilization metrics when Amazon ECS services use the Fargate launch type.
To view CloudWatch metrics, see View available metrics.
Turn on CloudWatch Logs for your Fargate tasks
Complete the following steps:
- Add the required logConfiguration parameters to your task definition to turn on the awslogs driver.
- Grant your AWS Identity and Access Management (IAM) task execution role logs:CreateLogStream and logs:PutLogEvents permissions to send logs to CloudWatch Logs.
- View your logs on the CloudWatch console.
Use Container Insights to monitor memory utilization
To monitor memory utilization for each container in a Fargate task, use CloudWatch Container Insights.
Complete the following steps:
- Open the CloudWatch console.
- In the navigation pane, choose Insights, and then choose Container Insights.
- On the Service dropdown list, choose ECS.
- Use the dropdown menus to select the type of resource that you want to view.
Note: Tasks are grouped by the task definition for each cluster.
- To get more information about a task definition, choose the name of the task definition.
- In the Task definition details view, choose View logs, and then open CloudWatch Logs Insights.
- In the Query text box, enter the following query, and then choose Run query:
stats avg(MemoryUtilized) by bin (30m) as period, TaskDefinitionFamily, TaskDefinitionRevision | filter Type = "Task" | sort period desc, TaskDefinitionFamily | limit 10
Related information
AWS Fargate for Amazon ECS
Introducing Amazon CloudWatch Container Insights for Amazon ECS
How Amazon ECS manages CPU and memory resources
How do I configure CloudWatch Container Insights to monitor my Amazon ECS tasks and container instance?