

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

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

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

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

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

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

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

## 實作步驟
<a name="implementation-steps"></a>

1.  找出與工作負載相關的效能相關指標。您應該收集與資源使用率和雲端工作負載運作方式有關的指標 (例如回應時間和輸送量)。 

   1.  [Amazon EC2 預設指標](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/viewing_metrics_with_cloudwatch.html) 

   1.  [Amazon ECS 預設指標](https://docs.aws.amazon.com/AmazonECS/latest/developerguide/cloudwatch-metrics.html) 

   1.  [Amazon EKS 預設指標](https://docs.aws.amazon.com/prescriptive-guidance/latest/implementing-logging-monitoring-cloudwatch/kubernetes-eks-metrics.html) 

   1.  [Lambda 預設指標](https://docs.aws.amazon.com/lambda/latest/dg/monitoring-functions-access-metrics.html) 

   1.  [Amazon EC2 記憶體和磁碟指標](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/mon-scripts.html) 

1.  為工作負載選擇並設定合適的記錄和監控解決方案。 

   1.  [AWS 原生可觀測性](https://catalog.workshops.aws/observability/en-US/aws-native) 

   1.  [適用於 OpenTelemetry 的 AWS Distro](https://aws.amazon.com/otel/) 

   1.  [Amazon Managed Service for Prometheus](https://docs.aws.amazon.com/grafana/latest/userguide/prometheus-data-source.html) 

1.  根據工作負載需求，為指標定義必要的篩選條件和彙總。 

   1.  [使用 Amazon CloudWatch Logs 和指標篩選條件，量化自訂應用程式指標](https://aws.amazon.com/blogs/mt/quantify-custom-application-metrics-with-amazon-cloudwatch-logs-and-metric-filters/) 

   1.  [使用 Amazon CloudWatch 策略標記收集自訂指標](https://aws.amazon.com/blogs/infrastructure-and-automation/collect-custom-metrics-with-amazon-cloudwatch-strategic-tagging/) 

1.  為指標設定資料保留政策，以符合安全性和營運目標。 

   1.  [CloudWatch 指標的預設資料保留](https://aws.amazon.com/cloudwatch/faqs/#AWS_resource_.26_custom_metrics_monitoring) 

   1.  [CloudWatch Logs 的預設資料保留](https://aws.amazon.com/cloudwatch/faqs/#Log_management) 

1.  如有必要，為指標建立警示和通知，以協助您主動回應效能相關問題。 

   1.  [使用 Amazon CloudWatch 異常偵測為自訂指標建立警示](https://docs.aws.amazon.com/prescriptive-guidance/latest/patterns/create-alarms-for-custom-metrics-using-amazon-cloudwatch-anomaly-detection.html) 

   1.  [使用 Amazon CloudWatch RUM 為特定網頁建立指標和警示](https://aws.amazon.com/blogs/mt/create-metrics-and-alarms-for-specific-web-pages-amazon-cloudwatch-rum/) 

1.  使用自動化來部署指標和記錄彙總代理程式。 

   1.  [AWS Systems Manager 自動化](https://docs.aws.amazon.com/systems-manager/latest/userguide/systems-manager-automation.html?ref=wellarchitected) 

   1.  [OpenTelemetry 收集器](https://aws-otel.github.io/docs/getting-started/collector) 

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

 **相關文件：** 
+  [Amazon CloudWatch 文件](https://docs.aws.amazon.com/cloudwatch/index.html?ref=wellarchitected) 
+  [使用 CloudWatch Agent 從 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 Logs](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) 
+  [發佈 CloudWatch 指標的 AWS 服務](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/CW_Support_For_AWS.html?ref=wellarchitected) 
+  [監控 AWS Fargate Amazon EKS](https://aws.amazon.com/blogs/containers/monitoring-amazon-eks-on-aws-fargate-using-prometheus-and-grafana/) 

 **相關影片：** 
+  [AWS 上的應用程式效能管理](https://www.youtube.com/watch?v=5T4stR-HFas&ref=wellarchitected) 

 **相關範例：** 
+  [Level 100：使用 CloudWatch 儀表板進行監控](https://wellarchitectedlabs.com/performance-efficiency/100_labs/100_monitoring_with_cloudwatch_dashboards/) 
+  [Level 100：使用 CloudWatch 儀表板監控 Windows EC2 執行個體](https://wellarchitectedlabs.com/performance-efficiency/100_labs/100_monitoring_windows_ec2_cloudwatch/) 
+  [Level 100：使用 CloudWatch 儀表板監控 Amazon Linux EC2 執行個體](https://wellarchitectedlabs.com/performance-efficiency/100_labs/100_monitoring_linux_ec2_cloudwatch/) 