

# PERF04-BP03 收集並記錄資料庫效能指標
<a name="perf_right_database_solution_collect_metrics"></a>

 若要了解您的資料管理系統如何執行，請務必追蹤相關指標。這些指標將協助您優化資料管理資源，以確保符合您的工作負載要求，並確保您對工作負載如何執行有著清楚的概觀。使用工具、程式庫和系統來記錄與資料庫效能有關的效能測量值。 

 

 有一些與資料庫託管所在系統相關的指標 (例如，CPU、儲存體、記憶體、IOPS)，也有一些用於存取資料本身的指標 (例如，每秒交易數、查詢率、回應時間、錯誤)。任何支援或操作人員都應該可以立即存取這些指標，並且有足夠的歷史記錄能夠識別趨勢、異常和瓶頸。 

 

 **預期成果：** 若要監控資料庫工作負載的效能，您必須記錄一段時間的多個效能指標。這可讓您偵測異常，以及針對業務指標測量效能，以確保符合您的工作負載需求。 

 **常用的反模式：** 
+  您只使用手動日誌檔案來搜尋指標。 
+  您只會將指標發佈至您團隊所使用的內部工具，而且沒有工作負載的全貌。 
+  您只會使用所選監控軟體記錄的預設指標。 
+  您只會在有問題時檢閱指標。 
+  您只會監控系統層級指標，而不會擷取資料存取或用量指標。 

 **建立此最佳實務的優勢：** 建立效能基準可協助您了解正常行為和工作負載的要求。異常模式可以更快地識別和偵錯，進而改善資料庫的效能和可靠性。可以設定資料庫容量，以確保最佳成本，而不會犧牲效能。 

 **若未建立此最佳實務，暴露的風險等級：** 高 
+  無法區分異常與正常效能等級將讓您難以識別問題和做出決策。 
+  可能未識別潛在的節省成本。 
+  將不會識別可能導致可靠性或效能下降的成長模式。 

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

 識別、收集、彙總資料庫相關指標，並使其相互關聯。指標應該同時包括支援資料庫的基礎系統和資料庫指標。基礎系統指標可能包括 CPU 使用率、記憶體、可用磁碟儲存、磁碟 I/O 和網路傳入和傳出指標，而資料庫指標可能包括每秒交易數、熱門查詢、平均查詢率、回應時間、索引使用情況、表格鎖定、查詢逾時，以及開啟的連線數目。此資料對於了解工作負載的執行方式，以及資料庫解決方案的使用方式至關重要。將這些指標納入資料驅動的方法，以調整和優化工作負載的資源。  

 **實作步驟：** 

1.  務必要追蹤哪些資料庫指標？ 

   1.  [監控 Amazon RDS 的指標](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/CHAP_Monitoring.html) 

   1.  [使用 Performance Insights 進行監控](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/USER_PerfInsights.html) 

   1.  [增強型監控](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/USER_Monitoring.OS.overview.html) 

   1.  [DynamoDB 指標](https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/metrics-dimensions.html) 

   1.  [監控 DynamoDB DAX](https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/DAX.Monitoring.html) 

   1.  [監控 MemoryDB](https://docs.aws.amazon.com/memorydb/latest/devguide/monitoring-cloudwatch.html) 

   1.  [監控 Amazon Redshift](https://docs.aws.amazon.com/redshift/latest/mgmt/metrics.html) 

   1.  [Timeseries 指標和維度參考](https://docs.aws.amazon.com/timestream/latest/developerguide/metrics-dimensions.html) 

   1.  [Aurora 的叢集層級指標](https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/Aurora.AuroraMySQL.Monitoring.Metrics.html) 

   1.  [監控 Amazon Keyspaces](https://docs.aws.amazon.com/keyspaces/latest/devguide/monitoring.html) 

   1.  [監控 Amazon Neptune](https://docs.aws.amazon.com/neptune/latest/userguide/monitoring.html) 

1.  資料庫監控是否會受益於偵測操作異常效能問題的機器學習解決方案？ 

   1.  [Amazon DevOps Guru for Amazon RDS](https://docs.aws.amazon.com/devops-guru/latest/userguide/working-with-rds.overview.how-it-works.html) 可讓您查看效能問題，並做出更正動作的建議。 

1.  您是否需要有關 SQL 使用情況的應用程式層級詳細資訊？ 

   1.  [AWS X-Ray](https://docs.aws.amazon.com/xray/latest/devguide/xray-api-segmentdocuments.html#api-segmentdocuments-sql) 可以檢測至應用程式，以獲得見解並封裝所有資料點以進行單一查詢。 

1.  您目前是否具有核准的記錄和監控解決方案？ 

   1.  [Amazon CloudWatch](https://aws.amazon.com/cloudwatch/) 可以收集架構中各種資源的指標。您還可以收集和發佈自訂指標以顯示業務或衍生指標。使用 CloudWatch 或第三方解決方案來設定可指出何時超過閾值的警示。 

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) 

 **實作計劃的工作量： **有一個 *中* 工作量，用來從所有資料庫資源識別、追蹤、收集、彙總指標，並使其相互關聯。 

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

 **相關文件：** 
+ [AWS 資料庫快取 ](https://aws.amazon.com/caching/database-caching/) 
+ [ Amazon Athena 10 大效能秘訣 ](https://aws.amazon.com/blogs/big-data/top-10-performance-tuning-tips-for-amazon-athena/)
+ [ Amazon Aurora 最佳實務 ](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/Aurora.BestPractices.html)
+  [Amazon DynamoDB Accelerator ](https://aws.amazon.com/dynamodb/dax/)
+ [Amazon DynamoDB 最佳實務 ](https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/BestPractices.html) 
+ [Amazon Redshift Spectrum 最佳實務 ](https://aws.amazon.com/blogs/big-data/10-best-practices-for-amazon-redshift-spectrum/) 
+ [Amazon Redshift 效能 ](https://docs.aws.amazon.com/redshift/latest/dg/c_challenges_achieving_high_performance_queries.html) 
+ [AWS 的雲端資料庫 ](https://aws.amazon.com/products/databases/) 
+  [Amazon RDS Performance Insights](https://aws.amazon.com/rds/performance-insights/) 

 **相關影片：** 
+ [AWS 專用資料庫 (DAT209-L) ](https://www.youtube.com/watch?v=q81TVuV5u28) 
+  [探究 Amazon Aurora 儲存的奧秘：運作方式 (DAT309-R) ](https://www.youtube.com/watch?v=uaQEGLKtw54)
+  [深入探討 Amazon DynamoDB：進階設計模式 (DAT403-R1) ](https://www.youtube.com/watch?v=6yqfmXiZTlM)

 **相關範例：** 
+  [Level 100：使用 CloudWatch 儀表板進行監控](https://wellarchitectedlabs.com/performance-efficiency/100_labs/100_monitoring_with_cloudwatch_dashboards/) 
+  [AWS 資料集擷取指標收集架構](https://github.com/awslabs/aws-dataset-ingestion-metrics-collection-framework) 
+  [Amazon RDS 監控研討會](https://www.workshops.aws/?tag=Enhanced%20Monitoring) 