

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

# `AWSSupport-TroubleshootCloudWatchAlarm`
<a name="automation-awssupport-troubleshoot-cloudwatchalarm"></a>

 **Description** 

 `AWSSupport-TroubleshootCloudWatchAlarm` Runbook 有助於識別和疑難排解設定錯誤或有問題的 Amazon CloudWatch (CloudWatch) 警示的問題。它利用 AWS APIs 和已知警示評估邏輯來偵測受監控指標中的延遲或遺失資料點，這可能會導致遺漏或延遲警示動作。此 Runbook 提供結構化方法來調查和解決 Amazon CloudWatch (CloudWatch) 警示相關問題。

 **如何運作？** 

 Runbook 會`AWSSupport-TroubleshootCloudWatchAlarm`執行下列步驟：
+ 驗證 Amazon CloudWatch (CloudWatch) 警示詳細資訊和 `AlarmTriggerTimestamp` 參數的值，以檢查是否在 2，592，000 秒 (30 天） 內。
+ 檢查警示是以指標或指標數學為基礎，還是異常偵測器警示。
+ 檢查警示是否處於資料不足的狀態。
+ 檢查 （警示） 中使用的 metric 是否與 `ListMetrics`值相符。
+ 驗證指標是否在指定的時間戳記遺失資料點 (s)。
+ 取得指定時間戳記的最新歷史記錄。
+ 檢查 （警示） 是否因 指標延遲或遺漏而未觸發。
+ 檢查 （警示） 已啟用的動作是否已交付。
+ 產生結合所有診斷結果的故障診斷報告。

 [執行此自動化 （主控台）](https://console.aws.amazon.com/systems-manager/automation/execute/AWSSupport-TroubleshootCloudWatchAlarm) 

**文件類型**

 自動化

**擁有者**

Amazon

**平台**

Linux、macOS、 Windows

**參數**

**必要的 IAM 許可**

`AutomationAssumeRole` 參數需要下列動作才能成功使用 Runbook。
+ `cloudwatch:DescribeAlarms`
+ `cloudwatch:DescribeAlarmHistory`
+ `cloudwatch:DescribeAnomalyDetectors`
+ `cloudwatch:GetMetricData`
+ `cloudwatch:GetMetricStatistics`
+ `cloudwatch:ListMetrics`

------
#### [ JSON ]

****  

```
{
    "Version":"2012-10-17",		 	 	 
    "Statement": [
        {
            "Sid": "",
            "Effect": "Allow",
            "Action": [
                "cloudwatch:DescribeAlarms",
                "cloudwatch:DescribeAlarmHistory",
                "cloudwatch:DescribeAnomalyDetectors",
                "cloudwatch:GetMetricData",
                "cloudwatch:GetMetricStatistics",
                "cloudwatch:ListMetrics"
            ],
            "Resource": "*"
        }
    ]
}
```

------

 **指示** 

請依照下列步驟設定自動化：

1. 在文件下的 Systems Manager [https://console.aws.amazon.com/systems-manager/documents/AWSSupport-TroubleshootCloudWatchAlarm/description](https://console.aws.amazon.com/systems-manager/documents/AWSSupport-TroubleshootCloudWatchAlarm/description)中導覽至 。

1. 選擇 Execute automation (執行自動化)。

1. 針對輸入參數，輸入下列內容：
   + **AutomationAssumeRole （選用）：**
     + 類型：`String`
     + 描述：（選用） 允許 Systems Manager Automation 代表您執行動作的 (IAM) 角色的 Amazon Resource Name AWS AWS Identity and Access Management (ARN)。如果未指定角色，Systems Manager Automation 會使用啟動此 Runbook 之使用者的許可。
   + **CloudWatchMetricAlarmName （必要）：**
     + 類型：`String`
     + 描述：（必要） 要故障診斷的 Amazon CloudWatch (CloudWatch) 指標警示名稱。
     + 允許模式： `^[a-zA-Z0-9.:;,\\-_&() ]{1,255}$`
   + **AlarmTriggerTimestamp （必要）：**
     + 類型：`String`
     + 描述：（必要） 發生警示問題的 UTC 時間戳記。此資訊對於疑難排解問題和了解問題發生的內容至關重要。時間戳記值應為從今天起算過去 30 天內的時間，格式為 `YYYY-MM-DDTHH:mm:ssZ`。範例：`2024-10-29T09:04:00Z`
     + 允許模式： `^(\\d{4})-(\\d{2})-(\\d{2})T(\\d{2}):(\\d{2}):(\\d{2})Z$`

1. 選取執行。

1. 自動化會啟動。

1. 文件會執行下列步驟：
   + **`VerifyRunbookInputs`**

     驗證 Amazon CloudWatch (CloudWatch) 警示詳細資訊和 `AlarmTriggerTimestamp` 參數的值，以檢查是否在 2，592，000 秒 (30 天） 內。
   + **`UpdateSSMDocumentInputChecksVariable`**

     `SSMDocumentInputChecks` 使用`VerifyRunbookInputs`步驟`SSMDocumentInputChecks`中的值更新變數。
   + **`BranchOnAlarmIsVerified`**

     Runbook 輸入驗證`AlarmTriggerTimestamp`和 上的分支`CloudWatchAlarmName`。
   + **`CheckMetricAlarmType`**

     檢查警示是以指標或指標數學為基礎，還是異常偵測器警示。
   + **`CheckAlarmInInsufficientDataState`**

     檢查警示是否處於資料不足的狀態。
   + **`UpdateInsufficientDataChecksVariable`**

     `InsufficientDataChecks` 使用`CheckAlarmInInsufficientDataState`步驟`InsufficientDataChecks`中的值更新變數。
   + **`BranchOnAlarmHasInsufficientData`**

     `CheckAlarmInInsufficientDataState` 步驟中`AlarmHasInsufficientData`值的分支，預設步驟為 `CheckMetricMismatch`。
   + **`CheckMetricMismatch`**

     檢查 （警示） 中使用的 metric 是否與 `ListMetrics`值相符。
   + **`UpdateMetricMismatchChecksVariable`**

     `MetricMismatchChecks` 使用`CheckMetricMismatch`步驟`MetricMismatchChecks`中的值更新變數。
   + **`BranchOnMetricsMatched`**

     `CheckMetricMismatch` 步驟中`MetricsMatched`值的分支，預設步驟為 `CheckMissingDatapoint`。
   + **`CheckMissingDatapoint`**

     驗證指標是否在指定的時間戳記遺失資料點 (s)。
   + **`UpdateMetricMissingDatapointsChecksVariable`**

     `MetricMissingDatapointsChecks` 使用`CheckMissingDatapoint`步驟`MetricMissingDatapointsChecks`中的值更新變數。
   + **`BranchOnMetricMissingDatapoint`**

     `CheckMissingDatapoint` 步驟`MetricMissingDatapoint`的值分支，預設步驟為 `GetAlarmHistoryDetails`。
   + **`GetAlarmHistoryDetails`**

     取得指定時間戳記的最新歷史記錄。
   + **`UpdateAlarmHistoryChecksVariable`**

     `AlarmHistoryChecks` 使用`GetAlarmHistoryDetails`步驟`AlarmHistoryChecks`中的值更新變數。
   + **`BranchOnAlarmHistoryFound`**

     `GetAlarmHistoryDetails` 步驟中`AlarmHistoryFound`值的分支，預設步驟為 `CheckDelayedMetric`。
   + **`CheckDelayedMetric`**

     檢查 （警示） 是否因 指標延遲或遺漏而未觸發。
   + **`UpdateDelayedMetricChecksVariable`**

     `DelayedMetricChecks` 使用`CheckDelayedMetric`步驟`DelayedMetricChecks`中的值更新變數。
   + **`BranchOnMetricDelayedAndDatapointsMeetThreshold`**

     `MetricDelayed` 和 `CheckDelayedMetric` 步驟`DatapointsMeetThreshold`的值上的分支，預設步驟為 `GenerateReport`。
   + **`CheckActionDelivered`**

     檢查 （警示） 已啟用的動作是否已交付。
   + **`UpdateActionDeliveredChecksVariable`**

     `ActionDeliveredChecks` 使用`CheckActionDelivered`步驟`ActionDeliveredChecks`的輸出更新變數。
   + **`GenerateReport`**

     編譯先前步驟的輸出並輸出報告。

1. 執行完成後，請檢閱輸出區段以取得執行的詳細結果：
   + **GenerateReport.Report**

     提供的 Amazon CloudWatch (CloudWatch) 指標警示的報告。

   ```
                   ------------------------------------------------------------------------------------------
                   |                     AWS CloudWatch Alarm Troubleshooting Results                       |
                   ------------------------------------------------------------------------------------------
                   |     Alarm Name                        -               Demo-Alarm                       |
                   |     Timestamp                         -               2025-03-04T06:31:00Z             |
                   ------------------------------------------------------------------------------------------
                   |     ✅ No Issue(s) Found                                                               |
                   ------------------------------------------------------------------------------------------
   
   
   
                   ==========================================================================================
                   1. Validating SSM Document input parameters:
                   ==========================================================================================
                   ✅ [PASSED]: Found a metric alarm with name Demo-Alarm
   
   
                   ==========================================================================================
                   2. Checking alarm's data state:
                   ==========================================================================================
                   ✅ [PASSED]: The alarm is not in INSUFFICIENT_DATA state, alarm's state is: ALARM
   
   
                   ==========================================================================================
                   3. Checking if the alarm experienced metric mismatches:
                   ==========================================================================================
                   ✅ [PASSED]: Metric matches with the configured metric for Alarm.
   
   
                   ==========================================================================================
                   4. Checking if the alarm's metric(s) experienced missing datapoint(s):
                   ==========================================================================================
                   ✅ [PASSED]: Metric has datapoints
   
   
                   ==========================================================================================
                   5. Retrieving alarm's history for timestamp 2025-03-04T06:31:00Z:
                   ==========================================================================================
                   ✅ [PASSED]: Found most recent alarm history item for the provided timestamp: '2025-03-04T06:31:00Z'
   
   
                   ==========================================================================================
                   6. Checking if the alarm experienced metric delays or the alarm's datapoint(s) did not meet the configured threshold:
                   ==========================================================================================
                   ✅ [PASSED]: CloudWatch alarm did not experience any delayed metric
   
   
                   ==========================================================================================
                   7. Checking if the alarm has actions enabled and if action(s) were delivered:
                   ==========================================================================================
                   ✅ [PASSED]: Successfully executed action arn:aws:sns:us-east-1:12345678910:Demo_Alarms_Topic
   
   
                   ------------------------------------------------------------------------------------------
   
                   ✅ All the checks have passed for CloudWatch alarm, Demo-Alarm, the alarm's configuration is correct.
   ```

 **參考** 

Systems Manager Automation
+ [執行此自動化 （主控台）](https://console.aws.amazon.com/systems-manager/documents/AWSSupport-TroubleshootCloudWatchAlarm/description)
+ [執行自動化](https://docs.aws.amazon.com//systems-manager/latest/userguide/automation-working-executing.html)
+ [設定 自動化](https://docs.aws.amazon.com//systems-manager/latest/userguide/automation-setup.html)
+ [支援自動化工作流程登陸頁面](https://aws.amazon.com/premiumsupport/technology/saw/)