

# PERF02-BP03 收集運算相關指標
<a name="perf_compute_hardware_collect_compute_related_metrics"></a>

 記錄並追蹤與運算相關的指標，進一步了解運算資源的效能，並改善效能及使用率。

 **常見的反模式：**
+  您只使用手動日誌檔案來搜尋指標。  
+  您只會使用監控軟體記錄的預設指標。
+  您只會在有問題時審查指標。

 **建立此最佳實務的優勢：**收集效能相關指標有助於使應用程式效能與業務需求保持一致，確保符合工作負載需求。這麼做也可以協助您持續改善工作負載中的資源效能和使用率。

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

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

 雲端工作負載可以產生大量資料，例如指標、日誌和事件。在 中 AWS 雲端，收集指標是改善安全性、成本效益、效能和永續性的重要步驟。 使用 [Amazon CloudWatch](https://aws.amazon.com/cloudwatch/) 等監控服務 AWS ，提供廣泛的效能相關指標，為您提供寶貴的洞見。CPU 使用率、記憶體使用率、磁碟 I/O 和網路傳入和傳出等指標可以提供使用率層級或效能瓶頸的洞察。將這些指標納入資料驅動的方法，以主動調整和優化工作負載的資源。  在理想的情況下，應該在單一平台中收集與運算資源相關的所有指標，並實作保留政策以支援成本和營運目標。

## 實作步驟
<a name="implementation-steps"></a>
+  識別與您的工作負載相關的效能相關指標。您應該收集與資源使用率和雲端工作負載運作方式有關的指標 (例如回應時間和輸送量)。
  +  [Amazon EC2 預設指標](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/viewing_metrics_with_cloudwatch.html) 
  +  [Amazon ECS 預設指標](https://docs.aws.amazon.com/AmazonECS/latest/developerguide/cloudwatch-metrics.html) 
  +  [Amazon EKS 預設指標](https://docs.aws.amazon.com/prescriptive-guidance/latest/implementing-logging-monitoring-cloudwatch/kubernetes-eks-metrics.html) 
  +  [Lambda 預設指標](https://docs.aws.amazon.com/lambda/latest/dg/monitoring-functions-access-metrics.html) 
  +  [Amazon EC2記憶體和磁碟指標](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/mon-scripts.html) 
+  為工作負載選擇並設定合適的日誌記錄和監控解決方案。
  +  [AWS 原生可觀測性](https://catalog.workshops.aws/observability/en-US/aws-native) 
  +  [AWS Distro for OpenTelemetry](https://aws.amazon.com/otel/) 
  +  [Amazon Managed Service for Prometheus](https://docs.aws.amazon.com/grafana/latest/userguide/prometheus-data-source.html) 
+  根據工作負載需求，為指標定義必要的篩選條件和彙總。
  +  [使用 Amazon CloudWatch Logs 和指標篩選條件量化自訂應用程式指標](https://aws.amazon.com/blogs/mt/quantify-custom-application-metrics-with-amazon-cloudwatch-logs-and-metric-filters/) 
  +  [使用 Amazon CloudWatch 策略標記收集自訂指標](https://aws.amazon.com/blogs/infrastructure-and-automation/collect-custom-metrics-with-amazon-cloudwatch-strategic-tagging/) 
+  為指標設定資料保留政策，以符合安全性和營運目標。
  +  [ CloudWatch 指標的預設資料保留](https://aws.amazon.com/cloudwatch/faqs/#AWS_resource_.26_custom_metrics_monitoring) 
  +  [ CloudWatch 日誌的預設資料保留](https://aws.amazon.com/cloudwatch/faqs/#Log_management) 
+  如有必要，為指標建立警示和通知，可協助您主動回應效能相關問題。
  +  [使用 Amazon CloudWatch 異常偵測建立自訂指標的警示](https://docs.aws.amazon.com/prescriptive-guidance/latest/patterns/create-alarms-for-custom-metrics-using-amazon-cloudwatch-anomaly-detection.html) 
  +  [使用 Amazon 為特定網頁建立指標和警示 CloudWatch RUM](https://aws.amazon.com/blogs/mt/create-metrics-and-alarms-for-specific-web-pages-amazon-cloudwatch-rum/) 
+  使用自動化來部署指標和記錄彙總代理程式。
  +  [AWS Systems Manager 自動化](https://docs.aws.amazon.com/systems-manager/latest/userguide/systems-manager-automation.html?ref=wellarchitected) 
  +  [OpenTelemetry 收集器](https://aws-otel.github.io/docs/getting-started/collector) 

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

 **相關文件：**
+  [監控與可觀測性](https://aws.amazon.com/cloudops/monitoring-and-observability/) 
+  [最佳實務：使用 實作可觀測性 AWS](https://aws.amazon.com/blogs/mt/best-practices-implementing-observability-with-aws/) 
+  [Amazon CloudWatch 文件](https://docs.aws.amazon.com/cloudwatch/index.html?ref=wellarchitected) 
+  [使用 CloudWatch 代理程式從 Amazon EC2執行個體和內部部署伺服器收集指標和日誌](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/Install-CloudWatch-Agent.html?ref=wellarchitected) 
+  [存取 的 Amazon CloudWatch Logs AWS Lambda](https://docs.aws.amazon.com/lambda/latest/dg/monitoring-functions-logs.html?ref=wellarchitected) 
+  [將 CloudWatch 日誌與容器執行個體搭配使用](https://docs.aws.amazon.com/AmazonECS/latest/developerguide/using_cloudwatch_logs.html?ref=wellarchitected) 
+  [發佈自訂指標](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/publishingMetrics.html?ref=wellarchitected) 
+  [AWS Answers：集中式日誌記錄](https://aws.amazon.com/answers/logging/centralized-logging/?ref=wellarchitected) 
+  [AWS 發佈 CloudWatch 指標的服務](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/CW_Support_For_AWS.html?ref=wellarchitected) 
+  [在 EKS上監控 Amazon AWS Fargate](https://aws.amazon.com/blogs/containers/monitoring-amazon-eks-on-aws-fargate-using-prometheus-and-grafana/) 

 **相關影片：**
+  [AWS re：Invent 2023 – 【LAUNCH】 現代工作負載的應用程式監控](https://www.youtube.com/watch?v=T2TovTLje8w) 
+  [AWS re：Invent 2023 – 實作應用程式可觀測性](https://www.youtube.com/watch?v=IcTcwUSwIs4) 
+  [AWS re：Invent 2023 – 建立有效的可觀測性策略](https://www.youtube.com/watch?v=7PQv9eYCJW8) 
+  [AWS re：Invent 2023 – AWS Distro for 的無縫可觀測性 OpenTelemetry](https://www.youtube.com/watch?v=S4GfA2R0N_A) 
+  [上的應用程式效能管理 AWS](https://www.youtube.com/watch?v=5T4stR-HFas&ref=wellarchitected) 

 **相關範例：**
+  [AWS 適用於 Linux Workloads Immersion Day - Amazon CloudWatch](https://catalog.us-east-1.prod.workshops.aws/workshops/a8e9c6a6-0ba9-48a7-a90d-378a440ab8ba/en-US/300-cloudwatch) 
+  [監控 Amazon ECS叢集和容器](https://ecsworkshop.com/monitoring/) 
+  [使用 Amazon CloudWatch 儀表板進行監控](https://catalog.workshops.aws/well-architected-performance-efficiency/en-US/3-monitoring/monitoring-with-cloudwatch-dashboards) 
+  [Amazon EKS研討會](https://www.eksworkshop.com/) 