

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

# AWS FIS 的实验日志
<a name="monitoring-logging"></a>

您可以使用实验日志记录，以便在实验运行时捕获有关详细信息。

您需要根据与每种日志目的地类型关联的成本付费使用实验日志记录。有关更多信息，请参阅 [Amazon CloudWatch 定价](https://aws.amazon.com/cloudwatch/pricing/)（在 “**付费套餐**、**日志**、**销售日志**” 下）和 [Amazon S3 定价](https://aws.amazon.com/s3/pricing/)。

## 权限
<a name="permissions-experiment-logging"></a>

您必须授予 AWS FIS 权限才能将日志发送到您配置的每个日志目标。有关更多信息，请参阅 *Amazon CloudWatch Logs 用户指南*中的以下内容：
+ [发送到日志的 CloudWatch 日志](https://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/AWS-logs-and-resource-policy.html#AWS-logs-infrastructure-CWL)
+ [发送到 Amazon S3 的日志](https://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/AWS-logs-and-resource-policy.html#AWS-logs-infrastructure-S3)

## 日志架构
<a name="experiment-log-schema"></a>

实验日志记录使用以下架构。当前架构采用版本 2。用于 `details` 的字段取决于 `log_type` 值。用于 `resolved_targets` 的字段取决于 `target_type` 值。有关更多信息，请参阅 [日志记录示例](#example-log-records)。

```
{
    "id": "EXP123abc456def789",
    "log_type": "experiment-start | target-resolution-start | target-resolution-detail | target-resolution-end | action-start | action-error | action-end | experiment-end",
    "event_timestamp": "yyyy-mm-ddThh:mm:ssZ",
    "version": "2",
    "details": {
        "account_id":"123456789012",
        "action_end_time": "yyyy-mm-ddThh:mm:ssZ",
        "action_id": "String",
        "action_name": "String",
        "action_start_time": "yyyy-mm-ddThh:mm:ssZ",
        "action_state": {
            "status": "pending | initiating | running | completed | cancelled | stopping | stopped | failed",
            "reason": "String"
        },
        "action_targets": "String to string map",
        "error_information": "String",
        "experiment_end_time": "yyyy-mm-ddThh:mm:ssZ",
        "experiment_state": {
            "status": "pending | initiating | running | completed | stopping | stopped | failed",
            "reason": "String"
        },
        "experiment_start_time": "yyyy-mm-ddThh:mm:ssZ",
        "experiment_template_id": "String",
        "page": Number,
        "parameters": "String to string map",
        "resolved_targets": [
            {
               "field": "value"
            }
        ],
        "resolved_targets_count": Number,
        "status": "failed | completed",
        "target_name": "String",
        "target_resolution_end_time": "yyyy-mm-ddThh:mm:ssZ",
        "target_resolution_start_time": "yyyy-mm-ddThh:mm:ssZ",
        "target_type": "String",
        "total_pages": Number,
        "total_resolved_targets_count": Number

    }
}
```

**发行说明**
+ 版本 2 引入了：
  + `target_type`字段和将`resolved_targets`字段从对象列表更改 ARNs 为对象列表。`resolved_targets` 对象的有效字段取决于 `target_type` 值，即目标的[资源类型](targets.md#resource-types)。
  + `action-error` 和 `target-resolution-detail` 事件类型（添加了 `account_id` 字段）。
+ 初始版本为版本 1。

## 日志目的地
<a name="experiment-log-destinations"></a>

AWS FIS 支持将日志传送到以下目的地：
+ 一个 Amazon S3 存储桶
+ Amazon CloudWatch 日志组

**S3 日志传输**  
这些日志会传输到以下位置。

```
bucket-and-optional-prefix/AWSLogs/account-id/fis/region/experiment-id/YYYY/MM/DD/account-id_awsfislogs_region_experiment-id_YYYYMMDDHHMMZ_hash.log
```

日志会在几分钟后传输到存储桶。

**CloudWatch 日志日志传输**  
日志将传送到日志流named /aws/fis/*experiment-id*。

日志会在一分钟以内传输到日志组。

## 日志记录示例
<a name="example-log-records"></a>

以下是在随机选择的 EC2 实例上运行**aws:ec2:reboot-instances**操作的实验日志记录示例。

**记录**
+ [experiment-start](#experiment-start)
+ [target-resolution-start](#target-resolution-start)
+ [target-resolution-detail](#target-resolution-detail)
+ [target-resolution-end](#target-resolution-end)
+ [action-start](#action-start)
+ [action-end](#action-end)
+ [action-error](#action-error)
+ [experiment-end](#experiment-end)<a name="experiment-start"></a>

**experiment-start**  
以下是 `experiment-start` 事件的示例记录。

```
{
    "id": "EXPhjAXCGY78HV2a4A",
    "log_type": "experiment-start",
    "event_timestamp": "2023-05-31T18:50:45Z",
    "version": "2",
    "details": {
        "experiment_template_id": "EXTCDh1M8HHkhxoaQ",
        "experiment_start_time": "2023-05-31T18:50:43Z"
    }
}
```<a name="target-resolution-start"></a>

**target-resolution-start**  
以下是 `target-resolution-start` 事件的示例记录。

```
{
    "id": "EXPhjAXCGY78HV2a4A",
    "log_type": "target-resolution-start",
    "event_timestamp": "2023-05-31T18:50:45Z",
    "version": "2",
    "details": {
        "target_resolution_start_time": "2023-05-31T18:50:45Z",
        "target_name": "EC2InstancesToReboot"
    }
}
```<a name="target-resolution-detail"></a>

**target-resolution-detail**  
以下是 `target-resolution-detail` 事件的示例记录。如果目标分辨率失败，则记录中还有 `error_information` 字段。

```
{
    "id": "EXPhjAXCGY78HV2a4A",
    "log_type": "target-resolution-detail",
    "event_timestamp": "2023-05-31T18:50:45Z",
    "version": "2",
    "details": {
        "target_resolution_end_time": "2023-05-31T18:50:45Z",
        "target_name": "EC2InstancesToReboot",
        "target_type": "aws:ec2:instance",
        "account_id": "123456789012",
        "resolved_targets_count": 2,
        "status": "completed"

    }
}
```<a name="target-resolution-end"></a>

**target-resolution-end**  
如果目标分辨率失败，则记录中还有 `error_information` 字段。如果 `total_pages` 大于 1，则表示已解析目标的数量超出一条记录的大小限制。还有其他包含剩余已解决目标的 `target-resolution-end` 记录。

以下是 EC2 操作`target-resolution-end`事件的示例记录。

```
{
    "id": "EXPhjAXCGY78HV2a4A",
    "log_type": "target-resolution-end",
    "event_timestamp": "2023-05-31T18:50:45Z",
    "version": "2",
    "details": {
        "target_resolution_end_time": "2023-05-31T18:50:46Z",
        "target_name": "EC2InstanceToReboot",
        "target_type": "aws:ec2:instance",
        "resolved_targets": [
            {
                "arn": "arn:aws:ec2:us-east-1:123456789012:instance/i-0f7ee2abffc330de5"
            }
        ],
        "page": 1,
        "total_pages": 1
    }
}
```

以下是 EKS 操作 `target-resolution-end` 事件的示例记录。

```
{
    "id": "EXP24YfiucfyVPJpEJn",
    "log_type": "target-resolution-end",
    "event_timestamp": "2023-05-31T18:50:45Z",
    "version": "2",
    "details": {
        "target_resolution_end_time": "2023-05-31T18:50:46Z",
        "target_name": "myPods",
        "target_type": "aws:eks:pod",
        "resolved_targets": [
            {
                "pod_name": "example-696fb6498b-sxhw5",
                "namespace": "default",
                "cluster_arn": "arn:aws:eks:us-east-1:123456789012:cluster/fis-demo-cluster",
                "target_container_name": "example"
            }
        ],
        "page": 1,
        "total_pages": 1
    }
}
```<a name="action-start"></a>

**action-start**  
以下是 `action-start` 事件的示例记录。如果实验模板指定了操作参数，则记录中还有 `parameters` 字段。

```
{
    "id": "EXPhjAXCGY78HV2a4A",
    "log_type": "action-start",
    "event_timestamp": "2023-05-31T18:50:56Z",
    "version": "2",
    "details": {
        "action_name": "Reboot",
        "action_id": "aws:ec2:reboot-instances",
        "action_start_time": "2023-05-31T18:50:56Z",
        "action_targets": {"Instances":"EC2InstancesToReboot"}
    }
}
```<a name="action-error"></a>

**action-error**  
以下是 `action-error` 事件的示例记录。只有操作失败时才会返回该事件。操作失败的每个账户都会返回该事件。

```
{
    "id": "EXPhjAXCGY78HV2a4A",
    "log_type": "action-error",
    "event_timestamp": "2023-05-31T18:50:56Z",
    "version": "2",
    "details": {
        "action_name": "pause-io",
        "action_id": "aws:ebs:pause-volume-io",
        "account_id": "123456789012",
        "action_state": {
            "status": "failed",
            "reason":"Unable to start Pause Volume IO. Target volumes must be attached to an instance type based on the Nitro system. VolumeId(s): [vol-1234567890abcdef0]:"
        }
    }
}
```<a name="action-end"></a>

**action-end**  
以下是 `action-end` 事件的示例记录。

```
{
    "id": "EXPhjAXCGY78HV2a4A",
    "log_type": "action-end",
    "event_timestamp": "2023-05-31T18:50:56Z",
    "version": "2",
    "details": {
        "action_name": "Reboot",
        "action_id": "aws:ec2:reboot-instances",
        "action_end_time": "2023-05-31T18:50:56Z",
        "action_state": {
            "status": "completed",
            "reason": "Action was completed."
        }
    }
}
```<a name="experiment-end"></a>

**experiment-end**  
以下是 `experiment-end` 事件的示例记录。

```
{
    "id": "EXPhjAXCGY78HV2a4A",
    "log_type": "experiment-end",
    "event_timestamp": "2023-05-31T18:50:57Z",
    "version": "2",
    "details": {
        "experiment_end_time": "2023-05-31T18:50:57Z",
        "experiment_state": {
            "status": "completed",
            "reason": "Experiment completed"
        }
    }
}
```

## 启用实验日志记录
<a name="enable-experiment-logging"></a>

默认禁用实验日志记录。要接收实验日志记录，您必须通过启用了日志记录的实验模板来创建实验。如果某个实验配置为使用一个以前未用于日志记录的目的地，则当您首次运行该实验时，我们会将此实验延迟约 15 秒，以便将日志配置为传输到此目的地。

**使用控制台启用实验日志记录**

1. 打开 AWS FIS 控制台，网址[https://console.aws.amazon.com/fis/](https://console.aws.amazon.com/fis/)为。

1. 在导航窗格中，选择**实验模板**。

1. 选择实验模板，然后依次选择**操作**和**更新实验模板**。

1. 对于**日志**，配置目的地选项。要向 S3 存储桶发送日志，请选择**发送到 Amazon S3 存储桶**，然后输入存储桶名称和前缀。要将日志发送到 CloudWatch 日志，请选择**发送到 CloudWatch 日志**并输入日志组。

1. 选择**更新实验模板**。

**要启用实验记录，请使用 AWS CLI**  
使用[update-experiment-template](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/fis/update-experiment-template.html)命令并指定日志配置。

## 禁用实验日志记录
<a name="disable-experiment-logging"></a>

如果不想再接收实验日志，则可以禁用实验日志记录。

**使用控制台禁用实验日志记录**

1. 打开 AWS FIS 控制台，网址[https://console.aws.amazon.com/fis/](https://console.aws.amazon.com/fis/)为。

1. 在导航窗格中，选择**实验模板**。

1. 选择实验模板，然后依次选择**操作**和**更新实验模板**。

1. 对于**日志**，清除 “**发送到 Amazon S3 存储桶**” 和 “**发送到 CloudWatch 日志**”。

1. 选择**更新实验模板**。

**要禁用实验记录，请使用 AWS CLI**  
使用[update-experiment-template](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/fis/update-experiment-template.html)命令并指定空日志配置。