

# REL06-BP01 監控工作負載的所有元件 (產生)
<a name="rel_monitor_aws_resources_monitor_resources"></a>

 使用 Amazon CloudWatch 或第三方工具監控工作負載的元件。使用 AWS Health 儀表板監控 AWS 服務。

 工作負載的所有元件都應該受到監控，包括前端、商業邏輯和儲存層。定義關鍵指標，描述如何從日誌中擷取指標 (如果需要)，並設定調用對應警示事件的閾值。確保指標與工作負載的關鍵績效指標 (KPI) 相關，並使用指標和日誌來識別服務降級的早期警告訊號。例如，與業務成果相關的指標 (例如每分鐘成功處理的訂單數量) 可以比技術指標 (例如 CPU 使用率) 更快地指出工作負載問題。使用 AWS Health 儀表板可針對 AWS 資源下的 AWS 服務的效能和可用性，為您提供個人化檢視。

 雲端監控提供新機遇。大多數雲端供應商都開發了可自訂的勾點，並且可以提供深入解析，協助您監控工作負載的多個層面。Amazon CloudWatch 等 AWS 服務會在使用者介入程度最低的情況下，套用統計和機器學習演算法來持續分析系統和應用程式的指標、判斷正常基準以及披露異常情況。異常偵測演算法會考慮指標的季節性和趨勢變化。

 AWS 提供大量可供使用的監控和日誌資訊，可用於定義工作負載特定的指標、需求變更程序，並採用機器學習技術，而不論機器學習專業知識如何。

 此外，監控所有外部端點，以確保它們獨立於基本實作。此主動監控可透過綜合交易 (有時稱為*使用者 Canary*，但請別與 Canary 部署混淆) 加以完成，它會定期運行工作負載的用戶端執行的許多常見任務匹配動作。在持續時間中讓這些任務保持簡單扼要，並確定在測試期間不會讓工作負載超載。Amazon CloudWatch Synthetics 讓您能夠[建立綜合性 Canary](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/CloudWatch_Synthetics_Canaries.html)，以監控您的端點和 API。您也可以將綜合性 Canary 用戶端節點與 AWS X-Ray 主控台結合，以指出綜合性 Canary 在所選時段內發生錯誤、故障或調節率等問題。

 **預期成果：**

 從工作負載的所有元件中收集並使用關鍵指標，以確保工作負載的可靠性和最佳的使用者體驗。偵測工作負載未達成業務成果，可讓您快速宣告災難並從事件中復原。

 **常見的反模式：**
+  僅監控工作負載的外部界面。
+  不產生任何工作負載特定指標，只依賴工作負載使用的 AWS 服務提供給您的指標。
+  僅在工作負載中使用技術指標，而不監控與工作負載貢獻的非技術 KPI 相關的任何指標。
+  依賴生產流量和簡單的運作狀態檢查來監控和評估工作負載狀態。

 **建立此最佳實務的優勢：**在工作負載中的所有層級進行監控，可讓您更快速地預測和解決構成工作負載的元件中的問題。

 **未建立此最佳實務時的曝險等級：**高 

## 實作指引
<a name="implementation-guidance"></a>

1.  **在可用的地方開啟日誌記錄。**應從工作負載的所有元件中取得監控資料。開啟其他日誌記錄，例如 S3 Access Logs，並允許您的工作負載記錄工作負載特定資料。從 Amazon ECS、Amazon EKS、Amazon EC2、Elastic Load Balancing、AWS Auto Scaling 和 Amazon EMR 等服務中收集 CPU、網路 I/O 和磁碟 I/O 平均值的指標。如需將指標發佈到 CloudWatch 的 AWS 服務清單，請參閱 [AWS Services That Publish CloudWatch Metrics](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/CW_Support_For_AWS.html)。

1.  **審核所有預設指標，並探索任何資料收集漏洞。**每個服務都會產生預設指標。收集預設指標可讓您進一步了解工作負載元件之間的相依性，以及元件可靠性和效能如何影響工作負載。您也可以使用 AWS CLI 或 API 建立自己的自訂指標並[發佈](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/publishingMetrics.html)到 CloudWatch。

1.  **評估所有指標，以決定在工作負載中為每個 AWS 服務提醒哪些指標。**您可以進行選擇，以選取對工作負載可靠性有重大影響的指標子集。專注於重要指標和閾值，可讓您調整[提醒](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/AlarmThatSendsEmail.html)的數量，並協助將誤報率降至最低。

