Skip to content

How do I monitor high memory utilization for Amazon ECS tasks on Fargate?

2 minute read
0

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:

  1. Open the Amazon CloudWatch console.
  2. Choose Alarms, and then choose All alarms.
  3. Choose Create alarm.
  4. 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:

  1. Add the required logConfiguration parameters to your task definition to turn on the awslogs driver.
  2. Grant your AWS Identity and Access Management (IAM) task execution role logs:CreateLogStream and logs:PutLogEvents permissions to send logs to CloudWatch Logs.
  3. 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:

  1. Open the CloudWatch console.
  2. In the navigation pane, choose Insights, and then choose Container Insights.
  3. On the Service dropdown list, choose ECS.
  4. 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.
  5. To get more information about a task definition, choose the name of the task definition.
  6. In the Task definition details view, choose View logs, and then open CloudWatch Logs Insights.
  7. 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?

AWS OFFICIALUpdated 5 months ago
4 Comments

It's absurd that AWS Batch doesn't show metrics by default when I click on a job and have awslogdriver enabled.

replied 2 years ago

Thank you for your comment. We'll review and update the Knowledge Center article as needed.

AWS
MODERATOR
replied 2 years ago

How is turning on CloudWatch logs relevant for monitoring memory utilization? I see nothing in my Fargate tasks CloudWatch logs that has any information about memory utilization.

The answer claims, "Note: CloudWatch automatically turns on memory and CPU utilization metrics when Amazon ECS services use the Fargate launch type." Do I need to also enable a CloudWatch alarm? I have a Fargate task that, when I check in CloudWatch > Metrics > All metrics does not have any metrics collected. Other Fargate tasks do, so I'm not sure why some Fargate tasks have metrics and others don't.

replied 4 months ago

Thank you for your comment. We'll review and update the Knowledge Center article as needed.

AWS
MODERATOR
replied 4 months ago