

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

# 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 Logs 的日誌](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)。
  + 新增`account_id`欄位的 `action-error`和 `target-resolution-detail`事件類型。
+ 第 1 版是初始版本。

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

AWS FIS 支援將日誌交付至下列目的地：
+ Amazon S3 儲存貯體
+ Amazon CloudWatch Logs 日誌群組

**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 Logs 日誌交付**  
日誌會交付至名為 /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)<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`事件的範例記錄。

```
{
    "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. 在 https：//[https://console.aws.amazon.com/fis/](https://console.aws.amazon.com/fis/) 開啟 AWS FIS 主控台。

1. 在導覽窗格中，選擇**實驗範本**。

1. 選取實驗範本，然後選擇**動作**、**更新實驗範本**。

1. 對於**日誌**，設定目的地選項。若要將日誌傳送至 S3 儲存貯體，請選擇**傳送至 Amazon S3 儲存貯體**，然後輸入儲存貯體名稱和字首。若要將日誌傳送至 CloudWatch Logs，請選擇**傳送至 CloudWatch Logs**，然後輸入日誌群組。

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. 在 https：//[https://console.aws.amazon.com/fis/](https://console.aws.amazon.com/fis/) 開啟 AWS FIS 主控台。

1. 在導覽窗格中，選擇**實驗範本**。

1. 選取實驗範本，然後選擇**動作**、**更新實驗範本**。

1. 對於**日誌**，清除**傳送至 Amazon S3 儲存貯體**和**傳送至 CloudWatch Logs**。

1. 選擇**更新實驗範本**。

**使用 停用實驗記錄 AWS CLI**  
使用 [update-experiment-template](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/fis/update-experiment-template.html) 命令並指定空白日誌組態。