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

3 minute read
0

I want to monitor high memory utilization for Amazon Elastic Container Service (Amazon ECS) tasks that run on AWS Fargate.

Resolution

To monitor high memory utilization on your Amazon ECS tasks on Fargate, use the following methods.

Use Amazon CloudWatch metrics

View your CloudWatch metrics in either the Amazon ECS console or the CloudWatch console.

Note: Amazon ECS services that use the Fargate launch type are automatically turned on for CloudWatch memory and CPU utilization metrics.

Turn on CloudWatch Logs for your Fargate tasks

Complete the following steps:

  1. Turn on the awslogs log driver.
  2. Add the required log configuration parameters to your task definition.
  3. Give your task's AWS Identity and Access Management (IAM) role the permission to send logs to CloudWatch Logs.
  4. View your logs in the CloudWatch console.

Note: Before you can view your logs, your tasks must enter the Running state.

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, under Container Insights, choose Resources.
  3. To get more information on a resource, choose the name of the resource.
    Note: Tasks are grouped by the task definition for each cluster.
  4. To get more information on a task definition, choose the name of the task definition.
  5. In the Container Performance section, choose Actions, and then choose View performance logs to open CloudWatch Logs Insights.
  6. For Query, 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

Use Container Insights to set an alarm on high memory utilization

Complete the following steps:

  1. Open the CloudWatch console.
  2. In the navigation pane, under Container Insights, choose Performance Monitoring.
  3. On the menu, choose ECS Tasks or ECS Services.
  4. On the Memory Utilization card, expand the card, and then choose View in Metrics.
  5. Choose the Graphed metrics tab, and then choose the bell icon in the Actions column for your task.
  6. On the Specify metric and conditions page, choose your values, or keep the default values.
  7. In the Conditions section, for Define the threshold value, enter 70 to set the alarm's memory utilization threshold to 70%.
  8. Choose Next.
  9. On the Configure actions page, in the Select an SNS topic section, choose Create new topic.
  10. For Send a notification to, enter the email ID where you want the alarm notifications sent.
  11. Choose Next.
  12. On the Add name and description page, for Alarm name, enter a name for your alarm.
  13. (Optional) For Alarm description, enter a description for your alarm.
  14. Choose Next, and then choose Create alarm.
  15. To confirm your subscription, follow the instructions in the confirmation email.
    Note: CloudWatch doesn't automatically create all possible metrics from the log data. To view additional metrics and details, use CloudWatch Logs Insights to analyze the log data.

Related information

AWS Fargate for Amazon ECS

Introducing Amazon CloudWatch Container Insights for Amazon ECS

How Amazon ECS manages CPU and memory resources

AWS OFFICIAL
AWS OFFICIALUpdated 9 months ago
2 Comments

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

replied a year ago

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

profile pictureAWS
MODERATOR
replied a year ago