

# PERF02-BP03 收集与计算相关的指标
<a name="perf_select_compute_collect_metrics"></a>

要了解计算资源的性能，您必须记录和跟踪各种系统的利用率。此数据可用于更准确地确定资源需求。  

 工作负载会生成大量数据，例如指标、日志和事件。确定您现有的存储、监控和可观察性服务是否可以管理生成的数据。确定反映资源利用率并且可以在单个平台上收集、聚合和关联的指标。这些指标应该代表您的所有工作负载资源、应用程序和服务，以便您可以轻松获得系统范围的可见性，并快速识别性能改进机会和问题。

 **期望结果：** 在单个平台上，识别、收集、聚合和关联涉及到计算相关资源的所有指标，并进行保留以支持成本和运营目标。 

 **常见反模式：** 
+  您只能手动搜索日志文件来查找指标。  
+  您只能将指标发布到内部工具。 
+  您只使用所选监控软件记录的默认指标。 
+  您只在出现问题时检查指标。 

 

 **建立此最佳实践的好处：** 要监控工作负载的性能，必须记录一段时间的多项性能指标。您可以利用这些指标来检测性能异常。这些指标还有助于根据业务指标衡量性能，以确保满足工作负载需求。 

 **未建立这种最佳实践的情况下暴露的风险等级：** 高 

## 实施指导
<a name="implementation-guidance"></a>

 识别、收集、聚合和关联与计算相关的指标。使用 Amazon CloudWatch 之类的服务可以使实施速度更快并更易于维护。除了记录的默认指标外，还可以识别和跟踪工作负载中的其他系统级指标。记录 CPU 利用率、内存、磁盘 I/O 和网络入站和出站指标等数据，以深入了解利用率水平或瓶颈。这些数据对于了解工作负载的性能以及计算解决方案的使用方式至关重要。将这些指标用作数据驱动方法的一部分，以便主动调整和优化工作负载的资源。  

 **实施步骤：** 

1.  必须跟踪哪些计算解决方案指标？ 

   1.  [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.  [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.  [EC2 内存和磁盘指标](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/mon-scripts.html) 

1.  我目前是否有经过批准的日志记录和监控解决方案？ 

   1.  [Amazon CloudWatch](https://aws.amazon.com/cloudwatch/) 

   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.  [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.  [AWS Systems Manager Automation](https://docs.aws.amazon.com/systems-manager/latest/userguide/systems-manager-automation.html?ref=wellarchitected) 

   1.  [OpenTelemetry Collector](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 代理从 Amazon EC2 实例和本地服务器收集指标和日志](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/Install-CloudWatch-Agent.html?ref=wellarchitected) 
+  [访问 AWS Lambda 的 Amazon CloudWatch Logs](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) 
+  [制定监控计划](https://www.youtube.com/watch?v=OMmiGETJpfU&ref=wellarchitected) 

 

 **相关示例：** 
+  [第 100 级：使用 CloudWatch 控制面板进行监控](https://wellarchitectedlabs.com/performance-efficiency/100_labs/100_monitoring_with_cloudwatch_dashboards/) 
+  [第 100 级：使用 CloudWatch 控制面板监控 Windows EC2 实例](https://wellarchitectedlabs.com/performance-efficiency/100_labs/100_monitoring_windows_ec2_cloudwatch/) 
+  [第 100 级：使用 CloudWatch 控制面板监控 Amazon Linux EC2 实例](https://wellarchitectedlabs.com/performance-efficiency/100_labs/100_monitoring_linux_ec2_cloudwatch/) 