

本文為英文版的機器翻譯版本，如內容有任何歧義或不一致之處，概以英文版為準。

# 在 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)。

------