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:
- Open the Amazon ECS console.
- In the navigation bar, select your AWS Region, and then choose Clusters.
- Choose Create cluster.
- Configure your cluster settings.
- Expand Monitoring, and then select Use Container Insights or Container Insights with enhanced observability
- 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)