

本文属于机器翻译版本。若本译文内容与英语原文存在差异，则一律以英文原文为准。

# Amazon ECS 集群的运行时覆盖率和故障排除
<a name="gdu-assess-coverage-ecs"></a>

Amazon ECS 集群的运行时间覆盖范围包括在 Amazon ECS 容器实例上 AWS Fargate 运行的任务[1](#ecs-container-instance)。

对于在 Fargate 上运行的 Amazon ECS 集群，运行时间覆盖率是在任务级别评估的。ECS 集群运行时覆盖率包括在您为 Fargate（仅限 ECS）启用了运行时监控和自动代理配置后开始运行的 Fargate 任务。默认情况下，Fargate 任务是不可变的。 GuardDuty 将无法安装安全代理来监视已在运行的任务上的容器。要包含此类 Fargate 任务，必须停止并重新启动该任务。务必要检查相关服务是否受支持。

有关 Amazon ECS 容器的信息，请参阅[容量创建](https://docs.aws.amazon.com/AmazonECS/latest/developerguide/create-capacity.html)。

**Topics**
+ [查看覆盖率统计数据](#ecs-review-coverage-statistics-ecs-runtime-monitoring)
+ [保险状态会随着 EventBridge 通知而发生变化](#ecs-runtime-monitoring-coverage-status-change)
+ [对 Amazon ECS-Fargate 运行时覆盖率问题进行故障排除](#ecs-runtime-monitoring-coverage-issues-troubleshoot)

## 查看覆盖率统计数据
<a name="ecs-review-coverage-statistics-ecs-runtime-monitoring"></a>

对于与您自己的账户或成员账户关联的 Amazon ECS 资源，覆盖率统计数据是选定 AWS 区域中正常 Amazon ECS 集群占所有 Amazon ECS 集群的百分比。这包括与 Fargate 和 Amazon EC2 实例关联的 Amazon ECS 集群的覆盖率。下式将其表示为：

*（健康 clusters/All 集群）\$1100*

### 注意事项
<a name="considerations-ecs-coverage-review-stats"></a>
+ ECS 集群的覆盖率统计数据包括与该 ECS 集群关联的 Fargate 任务或 ECS 容器实例的覆盖率状态。Fargate 任务的覆盖率状态包括处于正在运行状态或最近完成运行的任务。
+ 在 **ECS 集群运行时覆盖率**选项卡中，**覆盖的容器实例**字段指示与 Amazon ECS 集群关联的容器实例的覆盖率状态。

  如果 Amazon ECS 集群仅包含 Fargate 任务，则计数将显示为 **0/0**。
+ 如果 Amazon ECS 集群与没有安全代理的 Amazon EC2 实例相关联，则 Amazon ECS 集群的覆盖率状态也将为**不正常**。

  要确定关联的 Amazon EC2 实例的覆盖率问题并进行故障排除，请参阅适用于 Amazon EC2 实例的[对 Amazon EC2 运行时覆盖率问题进行故障排除](gdu-assess-coverage-ec2.md#ec2-runtime-monitoring-coverage-issues-troubleshoot)。

选择一种访问方法来查看您账户的覆盖率统计数据。

------
#### [ Console ]
+ 登录 AWS 管理控制台 并打开 GuardDuty 控制台，网址为[https://console.aws.amazon.com/guardduty/](https://console.aws.amazon.com/guardduty/)。
+ 在导航窗格中，选择**运行时监控**。
+ 选择**运行时覆盖率**选项卡。
+ 您可以在 **ECS 集群运行时覆盖率**选项卡下查看覆盖率统计数据，按**集群列表**中可用的每个 Amazon ECS 集群的覆盖率状态汇总。
  + 您可以按以下列筛选**集群列表**：
    + **账户 ID**
    + **集群名称**
    + **代理管理类型**
    + **覆盖状态**
+ 如果任何 Amazon ECS 集群的**覆盖率状态**为**不正常**，则**问题**列可能包含有关**不正常**状态原因的其他信息。

  如果 Amazon ECS 集群与 Amazon EC2 实例关联，请导航到 **EC2 实例运行时覆盖率**选项卡，然后按**集群名称**字段筛选以查看相关的**问题**。

------
#### [ API/CLI ]
+ 使用您自己的有效检测器 ID、当前区域和服务端点运行 [ListCoverage](https://docs.aws.amazon.com/guardduty/latest/APIReference/API_ListCoverage.html)API。您可以使用此 API 对实例列表进行筛选和排序。
  + 您可以使用以下 `CriterionKey` 选项之一更改示例 `filter-criteria`：
    + `ACCOUNT_ID`
    + `ECS_CLUSTER_NAME`
    + `COVERAGE_STATUS`
    + `MANAGEMENT_TYPE`
  + 您可以使用以下选项更改 `sort-criteria` 中的示例 `AttributeName`：
    + `ACCOUNT_ID`
    + `COVERAGE_STATUS`
    + `ISSUE`
    + `ECS_CLUSTER_NAME`
    + `UPDATED_AT`

      只有在关联的 Amazon ECS 集群中创建了新任务或相应的覆盖率状态发生变化时，该字段才会更新。
  + 您可以更改*max-results*（最多 50 个）。
  + 要查找您的账户和当前区域的，请查看[https://console.aws.amazon.com/guardduty/](https://console.aws.amazon.com/guardduty/)控制台中的 **“设置**” 页面，或者运行 [https://docs.aws.amazon.com/guardduty/latest/APIReference/API_ListDetectors.html](https://docs.aws.amazon.com/guardduty/latest/APIReference/API_ListDetectors.html)API。`detectorId`

  ```
  aws guardduty --region us-east-1 list-coverage --detector-id 12abc34d567e8fa901bc2d34e56789f0 --sort-criteria '{"AttributeName": "ECS_CLUSTER_NAME", "OrderBy": "DESC"}' --filter-criteria '{"FilterCriterion":[{"CriterionKey":"ACCOUNT_ID", "FilterCondition":{"EqualsValue":"111122223333"}}] }'  --max-results 5
  ```
+ 运行 [GetCoverageStatistics](https://docs.aws.amazon.com/guardduty/latest/APIReference/API_GetCoverageStatistics.html)API 以检索基于的覆盖率汇总统计信息`statisticsType`。
  + 您可以使用以下选项之一更改示例 `statisticsType`：
    + `COUNT_BY_COVERAGE_STATUS`：表示按覆盖率状态汇总的 ECS 集群的覆盖率统计数据。
    + `COUNT_BY_RESOURCE_TYPE`— 根据列表中的 AWS 资源类型汇总的覆盖率统计信息。
    + 您可以在命令中更改示例 `filter-criteria`。您可以对 `CriterionKey` 使用以下选项：
      + `ACCOUNT_ID`
      + `ECS_CLUSTER_NAME`
      + `COVERAGE_STATUS`
      + `MANAGEMENT_TYPE`
      + `INSTANCE_ID`
  + 要查找您的账户和当前区域的，请查看[https://console.aws.amazon.com/guardduty/](https://console.aws.amazon.com/guardduty/)控制台中的 **“设置**” 页面，或者运行 [https://docs.aws.amazon.com/guardduty/latest/APIReference/API_ListDetectors.html](https://docs.aws.amazon.com/guardduty/latest/APIReference/API_ListDetectors.html)API。`detectorId`

  ```
  aws guardduty --region us-east-1 get-coverage-statistics --detector-id 12abc34d567e8fa901bc2d34e56789f0 --statistics-type COUNT_BY_COVERAGE_STATUS --filter-criteria '{"FilterCriterion":[{"CriterionKey":"ACCOUNT_ID", "FilterCondition":{"EqualsValue":"123456789012"}}] }'
  ```

------

有关覆盖率问题的更多信息，请参阅[对 Amazon ECS-Fargate 运行时覆盖率问题进行故障排除](#ecs-runtime-monitoring-coverage-issues-troubleshoot)。

## 保险状态会随着 EventBridge 通知而发生变化
<a name="ecs-runtime-monitoring-coverage-status-change"></a>

Amazon ECS 集群的覆盖率状态可能显示为**不正常**。要检测覆盖率状态何时变为不正常，我们建议您定期监控覆盖率状态，并在状态变为**不正常**时进行故障排除。**或者，您可以创建 Amazon EventBridge 规则，以便在保险状态从 “**不健康” 变为 “健康**” 或其他情况时收到通知。**默认情况下，会在[EventBridge 公交车](https://docs.aws.amazon.com/eventbridge/latest/userguide/eb-event-bus.html)上为您的账户 GuardDuty 发布此内容。

### 示例通知架构
<a name="ecs-gdu-coverage-status-eventbridge-schema"></a>

在 EventBridge 规则中，您可以使用预定义的示例事件和事件模式来接收覆盖状态通知。有关创建 EventBridge 规则的更多信息，请参阅 *Amazon EventBridge 用户指南*中的[创建规则](https://docs.aws.amazon.com/eventbridge/latest/userguide/eb-get-started.html#eb-gs-create-rule)。

此外，您还可以使用以下示例通知架构来创建自定义事件模式。确保替换账户的值。要在您的 Amazon ECS 集群的覆盖状态从变`Healthy`为时收到通知`Unhealthy`，`detail-type`应该是*GuardDuty Runtime Protection Unhealthy*。要在保险状态从变为时收到通知`Healthy`，`Unhealthy`请将的`detail-type`值替换为*GuardDuty Runtime Protection Healthy*。

```
{
  "version": "0",
  "id": "event ID",
  "detail-type": "GuardDuty Runtime Protection Unhealthy",
  "source": "aws.guardduty",
  "account": "AWS 账户 ID",
  "time": "event timestamp (string)",
  "region": "AWS 区域",
  "resources": [
       ],
  "detail": {
    "schemaVersion": "1.0",
    "resourceAccountId": "string",
    "currentStatus": "string",
    "previousStatus": "string",
    "resourceDetails": {
        "resourceType": "ECS",
        "ecsClusterDetails": {
          "clusterName":"",
          "fargateDetails":{
            "issues":[],
            "managementType":""
          },
          "containerInstanceDetails":{
            "coveredContainerInstances":int,
            "compatibleContainerInstances":int
          }
        }
    },
    "issue": "string",
    "lastUpdatedAt": "timestamp"
  }
}
```

## 对 Amazon ECS-Fargate 运行时覆盖率问题进行故障排除
<a name="ecs-runtime-monitoring-coverage-issues-troubleshoot"></a>

如果 Amazon ECS 集群的覆盖率状态为**不正常**，则可以在**问题**列下查看原因。

下表提供了 Fargate（仅限 Amazon ECS）问题的建议故障排除步骤。有关 Amazon EC2 实例覆盖率问题的信息，请参阅适用于 Amazon EC2 实例的[对 Amazon EC2 运行时覆盖率问题进行故障排除](gdu-assess-coverage-ec2.md#ec2-runtime-monitoring-coverage-issues-troubleshoot)。

[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_cn/guardduty/latest/ug/gdu-assess-coverage-ecs.html)