

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

# Amazon EC2 实例的运行时覆盖率和故障排除
<a name="gdu-assess-coverage-ec2"></a>

对于 Amazon EC2 资源，运行时间覆盖率是在实例级别评估的。Amazon EC2 实例可能会在您的 AWS 环境中运行多种类型的应用程序和工作负载等等。此功能还支持由 Amazon ECS 托管的 Amazon EC2 实例，并且如果您在 Amazon EC2 实例上运行 Amazon ECS 集群，则实例级别的覆盖率问题将在 Amazon EC2 运行时覆盖率下显示。

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

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

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

*（ instances/All 运行正常的实例）\$1100*

如果您还为 Amazon ECS 集群部署了 GuardDuty 安全代理，则与在 Amazon EC2 实例上运行的 Amazon ECS 集群相关的任何实例级别覆盖问题都将显示为 Amazon EC2 实例运行时覆盖率问题。

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

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

------
#### [ API/CLI ]
+ 使用您自己的有效检测器 ID、当前区域和服务端点运行 [ListCoverage](https://docs.aws.amazon.com/guardduty/latest/APIReference/API_ListCoverage.html)API。您可以使用此 API 对实例列表进行筛选和排序。
  + 您可以使用以下 `CriterionKey` 选项之一更改示例 `filter-criteria`：
    + `ACCOUNT_ID`
    + `RESOURCE_TYPE`
    + `COVERAGE_STATUS`
    + `AGENT_VERSION`
    + `MANAGEMENT_TYPE`
    + `INSTANCE_ID`
    + `CLUSTER_ARN`
  + 当 `filter-criteria` 包含 `RESOURCE_TYPE` 为 **EC2** 的条件时，运行时监控将不支持将 **ISSUE** 作为 `AttributeName`。如果您使用该属性，API 响应将导致 `InvalidInputException`。

    您可以使用以下选项更改 `sort-criteria` 中的示例 `AttributeName`：
    + `ACCOUNT_ID`
    + `COVERAGE_STATUS`
    + `INSTANCE_ID`
    + `UPDATED_AT`
  + 您可以更改*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": "EKS_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`：表示按覆盖状态汇总的 EKS 集群的覆盖率统计数据。
    + `COUNT_BY_RESOURCE_TYPE`— 根据列表中的 AWS 资源类型汇总的覆盖率统计信息。
    + 您可以在命令中更改示例 `filter-criteria`。您可以对 `CriterionKey` 使用以下选项：
      + `ACCOUNT_ID`
      + `RESOURCE_TYPE`
      + `COVERAGE_STATUS`
      + `AGENT_VERSION`
      + `MANAGEMENT_TYPE`
      + `INSTANCE_ID`
      + `CLUSTER_ARN`
  + 要查找您的账户和当前区域的，请查看[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"}}] }'
  ```

------

如果 EC2 实例的覆盖率状态为**不正常**，请参阅[对 Amazon EC2 运行时覆盖率问题进行故障排除](#ec2-runtime-monitoring-coverage-issues-troubleshoot)。

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

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

### 示例通知架构
<a name="ec2-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 EC2 实例的覆盖状态从变`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": "EC2",
        "ec2InstanceDetails": {
          "instanceId":"",
          "instanceType":"",
          "clusterArn": "",
          "agentDetails": {
            "version":""
          },
          "managementType":""
        }
    },
    "issue": "string",
    "lastUpdatedAt": "timestamp"
  }
}
```

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

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

如果 EC2 实例与某个 EKS 集群关联，并且手动或通过自动代理配置安装了 EKS 安全代理，则要对覆盖率问题进行故障排除，请参阅[Amazon EKS 集群的运行时覆盖率和故障排除](eks-runtime-monitoring-coverage.md)。

下表列举了问题类型和相应的故障排除步骤。

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