How do I configure CloudWatch Container Insights to monitor my Amazon ECS tasks and container instance?

4 minute read
0

I want to configure Amazon CloudWatch Container Insights to monitor my Amazon Elastic Container Service (Amazon ECS) tasks and container instance.

Resolution

Note: If you receive errors when you run AWS Command Line Interface (AWS CLI) commands, then see Troubleshooting errors for the AWS CLI. Also, make sure that you're using the most recent AWS CLI version.

Container Insights aggregates cluster and service metrics. It's a best practice to use Container Insights with enhanced observability to get more detailed health and performance metrics for tasks and container instances. You can activate Container Insights and Container Insights with enhanced observability for the entire AWS account or for specific clusters.

Activate Container Insights at the account level

Note: When you activate Container Insights at the account level, you save time because all new clusters automatically have Container Insights activated.

Use the Amazon ECS console or the AWS CLI to activate Container Insights or activate Container Insights with enhanced observability. Note that you can activate Container Insights in the default AWS account settings for individual AWS Identity and Access Management (IAM) users. To do this, you must log in as the root user account.

To modify the account settings for all users, run the following put-account-setting-default:

aws ecs put-account-setting-default --name containerInsights --value enabled --region REGION_NAME

Note: Replace REGION_NAME with your AWS Region. Changes that you make with AWS CLI commands apply to the entire account unless an IAM user or role explicitly overrides these settings. To deactivate the default account setting for all IAM users or roles on your account, replace enabled with disabled. If the cluster has CloudWatch Application Insights activated, then you must delete it or deactivate monitoring for an application component when you deactivate Container Insights.

Activate Container Insights at the cluster level

To use the Amazon ECS console to create a new cluster with Container Insights activated, complete the following steps:

  1. Open the Amazon ECS console.
  2. In the navigation bar, select your AWS Region, and then choose Clusters.
  3. Choose Create cluster.
  4. Configure your cluster settings.
  5. Expand Monitoring, and then select Use Container Insights or Container Insights with enhanced observability
  6. Choose Create.

To use the AWS CLI to create a new cluster with Container Insights activated, run the following create-cluster command:

aws ecs create-cluster --cluster-name CLUSTER_NAME --settings name=containerInsights,value=enabled --region REGION_NAME

Note: Replace CLUSTER_NAME with your cluster name and REGION_NAME with your Region. To activate enhanced observability, replace value=enabled with value=enhanced.

Use the Amazon ECS console to turn on Container Insights for an existing cluster. Or, to use the AWS CLI, run the following update-cluster-settings command:

aws ecs update-cluster-settings --cluster CLUSTER_NAME --settings name=containerInsights,value=enabled --region REGION_NAME

Note: Replace CLUSTER_NAME with your cluster name and REGION_NAME with your Region. To turn off Container Insights, replace value=enabled with value=disabled. For enhanced observability, replace value=enabled with value=enhanced.

Review Container Insights options

When you use an Amazon Elastic Compute Cloud (Amazon EC2) launch type, define the CPU parameter at the task level or the container level. Then, you can view CPU usage metrics for your Amazon ECS tasks.

You can view network metrics for all tasks that run on AWS Fargate and for tasks on Amazon EC2 instances that use bridge network mode. Metrics are also available for tasks that use Amazon Virtual Private Cloud (Amazon VPC) network modes.

To collect the instance-level metrics from Amazon ECS clusters that are hosted on an EC2 instance, deploy the CloudWatch agent.

Related information

Amazon ECS Container Insights metrics

Amazon ECS Container Insights with enhanced observability metrics

Viewing Container Insights metrics

Example 12 - Container insights for Amazon ECS (with and without enhanced observability)

AWS OFFICIAL
AWS OFFICIALUpdated 2 months ago
1 Comment

Dear AWS,

I first discovered this functionality myself, an then found this article - although this is very valuable functionality, but it's completely not ready for real-world usage. Same for task level logs - click on logs tab for task in containerinsights directs to Service log group, not to container log stream as expected. I'd appreciate you implementing this as CloudWatch metrics instead of logs. At the same time implementing this as metrics would involve creating metric dimension per container that would severely impact CloudWatch usage price. So if you implement this in simple and cheap way, you could make customers, us included, to make choice of CloudWatch instead of DataDog, Dynatrace or other solutions providing container-level metrics and logs out of the box.

replied 4 months ago