1.  **在調用提醒後，定義工作負載的提醒和復原程序。**定義提醒可讓您快速通知、呈報並遵循必要的步驟，以便從事件中復原並實現規定的復原時間點目標 (RTO)。可以使用 [https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/AlarmThatSendsEmail.html#alarms-and-actions](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/AlarmThatSendsEmail.html#alarms-and-actions)來調用自動化工作流程，並根據定義的閾值啟動復原程序。

1.  **探索如何使用綜合交易來收集有關工作負載狀態的相關資料。**綜合監控遵循相同的路由並執行與客戶相同的動作，即使您的工作負載沒有任何客戶流量，也能持續驗證您的客戶體驗。透過使用[綜合交易](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/CloudWatch_Synthetics_Canaries.html)，您可以在客戶之前發現問題。

## 資源
<a name="resources"></a>

 **相關的最佳實務：**
+ [REL11-BP03 將所有分層的修復自動化](rel_withstand_component_failures_auto_healing_system.md)

 **相關文件：**
+  [開始使用 AWS Health 儀表板 — 您的帳戶運作狀態](https://docs.aws.amazon.com/health/latest/ug/getting-started-health-dashboard.html) 
+  [發佈 CloudWatch 指標的 AWS 服務](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/CW_Support_For_AWS.html) 
+  [Network Load Balancer 的存取日誌](https://docs.aws.amazon.com/elasticloadbalancing/latest/network/load-balancer-access-logs.html) 
+  [Application Load Balancer 的存取日誌](https://docs.aws.amazon.com/elasticloadbalancing/latest/application/load-balancer-access-logs.html) 
+  [存取 AWS Lambda 的 Amazon CloudWatch Logs](https://docs.aws.amazon.com/lambda/latest/dg/monitoring-functions-logs.html) 
+  [Amazon S3 伺服器存取日誌記錄](https://docs.aws.amazon.com/AmazonS3/latest/dev/ServerLogs.html) 
+  [啟用 Classic Load Balancer 的存取日誌](https://docs.aws.amazon.com/elasticloadbalancing/latest/classic/enable-access-logs.html) 
+  [將日誌資料匯出至 Amazon S3](https://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/S3Export.html) 
+  [在 Amazon EC2 執行個體上安裝 CloudWatch Agent](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/install-CloudWatch-Agent-on-EC2-Instance.html) 
+  [發佈自訂指標](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/publishingMetrics.html) 
+  [使用 Amazon CloudWatch 儀表板](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/CloudWatch_Dashboards.html) 
+  [使用 Amazon CloudWatch 指標](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/working_with_metrics.html) 
+  [使用 Canary (Amazon CloudWatch Synthetics)](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/CloudWatch_Synthetics_Canaries.html) 
+  [什麼是 Amazon CloudWatch Logs？](https://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/WhatIsCloudWatchLogs.html) 

   **使用者指南：**
+  [建立追蹤](https://docs.aws.amazon.com/awscloudtrail/latest/userguide/cloudtrail-create-a-trail-using-the-console-first-time.html) 
+  [監控 Amazon EC2 Linux 執行個體的記憶體和磁碟指標](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/mon-scripts.html) 
+  [CloudWatch Logs 與容器執行個體搭配使用](https://docs.aws.amazon.com/AmazonECS/latest/developerguide/using_cloudwatch_logs.html) 
+  [VPC 流量日誌](https://docs.aws.amazon.com/AmazonVPC/latest/UserGuide/flow-logs.html) 
+  [什麼是 Amazon DevOps Guru？](https://docs.aws.amazon.com/devops-guru/latest/userguide/welcome.html) 
+  [什麼是 AWS X-Ray？](https://docs.aws.amazon.com/xray/latest/devguide/aws-xray.html) 

 **相關部落格：**
+  [使用 Amazon CloudWatch Synthetics 和 AWS X-Ray 進行偵錯](https://aws.amazon.com/blogs/devops/debugging-with-amazon-cloudwatch-synthetics-and-aws-x-ray/) 

 **相關範例：**
+  [Amazon 建置者資料中心：偵測分散式系統，以了解運作狀態](https://aws.amazon.com/builders-library/instrumenting-distributed-systems-for-operational-visibility/) 
+  [可觀測性研討會](https://catalog.workshops.aws/observability/en-US) 