

# 在 Amazon ECS 上设置 Container Insights
<a name="deploy-container-insights-ECS-cluster"></a>

可以使用 Amazon ECS 控制台或 AWS CLI 在新的和现有的 Amazon ECS 集群上设置具有增强型可观测性的 Container Insights 或 Container Insights。Container Insights 在集群、任务和服务级别收集指标。具有增强型可观测性的 Container Insights 可提供其他维度和指标，以便深入了解容器级别的可见性。

如果在 Amazon EC2 实例上使用 Amazon ECS，则必须使用包含 Amazon ECS 代理版本 1.29 或更高版本的 AMI 启动该实例。有关更新代理版本的信息，请参阅[更新 Amazon ECS 容器代理](https://docs.aws.amazon.com/AmazonECS/latest/developerguide/ecs-agent-update.html)。

**注意**  
如果用于 Amazon ECS Container Insights 指标的客户自主管理型 AWS KMS 密钥尚未配置为与 CloudWatch 配合使用，则必须更新密钥政策，以便允许在 CloudWatch Logs 中使用加密日志。您还必须将自己的 AWS KMS 密钥与 `/aws/ecs/containerinsights/ClusterName/performance` 中的日志组相关联。有关更多信息，请参阅[使用 AWS Key Management Service 对 CloudWatch Logs 中的日志数据进行加密](https://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/encrypt-log-data-kms.html)。

我们建议您使用具有增强型可观测性的 Container Insights，而不是 Container Insights，因为前者可以在容器环境中提供详细的可见性，从而缩短解决问题的平均时间。

## 设置具有增强型可观测性的 Container Insights
<a name="set-container-insights-ECS-cluster-enhanced"></a>

可以使用 Amazon ECS 控制台或 AWS CLI 启用具有增强型可观测性的 Container Insights。

------
#### [ AWS CLI ]

使用以下命令启用具有增强型可观测性的 Container Insights。

 将 `containerInsights` 账户设置设置为 `enhanced`

```
aws ecs put-account-setting --name containerInsights --value enhanced
```

 输出示例

```
{
    "setting": {
        "name": "containerInsights",
        "value": "enhanced",
        "principalArn": "arn:aws:iam::123456789012:johndoe",
         "type": user
    }
}
```

**注意**  
默认情况下，仅 `put-account-setting` 适用于当前已经过身份验证的用户。要为所有用户和角色启用账户范围的设置，请使用根用户，如以下示例所示。  

```
aws ecs put-account-setting --name containerInsights --value enhanced --principal-arn arn:aws:iam::accountID:root
```

设置此账户设置后，所有新集群都会自动使用具有增强型可观测性的 Container Insights。使用 `update-cluster-settings` 命令将具有增强型可观测性的 Container Insights 添加到现有集群，或者将当前使用 Container Insights 的集群升级为具有增强型可观测性的 Container Insights。

```
aws ecs update-cluster-settings --cluster cluster-name --settings name=containerInsights,value=enhanced
```

------
#### [ Amazon ECS console ]

1. 在 [https://console.aws.amazon.com/ecs/v2](https://console.aws.amazon.com/ecs/v2) 打开控制台。

1. 在顶部的导航栏中，选择要查看其账户设置的区域。

1. 在导航页面中，选择 **Account Settings**（账户设置）。

1. 选择**更新**。

1. 要使用具有增强型可观测性的 Container Insights，请选择**具有增强型可观测性的 Container Insights**。

1. 选择**保存更改**。

1. 在确认屏幕上，选择**确认**以保存选择。

进行此设置后，所有新集群都会自动使用具有增强型可观测性的 Container Insights。可以将具有增强型可观测性的 Container Insights 添加到现有集群，或者将当前使用 Container Insights 的集群升级为具有增强型可观测性的 Container Insights。有关更多信息，请参阅《Amazon Elastic Container Service 开发人员指南》中的[更新 Amazon ECS 集群](https://docs.aws.amazon.com/AmazonECS/latest/developerguide/update-cluster-v2.html)。**

------

## 设置 Container Insights
<a name="set-container-insights-ECS-cluster"></a>

可以使用 Amazon ECS 控制台或 AWS CLI 启用 Container Insights。

------
#### [ AWS CLI ]

要使用 Container Insights，请将 `container Insights` 账户设置设置为 `enabled`。使用以下命令启用 Container Insights。

```
aws ecs put-account-setting --name containerInsights --value enabled
```

 输出示例

```
{
    "setting": {
        "name": "container Insights",
        "value": "enabled",
        "principalArn": "arn:aws:iam::123456789012:johndoe",
         "type": user
    }
}
```

将 `container Insights` 账户设置设为 `enabled` 时，默认情况下，所有新集群都会启用 Container Insights。使用 `update-cluster-settings` 命令将 Container Insights 添加到现有集群。

```
aws ecs update-cluster-settings --cluster cluster-name --settings name=containerInsights,value=enabled
```

------
#### [ Amazon ECS console ]

1. 在 [https://console.aws.amazon.com/ecs/v2](https://console.aws.amazon.com/ecs/v2) 打开控制台。

1. 在顶部的导航栏中，选择要查看其账户设置的区域。

1. 在导航页面中，选择 **Account Settings**（账户设置）。

1. 选择**更新**。

1. 要使用 Container Insights，请选择 **Container Insights**。

1. 选择**保存更改**。

1. 在确认屏幕上，选择**确认**以保存选择。

进行此设置后，所有新集群都会自动使用 Container Insights。更新现有集群来添加 Container Insights。有关更多信息，请参阅《Amazon Elastic Container Service 开发人员指南》中的[更新 Amazon ECS 集群](https://docs.aws.amazon.com/AmazonECS/latest/developerguide/update-cluster-v2.html)。**

------