

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

# `AWSSupport-TroubleshootWindowsPerformance`
<a name="awssupport-troubleshoot-windows-performance"></a>

 **Description** 

 Runbook `AWSSupport-TroubleshootWindowsPerformance`有助於疑難排解 Amazon Elastic Compute Cloud (Amazon EC2) Windows 執行個體上持續發生的效能問題。Runbook 會從目標執行個體擷取日誌，並分析 CPU、記憶體、磁碟和網路效能指標。或者，自動化可以擷取程序傾印，以協助您判斷效能降低的潛在原因。如果您允許此 Runbook 安裝事件和系統日誌，自動化也會使用最新的[https://docs.aws.amazon.com//AWSEC2/latest/WindowsGuide/Windows-Server-EC2Rescue.html](https://docs.aws.amazon.com//AWSEC2/latest/WindowsGuide/Windows-Server-EC2Rescue.html)工具來擷取事件和系統日誌。

 **如何運作？** 

 Runbook 會執行下列步驟：
+ 檢查 Amazon EC2 執行個體的先決條件。
+ 在 Amazon EC2 Windows 執行個體的根磁碟中產生效能日誌
+ 將擷取的日誌儲存在資料夾中 `C:\ProgramData\Amazon\SSM\TroubleshootWindowsPerformance`
+ 如果提供 Amazon Simple Storage Service (Amazon S3) 儲存貯體，且自動化擔任角色具有必要的許可，則擷取的日誌會上傳至 Amazon S3 儲存貯體。
+ 將最新的`EC2Rescue`工具安裝到 Amazon EC2 Windows 執行個體，以擷取您選擇安裝的事件和系統日誌，但不會分析程序傾印和 擷取的日誌`EC2Rescue`。

**重要**  
若要執行此 Runbook，Amazon EC2 Windows 執行個體必須由 管理 AWS Systems Manager。如需詳細資訊，請參閱[為什麼我的 Amazon EC2 執行個體未顯示為受管節點](https://repost.aws/knowledge-center/systems-manager-ec2-instance-not-appear)。
若要執行此 Runbook，Amazon EC2 Windows 執行個體必須使用 PowerShell 4.0 或更新版本在 Windows 8.1 / Windows Server 2012 R2 (6.3) 或更新版本上執行。如需詳細資訊，請參閱 [Windows 作業系統版本](https://learn.microsoft.com/en-us/windows/win32/sysinfo/operating-system-version)。
對於產生效能日誌，根裝置上需要至少 10 GB 的可用空間。如果根磁碟大於 100 GB，則可用空間必須大於磁碟大小的 10%。如果您在執行期間傾印程序，可用空間必須大於 10 GB，加上程序耗用超過 10 GB 記憶體時程序耗用的總記憶體大小。
在根裝置上產生的日誌不會自動刪除。
Runbook 不會解除安裝`EC2Rescue`工具。如需詳細資訊，請參閱[`EC2Rescue`使用 Windows Server](https://docs.aws.amazon.com//AWSEC2/latest/WindowsGuide/Windows-Server-EC2Rescue.html)。
最佳實務是在效能影響期間執行此自動化。您也可以使用 AWS Systems Manager State Manager 關聯或排程 AWS Systems Manager 維護 Windows 定期執行。

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

**文件類型**

 自動化

**擁有者**

Amazon

**平台**

Windows

**參數**

**必要的 IAM 許可**

`AutomationAssumeRole` 參數需要下列動作才能成功使用 Runbook。
+ `ec2:DescribeInstances`
+ `ssm:DescribeAutomationExecutions`
+ `ssm:DescribeInstanceInformation`
+ `ssm:GetAutomationExecution`
+ `ssm:ListCommands`
+ `ssm:ListCommandInvocations`
+ `ssm:SendCommand`
+ `s3:ListBucket`
+ `s3:GetEncryptionConfiguration`
+ `s3:GetBucketPublicAccessBlock`
+ `s3:GetBucketPolicyStatus`
+ `s3:PutObject`
+ `s3:GetBucketAcl`
+ `s3:GetAccountPublicAccessBlock`

 *（選用） 連接到執行個體描述檔的 IAM 角色或在執行個體上設定的 IAM 使用者需要下列動作，才能將日誌上傳至為參數 指定的 Amazon S3 儲存貯體`LogUploadBucketName`：*
+ `s3:PutObject`
+ `s3:GetObject`
+ `s3:ListBucket`

 **指示** 

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

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

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

1. 針對輸入參數，輸入下列內容：
   + **AutomationAssumeRole （選用）：**

     (IAM) 角色的 Amazon Resource Name AWS AWS Identity and Access Management (ARN)，允許 Systems Manager Automation 代表您執行動作。如果未指定角色，Systems Manager Automation 會使用啟動此 Runbook 之使用者的許可。
   + **InstanceId （必要）：**

     您要執行自動化的目標 Amazon EC2 Windows 執行個體 ID。執行個體必須由 Systems Manager 管理，才能執行自動化。
   + **CaptureProcessDump （選用）：**

     要擷取的程序傾印類型。自動化可以為可能造成自動化開始時效能影響的程序擷取一個程序傾印。執行個體根磁碟區需要至少 10 GB 的可用空間 （根磁碟區大小大於 100 GB 時大於磁碟大小的 10%，以及 10 GB，加上程序耗用超過 10 GB 記憶體時程序耗用的總記憶體大小）。
   + **LogCaptureDuration （選用）：**

     此自動化會在問題存在時擷取日誌的分鐘數`15`，介於 `1`和 之間。預設值為 `5`。
   + **LogUploadBucketName （選用）：**

     帳戶中您要上傳日誌的 Amazon S3 儲存貯體。儲存貯體必須使用伺服器端加密 (SSE) 設定，且儲存貯體政策不得將不必要的讀取/寫入許可授予不需要存取擷取日誌的各方。Amazon EC2 Windows 執行個體必須能夠存取 Amazon S3 儲存貯體。
   + **InstallEC2RescueTool （選用）：**

     將 設定為 `Yes` 允許 Runbook 安裝最新版本`EC2Rescue`的工具，以擷取 Windows 事件和系統日誌。預設值為 `No`。
   + **確認 （必要）：**

     閱讀此自動化 Runbook 所執行動作的完整詳細資訊，如果您同意，請輸入 `Yes, I understand and acknowledge`。  
![\[Input parameters form for troubleshooting Amazon EC2 Windows instance performance issues.\]](http://docs.aws.amazon.com/zh_tw/systems-manager-automation-runbooks/latest/userguide/images/awssupport-troubleshoot-windows-performance_input_parameters.png)

1. 選取執行。

1. 自動化會啟動。

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

     確保只有一個以執行個體為目標的 Runbook 執行。如果 Runbook 找到另一個以相同執行個體為目標的執行，則會傳回錯誤並結束。
   + **`AssertInstanceIsWindows:`**

     宣告 Amazon EC2 執行個體正在 Windows 作業系統上執行。否則，自動化會結束。
   + **`AssertInstanceIsManagedInstance:`**

     宣告 Amazon EC2 執行個體由 管理 AWS Systems Manager。否則，自動化會結束。
   + **`VerifyPrerequisites:`**

     驗證執行個體作業系統上的 PowerShell 版本，並確保執行個體可以透過 Systems Manager 連線以執行 PowerShell 命令。此自動化支援在 Windows 8.1 / Server 2012 R2 (6.3) 或更新版本上執行的 PowerShell 4.0 及更高版本。如果版本較舊，自動化會失敗。當您選擇將日誌上傳至 Amazon S3 儲存貯體時，此自動化會檢查 AWS Tools for PowerShell 模組是否可用。如果沒有，自動化會結束。
   + **`BranchOnProcessDump:`**

     如果您設定分支以擷取影響效能的程序傾印，則根據分支。
   + **`CaptureProcessDump:`**

     檢查執行個體是否有足夠的空間來執行此自動化 （當您選擇最高 CPU/記憶體時）。
   + **`CapturePerformanceLogs:`**

     再次檢查磁碟空間，並在執行個體上執行 PowerShell 指令碼，以建立 perfmon 計數器並啟動效能監控和 Windows 效能記錄器記錄。符合定義的 後，指令碼`LogCaptureDuration`會停止。
   + **`SummarizePerformanceLogs:`**

     摘要上一個步驟產生的 XML 報告 `CapturePerformanceLogs`，以尋找耗用最多 WorkingSet64 （記憶體） 和 % 處理器時間 (CPU) 的負責程序，顯示為自動化上的輸出。它會產生使用 LogicalDisk、網路介面、記憶體、TCPv4, IPv4 和 UDPv4 的類似資訊，並將其儲存在`analysis_output.log`輸出資料夾中。
   + **`BranchOnInstallEC2Rescue:`**

     如果您將其設定為在 Amazon EC2 執行個體中安裝最新的`EC2Rescue`工具，則分支。
   + **`InstallEC2RescueTool:`**

     在執行個體作業系統中安裝 `EC2Rescue`工具，以使用 擷取`EC2Rescue`日誌`AWS-ConfigureAWSPackage`。
   + **`RunEC2RescueTool:`**

     在執行個體作業系統中執行 `EC2Rescue`工具，以擷取所需的所有日誌。 只會`EC2Rescue`擷取必要的日誌以節省空間。
   + **`BranchOnIfS3BucketProvided:`**

     根據 的使用者輸入分支`LogUploadBucketName`，以查看是否有儲存貯體名稱可供上傳日誌。
   + **`GetS3BucketPublicStatus:`**

     確定是否提供 Amazon S3 儲存貯體，如果提供，則確認 Amazon S3 儲存貯體不是公有的，並使用 SSE 設定。
   + **`UploadLogResult:`**

     將日誌上傳至提供的 Amazon S3 儲存貯體。如果 PowerShell 版本是 5.0 或更新版本，它會將日誌壓縮為 ZIP 封存並上傳。它會在上傳完成後刪除 ZIP 檔案。如果 PowerShell 版本低於 5.0，則會將檔案直接上傳至資料夾。
   + **`CleanUpLogsOnFailure:`**

     清除`CapturePerformanceLogs`步驟失敗時產生的所有日誌。如果 SSM Agent 無法正常運作，或 Windows 系統沒有回應，則`CleanUpLogsOnFailure`步驟可能會失敗或逾時。

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

   目標執行個體具有所有必要先決條件的執行。  
![\[Output logs showing performance capture process, EC2Rescue completion, and top CPU/memory usage processes.\]](http://docs.aws.amazon.com/zh_tw/systems-manager-automation-runbooks/latest/userguide/images/awssupport-troubleshoot-windows-performance_outputs_all_prerequisites_met.png)

   目標執行個體位於 Linux 平台上且執行失敗的執行。您可以選擇步驟 ID 以查看失敗詳細資訊。  
![\[Execution status showing failed overall status with 2 executed steps, 1 succeeded and 1 failed.\]](http://docs.aws.amazon.com/zh_tw/systems-manager-automation-runbooks/latest/userguide/images/awssupport-troubleshoot-windows-performance_outputs_failed_linux_instance.png)

   步驟 的失敗詳細資訊`AssertInstanceIsWindows`。  
![\[Failure details showing verification error for Linux property value instead of Windows.\]](http://docs.aws.amazon.com/zh_tw/systems-manager-automation-runbooks/latest/userguide/images/awssupport-troubleshoot-windows-performance_outputs_assert_windows_fail.png)

 **參考** 

Systems Manager Automation
+ [執行此自動化 （主控台）](https://console.aws.amazon.com/systems-manager/documents/AWSSupport-TroubleshootWindowsPerformance/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/)