

本文為英文版的機器翻譯版本，如內容有任何歧義或不一致之處，概以英文版為準。

# 使用績效詳情進行監控
<a name="performance-insights"></a>

Performance Insights 會新增現有的 Amazon DocumentDB 監控功能，以說明您的叢集效能，並協助您分析影響叢集效能的任何問題。使用績效詳情儀表板，您可以視覺化資料庫負載，並依等待、查詢陳述式、主機或應用程式篩選負載。

**注意**  
Performance Insights 僅適用於 Amazon DocumentDB 3.6、4.0、5.0 和 8.0 執行個體型叢集。

**它如何有用？**
+ 視覺化資料庫效能 — 視覺化負載，以判斷負載在資料庫上的時間和位置
+ 判斷造成資料庫負載的原因 — 判斷哪些查詢、主機和應用程式造成執行個體負載
+ 判斷資料庫何時載入 - 放大績效詳情儀表板以專注於特定事件，或縮小以查看較大時間範圍的趨勢
+ 資料庫負載警示 — 從 CloudWatch 自動存取新的資料庫負載指標，您可以在其中監控資料庫負載指標和其他 Amazon DocumentDB 指標，並設定警示

**Amazon DocumentDB Performance Insights 有哪些限制？**
+  AWS GovCloud （美國東部） 和 AWS GovCloud （美國西部） 區域中的績效詳情不可用
+ Amazon DocumentDB 的績效詳情會保留最多 7 天的效能資料
+ 績效詳情中不會彙總超過 1，024 個位元組的查詢

**Topics**
+ [績效詳情概念](performance-insights-concepts.md)
+ [啟用和停用績效詳情](performance-insights-enabling.md)
+ [設定績效詳情的存取政策](performance-insights-policies.md)
+ [使用績效詳情儀表板來分析指標](performance-insights-analyzing.md)
+ [使用績效詳情 API 來擷取指標](performance-insights-metrics.md)
+ [Performance Insights 的 Amazon CloudWatch 指標](performance-insights-cloudwatch.md)
+ [計數器指標的績效詳情](performance-insights-counter-metrics.md)

# 績效詳情概念
<a name="performance-insights-concepts"></a>

**Topics**
+ [平均作用中工作階段](#performance-insights-concepts-sessions)
+ [維度](#performance-insights-concepts-dimensions)
+ [最大 vCPU](#performance-insights-concepts-maxvcpu)

## 平均作用中工作階段
<a name="performance-insights-concepts-sessions"></a>

資料庫負載 (DB 負載) 測量資料庫中的活動程度。績效詳情中的關鍵指標為 `DB Load`，每秒收集一次。`DBLoad` 指標的單位是 Amazon DocumentDB *執行個體的平均作用中工作階段 (AAS)*。

*作用中*工作階段是已將工作提交至 Amazon DocumentDB 執行個體並等待回應的連線。例如，如果您將查詢提交至 Amazon DocumentDB 執行個體，資料庫工作階段會在執行個體處理查詢時處於作用中狀態。

若要取得平均作用中工作階段 (AAS)，績效詳情會取樣同時執行查詢的工作階段數目。AAS 是工作階段總數除以樣本總數。下表顯示執行中查詢的五個連續範例。


| 樣本 | 執行查詢的工作階段數目 | AAS | 算式 | 
| --- | --- | --- | --- | 
|  1  |  2  |  2  |  2 個工作階段 / 1 個樣本  | 
|  2  |  0  |  1  |  2 個工作階段 / 2 個樣本  | 
|  3  |  4  |  2  |  6 個工作階段 / 3 個樣本  | 
|  4  |  0  |  1.5  |  6 個工作階段 / 4 個樣本  | 
|  5  |  4  |  2  |  10 個工作階段 / 5 個樣本  | 

在上述範例中，1-5 時間間隔的資料庫負載為 2 個 AAS。資料庫負載的增加意味著，就平均而言，更多的工作階段正執行於資料庫上。

## 維度
<a name="performance-insights-concepts-dimensions"></a>

`DB Load` 指標與其他時間序列指標不同，因為您可以將它分為名為維度的子元件。您可以將維度視為 `DB Load` 指標的不同特性類別。當您診斷效能問題時，最有用的維度是**等待狀態**和**熱門查詢**。

**等待狀態**  
*等待狀態*會導致查詢陳述式等待特定事件發生，然後才能繼續執行。例如，查詢陳述式可能會等到鎖定的資源解除鎖定。透過`DB Load`結合等待狀態，您可以取得工作階段狀態的完整資訊。以下是各種 Amazon DocumentDB 等待狀態：


| Amazon DocumentDB 等待狀態 | 等待狀態描述 | 
| --- | --- | 
|  鎖定  |  當工作階段正在等待分頁緩衝集區時，會發生鎖定等待狀態。當系統經常處理大型查詢、集合掃描，或緩衝集區太小而無法處理工作集時，經常分頁和分頁緩衝集區。  | 
| CPU |  當工作階段在 CPU 上等待時，會發生 CPU 等待狀態。  | 
|  CollectionLock  |  當工作階段正在等待取得集合的鎖定時，會發生 CollectionLock 等待狀態。當集合上有 DDL 操作時，就會發生這些事件。  | 
| DocumentLock |  當工作階段正在等待取得文件鎖定時，會發生 DocumentLock 等待狀態。對相同文件進行大量並行寫入會導致該文件的 DocumentLock 等待狀態變多。  | 
|  SystemLock  |  當工作階段在系統上等待時，會發生 SystemLock 等待狀態。當系統經常有長時間執行的查詢、長時間執行的交易或高並行時，就會發生這種情況。  | 
|  IO  |  當工作階段等待 IO 完成時，會發生 IO 等待狀態。  | 
|  BufferLock  |  當工作階段正在緩衝區中的共用頁面上等待取得鎖定時，BufferLock 等待狀態就會發生。如果其他程序在請求的頁面上保留開啟游標，BufferLock 等待狀態可能會延長。  | 
|  LowMemThrottle  |  當工作階段因 Amazon DocumentDB 執行個體上的記憶體壓力過大而等待時，會發生 LowMemThrottle 等待狀態。如果此狀態持續很長時間，請考慮擴展執行個體以提供額外的記憶體。如需詳細資訊，請參閱 [Resource Governor](https://docs.aws.amazon.com/documentdb/latest/developerguide/how-it-works.html)。  | 
|  BackgroundActivity  |  當工作階段正在等待內部系統程序時，會發生 BackgroundActivity 等待狀態。  | 
|  其他  |  其他等待狀態是內部等待狀態。如果此狀態持續很長時間，請考慮終止此查詢。如需詳細資訊，請參閱[如何尋找和終止長時間執行或封鎖的查詢？](https://docs.aws.amazon.com/documentdb/latest/developerguide/user_diagnostics.html#user_diagnostics-query_terminating.html)  | 

**熱門查詢**  
等待狀態會顯示瓶頸，而熱門查詢會顯示哪些查詢對資料庫負載的影響最大。例如，許多查詢目前可能正在資料庫上執行，但單一查詢可能會耗用 99% 的資料庫負載。在此情況下，高負載可能表示查詢發生問題。

## 最大 vCPU
<a name="performance-insights-concepts-maxvcpu"></a>

在儀表板中，**資料庫負載**圖表會收集、彙整並顯示工作階段資訊。若要查看作用中的工作階段是否超過最大 CPU，請查看它與**最大 vCPU 數**線的關係。**最大 vCPU** 值取決於 Amazon DocumentDB 執行個體的 vCPU （虛擬 CPU) 核心數量。

若資料庫負載通常高於**最大 vCPU 數**線，而主要等待狀態為 CPU，則 CPU 會超過負載。在這種情況下，您可能想要調節執行個體的連線、調整具有高 CPU 負載的任何查詢，或考慮較大的執行個體類別。處於任何等待狀態的密集且穩定的執行個體表示可能有您應解決的瓶頸或資源爭用問題。即使資料庫負載未超過**最大 vCPU 數**線，仍可能會有上述的問題。

# 啟用和停用績效詳情
<a name="performance-insights-enabling"></a>

若要使用績效詳情，請在資料庫執行個體上啟用。您可以視需要稍後停用它。啟用和停用績效詳情不會造成停機、重新開機或容錯移轉。

績效詳情代理程式會耗用資料庫主機上有限的 CPU 和記憶體。當資料庫負載過高時，代理程式會減少收集資料的頻率來限制效能影響。

## 建立叢集時啟用績效詳情
<a name="performance-insights-enabling-create-instance"></a>

在主控台中，您可以在建立或修改新的資料庫執行個體時啟用或停用績效詳情。

### 使用 AWS 管理主控台
<a name="create-instance-console"></a>

在 主控台中，您可以在建立 Amazon DocumentDB 叢集時啟用績效詳情。當您建立新的 Amazon DocumentDB 叢集時，請在績效詳情區段中選擇啟用**績效詳情來啟用****績效詳情**。

**主控台指示**

1. 若要建立叢集，請遵循[建立 Amazon DocumentDB 叢集的指示。](https://docs.aws.amazon.com/documentdb/latest/developerguide/db-cluster-create.html)

1. 在**績效詳情區段中選取啟用**績效詳情。  
![\[已選取啟用績效詳情的績效詳情區段。\]](http://docs.aws.amazon.com/zh_tw/documentdb/latest/developerguide/images/performance-insights/select-performance-insights.png)
**注意**  
Performance Insights 資料保留期間為七天。

   ** AWS KMS key** — 指定您的 AWS KMS 金鑰。Performance Insights 會使用 AWS KMS 金鑰加密所有潛在的敏感資料。將會對傳輸中與靜態資料進行加密。如需詳細資訊，請參閱設定績效詳情 AWS AWS KMS 的政策。

## 修改執行個體時啟用和停用
<a name="performance-insights-enabling-modify-instance"></a>

您可以使用 主控台或 修改資料庫執行個體來啟用或停用績效詳情 AWS CLI。

------
#### [ Using the AWS 管理主控台 ]

**主控台指示**

1. 登入 AWS 管理主控台，並在 https：//[https://console.aws.amazon.com/docdb](https://console.aws.amazon.com/docdb) 開啟 Amazon DocumentDB 主控台。

1. 選擇 **Clusters (叢集)**。

1. 選擇資料庫執行個體，然後選擇 **修改 (Modify)**。

1. 在績效詳情區段中，選擇**啟用績效詳情**或**停用績效詳情**。
**注意**  
如果您選擇**啟用績效詳情**，您可以指定您的 AWS AWS KMS 金鑰。Performance Insights 會使用 AWS KMS 金鑰加密所有潛在的敏感資料。將會對傳輸中與靜態資料進行加密。如需詳細資訊，請參閱[加密靜態 Amazon DocumentDB 資料](https://docs.aws.amazon.com/documentdb/latest/developerguide/encryption-at-rest.html)。

1. 選擇 **Continue** (繼續)。

1. 在 **Scheduling of Modifications (修改排程)** 中，選擇 **Apply immediately (立即套用)**。如果您在**下一個排定的維護時段選擇套用**，您的執行個體會忽略此設定，並立即啟用績效詳情。

1. 選擇 **Modify instance (修改執行個體)**。

------
#### [ Using the AWS CLI ]

使用 `create-db-instance`或 `modify-db-instance` AWS AWS CLI 命令時，您可以透過指定 來啟用績效詳情`--enable-performance-insights`，或透過指定 來停用它`--no-enable-performance-insights`。

下列程序說明如何使用 AWS AWS CLI啟用或停用資料庫執行個體的績效詳情。



**AWS AWS CLI 指示**

呼叫 `modify-db-instance` AWS AWS CLI 命令並提供下列值：
+ `--db-instance-identifer` — 資料庫執行個體的名稱
+ `--enable-performance-insights` 以啟用或 `--no-enable-performance-insights` 以停用

**Example**  
下列範例會啟用 的績效詳情`sample-db-instance`：  

```
aws docdb modify-db-instance \
    --db-instance-identifier sample-db-instance \
    --enable-performance-insights
```

```
aws docdb modify-db-instance ^
    --db-instance-identifier sample-db-instance ^
    --enable-performance-insights
```

------

# 設定績效詳情的存取政策
<a name="performance-insights-policies"></a>

若要存取績效詳情，您必須具有來自 AWS Identity and Access Management (IAM) 的適用許可。您可以使用下列選項授予存取權：
+ 將 `AmazonRDSPerformanceInsightsReadOnly` 受管政策連接到許可集或角色。
+ 建立自訂 IAM 政策，並將其連接至許可集或角色。

此外，如果您在開啟績效詳情時指定客戶受管金鑰，請確保您帳戶中的使用者具備 KMS 金鑰的 `kms:Decrypt` 和 `kms:GenerateDataKey` 許可。

**注意**  
對於使用 AWS KMS 金鑰和安全群組管理encryption-at-rest，Amazon DocumentDB 會利用與 [Amazon RDS](https://aws.amazon.com/rds) 共用的操作技術。

## 將 AmazonRDSPerformanceInsightsReadOnly 政策連接至 IAM 主體
<a name="USER_PerfInsights.access-control.IAM-principal"></a>

`AmazonRDSPerformanceInsightsReadOnly` 是一種 AWS受管政策，可授予 Amazon DocumentDB Performance Insights API 所有唯讀操作的存取權。目前，此 API 中的所有操作都是唯讀操作。若您將 `AmazonRDSPerformanceInsightsReadOnly` 連接至許可集或角色，收件人可使用績效詳情搭配其他主控台功能。

## 建立績效詳情的自訂 IAM 政策
<a name="USER_PerfInsights.access-control.custom-policy"></a>

對於沒有 `AmazonRDSPerformanceInsightsReadOnly` 政策提供的使用者，您可以建立或修改由使用者管理的 IAM 政策來授予績效詳情的存取權。當您將政策連接到許可集或角色時，收件人可以使用績效詳情。

**建立自訂政策**

1. 前往 [https://console.aws.amazon.com/iam/](https://console.aws.amazon.com/iam/) 開啟 IAM 主控台。

1. 在導覽窗格中，選擇**政策**。

1. 選擇 **Create policy** (建立政策)。

1. 在 **Create Policy (建立政策)** 頁面上，選擇 JSON 標籤。

1. 複製並貼上下列文字，將 *us-east-1* 取代為您的 AWS 區域名稱，並將 *111122223333* 取代為您的客戶帳戶號碼。

------
#### [ JSON ]

****  

   ```
   {
       "Version":"2012-10-17",		 	 	 
       "Statement": [
           {
               "Effect": "Allow",
               "Action": "rds:DescribeDBInstances",
               "Resource": "*"
           },
           {
               "Effect": "Allow",
               "Action": "rds:DescribeDBClusters",
               "Resource": "*"
           },
           {
               "Effect": "Allow",
               "Action": "pi:DescribeDimensionKeys",
               "Resource": "arn:aws:pi:us-east-1:111122223333:metrics/rds/*"
           },
           {
               "Effect": "Allow",
               "Action": "pi:GetDimensionKeyDetails",
               "Resource": "arn:aws:pi:us-east-1:111122223333:metrics/rds/*"
           },
           {
               "Effect": "Allow",
               "Action": "pi:GetResourceMetadata",
               "Resource": "arn:aws:pi:us-east-1:111122223333:metrics/rds/*"
           },
           {
               "Effect": "Allow",
               "Action": "pi:GetResourceMetrics",
               "Resource": "arn:aws:pi:us-east-1:111122223333:metrics/rds/*"
           },
           {
               "Effect": "Allow",
               "Action": "pi:ListAvailableResourceDimensions",
               "Resource": "arn:aws:pi:us-east-1:111122223333:metrics/rds/*"
           },
           {
               "Effect": "Allow",
               "Action": "pi:ListAvailableResourceMetrics",
               "Resource": "arn:aws:pi:us-east-1:111122223333:metrics/rds/*"
           }
       ]
   }
   ```

------

1. 選擇 **Review policy** (檢閱政策)。

1. 為政策提供名稱並選擇性輸入描述，然後選擇 **Create policy (建立政策)**。

現在您可以將政策連接到許可集或角色。以下程序假設您已有基於此用途使用的使用者。

**將政策連接至使用者**

1. 在以下網址開啟 IAM 主控台：[https://console.aws.amazon.com/iam/](https://console.aws.amazon.com/iam/)。

1. 在導覽窗格中，選擇 **Users** (使用者)。

1. 從清單中選擇現有的使用者。
**重要**  
若要使用績效詳情，請確定除了自訂政策之外，您還可以存取 Amazon DocumentDB。例如，**AmazonDocDBReadOnlyAccess** 預先定義的政策提供 Amazon DocDB.For詳細資訊，請參閱[使用政策管理存取權](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/UsingWithRDS.IAM.html#security_iam_access-manage)。

1. 在 **Summary** (摘要) 頁面上，選擇 **Add permissions** (新增許可)。

1. 選擇 **Attach existing policies directly** (直接連接現有政策)。對於 **Search (搜尋)**，請輸入政策名稱的前幾個字母，如下所示。  
![\[選擇一個政策\]](http://docs.aws.amazon.com/zh_tw/documentdb/latest/developerguide/images/performance-insights/pi-add-permissions.png)

1. 選擇您的政策，然後選擇 **Next: Review (下一步：檢閱)**。

1. 選擇 **Add permissions** (新增許可)。

## 設定 Performance Insights AWS KMS 的政策
<a name="USER_PerfInsights.access-control.cmk-policy"></a>

Performance Insights 使用 AWS KMS key 來加密敏感資料。當您透過 API 或主控台啟用績效詳情時，可使用下列選項：
+ 選擇預設值 AWS 受管金鑰。

  Amazon DocumentDB 會將 AWS 受管金鑰 用於新的資料庫執行個體。Amazon DocumentDB 會 AWS 受管金鑰 為 AWS 您的帳戶建立 。每個 AWS 區域的 Amazon DocumentDB AWS 受管金鑰 AWS 帳戶都有不同的 。
+ 選擇客戶受管金鑰。

  如果您指定客戶受管金鑰，則您帳戶中呼叫績效詳情 API 的使用者需要 KMS 金鑰的 `kms:Decrypt` 和 `kms:GenerateDataKey` 許可。您可以透過 IAM 政策設定這些許可。不過，我們建議您透過 KMS 金鑰政策來管理這些許可。如需詳細資訊，請參閱[在 AWS KMS 中使用金鑰政策](https://docs.aws.amazon.com/kms/latest/developerguide/key-policies.html)。

**Example**  
下列範例金鑰政策說明如何將陳述式新增至 KMS 金鑰政策。這些陳述式允許存取績效詳情。視您使用 的方式而定 AWS KMS，您可能想要變更一些限制。在將陳述式新增至您的政策之前，請先移除所有註解。

# 使用績效詳情儀表板來分析指標
<a name="performance-insights-analyzing"></a>

績效詳情儀表板包含資料庫效能資訊，可協助您分析效能問題並對其進行故障排除。在主儀表板頁面上，您可以檢視資料庫載入 （資料庫載入） 的相關資訊。您可以依等待狀態或查詢等維度來「配量」資料庫負載。

**Topics**
+ [績效詳情儀表板概觀](performance-insights-dashboard-overview.md)
+ [開啟績效詳情儀表板](performance-insights-dashboard-opening.md)
+ [依等待狀態分析資料庫負載](performance-insights-analyzing-db-load.md)
+ [熱門查詢索引標籤概觀](performance-insights-top-queries.md)
+ [在資料庫負載圖表上放大](performance-insights-zoom-db-load.md)

# 績效詳情儀表板概觀
<a name="performance-insights-dashboard-overview"></a>

儀表板是與績效詳情進行互動的最簡單方式。下列範例顯示 Amazon DocumentDB 執行個體的儀表板。根據預設，績效詳情儀表板會顯示過去一小時內的資料。

![\[Performance Insights 儀表板顯示 Amazon DocumentDB 執行個體的 CPU 使用率和資料庫負載隨時間的變化。\]](http://docs.aws.amazon.com/zh_tw/documentdb/latest/developerguide/images/performance-insights/overview-dashboard.png)


儀表板分成下列部分：

1. **計數器指標** – 顯示特定效能計數器指標的資料。

1. **資料庫負載** – 顯示資料庫負載與資料庫執行個體容量的比較，以**最大 vCPU** 行表示。

1.  **最高維**度 - 顯示造成資料庫負載的最高維度。這些維度包括 `waits`、`queries`、`databases`、 `hosts`和 `applications`。

**Topics**
+ [計數器指標圖表](#performance-insights-overview-metrics)
+ [資料庫負載圖表](#performance-insights-overview-db-load-chart)
+ [最高維度表格](#performance-insights-overview-top-dimensions)

## 計數器指標圖表
<a name="performance-insights-overview-metrics"></a>

您可以使用計數器指標來自訂績效詳情儀表板，以包含高達 10 個其它圖表。這些圖表顯示數十種作業系統指標的選擇。您可以將此資訊與資料庫負載相互關聯，以協助識別和分析效能問題。

**Counter Metrics** (計數器指標) 圖表顯示效能計數器的資料。

![\[計數器指標圖表顯示 CPU 使用率隨時間的變化。\]](http://docs.aws.amazon.com/zh_tw/documentdb/latest/developerguide/images/performance-insights/counter-metrics.png)


若要變更效能計數器，請選擇**管理指標**。您可以選取多個**作業系統指標**，如下列螢幕擷取畫面所示。若要查看任何指標的詳細資訊，請將游標移到指標名稱上。

![\[Performance Insights 儀表板指標選擇介面與作業系統指標選項。\]](http://docs.aws.amazon.com/zh_tw/documentdb/latest/developerguide/images/performance-insights/overview-os-metrics.png)


## 資料庫負載圖表
<a name="performance-insights-overview-db-load-chart"></a>

**資料庫負載**圖表顯示資料庫活動與執行個體容量的比較，如**最大 vCPU** 行所表示。依預設，堆疊折線圖以每個時間單位的平均作用中工作階段數來表示資料庫負載。資料庫負載依等待狀態切割 (分組)。

![\[資料庫負載圖表顯示一段時間內的平均作用中工作階段，CPU 用量在接近尾端時爆增。\]](http://docs.aws.amazon.com/zh_tw/documentdb/latest/developerguide/images/performance-insights/database-load.png)


**資料庫負載依維度配量**  
您可以選擇將負載顯示為作用中工作階段 (依任何支援維度分組)。下圖顯示 Amazon DocumentDB 執行個體的維度。

![\[圖表顯示下拉式清單中顯示具有各種「依配量」選項的資料庫載入。\]](http://docs.aws.amazon.com/zh_tw/documentdb/latest/developerguide/images/performance-insights/database-load-sliced.png)


**維度項目的資料庫負載詳細資訊**  
若要查看有關維度內資料庫負載項目的詳細資訊，請將游標移到項目名稱上。下圖顯示查詢陳述式的詳細資訊。

![\[長條圖顯示資料庫載入，並在將滑鼠游標暫留在項目名稱上時顯示其他詳細資訊。\]](http://docs.aws.amazon.com/zh_tw/documentdb/latest/developerguide/images/performance-insights/database-load-details.png)


若要以圖例查看在所選時段內任何項目的詳細資訊，請將游標移到該項目上。

![\[長條圖顯示資料庫載入，並在將游標暫留在長條上時顯示其他詳細資訊。\]](http://docs.aws.amazon.com/zh_tw/documentdb/latest/developerguide/images/performance-insights/database-load-hover.png)


## 最高維度表格
<a name="performance-insights-overview-top-dimensions"></a>

**最高維度資料表**會依不同維度分割資料庫負載。維度是資料庫負載各種特性的類別或「配量依據」。如果維度是查詢，**則熱門查詢**會顯示對資料庫負載貢獻最大的查詢陳述式。

選擇下列任一維度索引標籤：

![\[最高查詢維度索引標籤顯示兩個最高查詢。\]](http://docs.aws.amazon.com/zh_tw/documentdb/latest/developerguide/images/performance-insights/top-dimensions.png)


下表提供每個索引標籤的簡短描述。


| Tab | Description | 
| --- | --- | 
|  最高等待  |   資料庫後端正在等待的事件  | 
|  熱門查詢  |  目前正在執行的查詢陳述式  | 
|  最高主機  |  連線用戶端的主機 IP 和連接埠  | 
|  最高資料庫  |  用戶端連線的資料庫名稱  | 
|  最高應用程式  |  連線至資料庫的應用程式名稱  | 

若要了解如何使用**熱門查詢索引標籤來分析查詢**，請參閱 [熱門查詢索引標籤概觀](performance-insights-top-queries.md)。

# 開啟績效詳情儀表板
<a name="performance-insights-dashboard-opening"></a>

**若要在 AWS 管理主控台中檢視績效詳情儀表板，請使用下列步驟：**

1. 在 https：//[https://console.aws.amazon.com/docdb/](https://console.aws.amazon.com/docdb/home#performance-insights) 開啟績效詳情主控台。

1. 選擇資料庫執行個體。會顯示該 Amazon DocumentDB 執行個體的績效詳情儀表板。

   對於已啟用績效詳情的 Amazon DocumentDB 執行個體，您也可以選擇執行個體清單中的**工作階段**項目來存取儀表板。在 **Current activity (目前活動)** 中，**Sessions (工作階段)** 項目顯示了過去五分鐘內平均作用中工作階段的資料庫負載。負載以進度條圖形的方式顯示。當長條為空時，執行個體會閒置。隨著負載增加，進度條會填入藍色。當負載通過執行個體類別上的虛擬 CPUs vCPUs) 數量時，長條會變成紅色，表示潛在的瓶頸。  
![\[叢集頁面顯示 Amazon DocumentDB 區域叢集，以及每個叢集執行個體的 CPU 和目前活動。\]](http://docs.aws.amazon.com/zh_tw/documentdb/latest/developerguide/images/performance-insights/opening-clusters.png)

1. (選用) 選取右上角中的按鈕，以選擇不同的時間間隔。例如，若要將間隔變更為 1 小時，請選取 **1 小時**。  
![\[時間間隔按鈕範圍從五分鐘到一週。\]](http://docs.aws.amazon.com/zh_tw/documentdb/latest/developerguide/images/performance-insights/opening-time.png)

   在下列螢幕擷取畫面中，資料庫載入間隔為 1 小時。  
![\[長條圖顯示平均作用中工作階段中測量的資料庫負載。\]](http://docs.aws.amazon.com/zh_tw/documentdb/latest/developerguide/images/performance-insights/opening-db-load.png)

1. 若要自動重新整理資料，請啟用**自動重新整理**。  
![\[已啟用自動重新整理按鈕，顯示在時間間隔按鈕旁。\]](http://docs.aws.amazon.com/zh_tw/documentdb/latest/developerguide/images/performance-insights/opening-auto-refresh.png)

   績效詳情儀表板會自動以新資料進行重新整理。重新整理速度取決於顯示的資料量：
   + 5 分鐘的資料每 5 秒重新整理一次。
   + 1 小時內的資料每分鐘重新整理一次。
   + 5 小時內的資料每分鐘重新整理一次。
   + 24 小時內的資料每 5 分鐘重新整理一次。
   + 1 週內的資料每小時重新整理。

# 依等待狀態分析資料庫負載
<a name="performance-insights-analyzing-db-load"></a>

如果**資料庫負載 （資料庫負載）** 圖表顯示瓶頸，您可以找出負載的來源。若要這麼做，請查看**資料庫負載**圖表下的最高負載項目表格。選擇特定項目，例如查詢或應用程式，以深入了解該項目並查看其詳細資訊。

依等待和熱門查詢分組的資料庫負載通常會提供效能問題的最深入見解。根據等待分組的資料庫負載顯示該資料庫中是否有任何資源或正在發生的瓶頸。在此情況下，頂端載入項目資料表的頂端**查詢**索引標籤會顯示哪些查詢正在驅動該載入。

診斷效能問題的典型工作流程如下：

1. 檢閱**資料庫負載**圖表並查看是否有任何資料庫負載超越**最高 CPU** 線的情況。

1. 若有，請查看**資料庫負載**圖表，並找出哪一個或那幾個等待狀態是主因。

1. 透過查看頂端載入項目資料表上的熱門查詢索引標籤對這些等待狀態貢獻最大，**來識別導致載入的摘要查詢**。您可以依**「等待載入 (AAS)」**欄來識別這些項目。

1. 在**熱門查詢**索引標籤中選擇其中一個摘要查詢來展開查詢，並查看由其構成的子查詢。

您也可以分別選取**最高主機或最高應用程式，查看哪些主機**或**應用程式**造成最大負載。應用程式名稱是在 Amazon DocumentDB 執行個體的連線字串中指定。 `Unknown`表示未指定應用程式欄位。

例如，在下列儀表板中，**CPU** 會等待大部分資料庫負載的帳戶。在 最高查詢 下選取**最高查詢** 將限制資料庫負載圖表的範圍，以專注於選取查詢所貢獻的最大負載。

![\[資料庫負載圖表顯示 CPU 用量尖峰。對應的熱門查詢索引標籤會顯示造成等待狀態最多的查詢。\]](http://docs.aws.amazon.com/zh_tw/documentdb/latest/developerguide/images/performance-insights/db-load-1.png)


![\[資料庫負載圖表顯示查詢的 CPU 用量尖峰，造成等待狀態最多。對應的熱門查詢索引標籤會顯示查詢的子查詢。\]](http://docs.aws.amazon.com/zh_tw/documentdb/latest/developerguide/images/performance-insights/db-load-2.png)


# 熱門查詢索引標籤概觀
<a name="performance-insights-top-queries"></a>

根據預設，**頂端查詢**索引標籤會顯示對資料庫載入貢獻最大的查詢。您可以分析查詢文字，以協助調整查詢。

**Topics**
+ [查詢摘要](#performance-insights-top-queries-digests)
+ [依等待分組的負載 (AAS)](#performance-insights-top-queries-aas)
+ [檢視詳細查詢資訊](#performance-insights-top-queries-query-info)
+ [存取陳述式查詢文字](#performance-insights-top-queries-accessing-text)
+ [檢視和下載陳述式查詢文字](#performance-insights-top-queries-viewing-downloading)

## 查詢摘要
<a name="performance-insights-top-queries-digests"></a>

*查詢摘要*是多個實際查詢的複合，這些查詢在結構上類似，但可能有不同的常值。摘要中，問號會取代硬式編碼值。例如，查詢摘要可能如下所示：

```
{"find":"customerscollection","filter":{"FirstName":"?"},"sort":{"key":{"$numberInt":"?"}},"limit":{"$numberInt":"?"}}
```

此摘要可能包含下列子查詢：

```
{"find":"customerscollection","filter":{"FirstName":"Karrie"},"sort":{"key":{"$numberInt":"1"}},"limit":{"$numberInt":"3"}}
{"find":"customerscollection","filter":{"FirstName":"Met"},"sort":{"key":{"$numberInt":"1"}},"limit":{"$numberInt":"3"}}
{"find":"customerscollection","filter":{"FirstName":"Rashin"},"sort":{"key":{"$numberInt":"1"}},"limit":{"$numberInt":"3"}}
```

若要查看摘要中的常值查詢陳述式，請選取查詢，然後選擇加號 (`+`)。在下列螢幕擷取畫面中，所選查詢為摘要。

![\[頂端查詢資料表顯示已擴展的查詢摘要，並選取一個子查詢。\]](http://docs.aws.amazon.com/zh_tw/documentdb/latest/developerguide/images/performance-insights/top-queries-literal.png)


**注意**  
查詢摘要會將類似的查詢陳述式分組，但不會修訂敏感資訊。

## 依等待分組的負載 (AAS)
<a name="performance-insights-top-queries-aas"></a>

在**最高查詢**中，**依等待載入 (AAS)** 欄說明與每個最高載入項目相關聯的資料庫載入百分比。此欄會依目前在**資料庫負載圖表中選取的任何分組來反映該項目的負載**。例如，您可以依等待狀態將 **DB load** (資料庫負載) 圖表分組。在此情況下，**根據等待列出資料庫負載**列較大且分段，並以顏色為代碼來顯示該查詢所帶來的指定等待狀態程度。這也會顯示哪些等待狀態會影響選取的查詢。

![\[長條圖顯示依 CPU、IO 和閂鎖等待狀態分組的資料庫負載。對應的資料表會根據等待的負載顯示最熱門的查詢。\]](http://docs.aws.amazon.com/zh_tw/documentdb/latest/developerguide/images/performance-insights/top-queries-aas.png)


## 檢視詳細查詢資訊
<a name="performance-insights-top-queries-query-info"></a>

在**頂端查詢**表格中，您可以開啟*摘要陳述*式來檢視其資訊。資訊會顯示在底部窗格中。

![\[上方查詢表格顯示選取的查詢陳述式及其查詢資訊如下。\]](http://docs.aws.amazon.com/zh_tw/documentdb/latest/developerguide/images/performance-insights/top-queries-detailed.png)


下列識別符 (IDs) 類型與查詢陳述式相關聯：

1. **支援查詢 ID** – 查詢 ID 的雜湊值。此值僅適用於使用 AWS Support 時參考查詢 ID。 AWS Support 無法存取您的實際查詢 IDs和查詢文字。

1. **支援摘要 ID** – 摘要 ID 的雜湊值。此值僅適用於使用 AWS Support 時參考摘要 ID。 AWS Support 無法存取您的實際摘要 IDs 和查詢文字。

## 存取陳述式查詢文字
<a name="performance-insights-top-queries-accessing-text"></a>

根據預設，**熱門查詢**表格中的每一列都會為每個查詢陳述式顯示 500 個位元組的查詢文字。當摘要陳述式超過 500 個位元組時，您可以在績效詳情儀表板中開啟陳述式來檢視更多文字。在此情況下，所顯示查詢的長度上限為 1 KB。如果您檢視完整的查詢陳述式，您也可以選擇**下載**。

## 檢視和下載陳述式查詢文字
<a name="performance-insights-top-queries-viewing-downloading"></a>

在績效詳情儀表板中，您可以檢視或下載查詢文字。

**在績效詳情儀表板中檢視更多查詢文字**

1. 開啟 Amazon DocumentDB 主控台，網址為：https：//[https://console.aws.amazon.com/docdb/](https://console.aws.amazon.com/docdb/) 

1. 在導覽窗格中，選擇 **Performance Insights** (績效詳情)。

1. 選擇資料庫執行個體。顯示該資料庫執行個體的績效詳情儀表板。

   文字大於 500 個位元組的查詢陳述式看起來如下圖所示：  
![\[選取子查詢的熱門查詢表。\]](http://docs.aws.amazon.com/zh_tw/documentdb/latest/developerguide/images/performance-insights/top-queries-statement.png)

1. 檢查查詢資訊區段以檢視更多查詢文字。  
![\[查詢資訊區段顯示所選查詢的完整文字。\]](http://docs.aws.amazon.com/zh_tw/documentdb/latest/developerguide/images/performance-insights/top-queries-query-text.png)

績效詳情儀表板最多可顯示每個完整查詢陳述式的 1 KB。

**注意**  
若要複製或下載查詢陳述式，請停用任何快顯封鎖程式。

# 在資料庫負載圖表上放大
<a name="performance-insights-zoom-db-load"></a>

您可以使用績效詳情使用者界面的其他功能來協助並分析效能資料。

**長按拖曳來放大**  
在績效詳情界面中，您可以選擇負載圖表的一小部分，並放大詳細資訊。

![\[長條圖顯示資料庫負載，其中一部分會反白顯示以放大。\]](http://docs.aws.amazon.com/zh_tw/documentdb/latest/developerguide/images/performance-insights/pi-zoom-1.png)


若要放大小部分的負載表格，選擇開始時間並拖曳到您想要的時間範圍結束時間。您這麼做的話，所選區域將有反白顯示。當您放開滑鼠時，負載圖表會放大所選區域，並重新計算**最高*項目***表。

![\[資料庫負載長條圖顯示放大部分，下方有對應的最高等待資料表。\]](http://docs.aws.amazon.com/zh_tw/documentdb/latest/developerguide/images/performance-insights/pi-zoom-2.png)


# 使用績效詳情 API 來擷取指標
<a name="performance-insights-metrics"></a>

在啟用績效詳情時，API 會提供對執行個體效能的可見性。Amazon CloudWatch Logs 提供授權來源，以用於 AWS 服務的付費監控指標。

績效詳情提供以平均作用中工作階段 (AAS) 評估的資料庫負載特定網域檢視。此指標在 API 消費者看來是二維時間序列資料集。資料的時間維度提供查詢的時間範圍內各時間點的資料庫負載資料。每個時間點會根據請求的維度來分解整體負載，例如 `Query`、`Wait-state`、`Application`、或者 `Host`，在該時間點所測得。

Amazon DocumentDB Performance Insights 會監控您的 Amazon DocumentDB 資料庫執行個體，讓您可以分析資料庫效能並進行疑難排解。檢視績效詳情資料的一個方法就是使用 AWS 管理主控台。績效詳情也提供公有 API，讓您可以查詢自己的資料。您可以使用 API 執行下列動作：
+ 將資料卸載至資料庫
+ 將績效詳情資料新增至現有監控儀表板
+ 建置監控工具

若要使用績效詳情 API，請在其中一個 Amazon DocumentDB 執行個體上啟用績效詳情。如需啟用績效詳情的相關資訊，請參閱 [啟用和停用績效詳情](performance-insights-enabling.md)。如需績效詳情 API 的相關詳細資訊，請參閱 [ 績效詳情 API 參考](https://docs.aws.amazon.com/performance-insights/latest/APIReference/Welcome.html)。

績效詳情 API 提供下列操作。


****  

|  績效詳情動作  |  AWS CLI 命令  |  Description  | 
| --- | --- | --- | 
|  [https://docs.aws.amazon.com/performance-insights/latest/APIReference/API_DescribeDimensionKeys.html](https://docs.aws.amazon.com/performance-insights/latest/APIReference/API_DescribeDimensionKeys.html)  |  [https://docs.aws.amazon.com/cli/latest/reference/pi/describe-dimension-keys.html](https://docs.aws.amazon.com/cli/latest/reference/pi/describe-dimension-keys.html)  |  針對特定時段，擷取其指標的前 N 個維度金鑰。  | 
|  [https://docs.aws.amazon.com/performance-insights/latest/APIReference/API_GetDimensionKeyDetails.html](https://docs.aws.amazon.com/performance-insights/latest/APIReference/API_GetDimensionKeyDetails.html)  |  [https://docs.aws.amazon.com/cli/latest/reference/pi/get-dimension-key-details.html](https://docs.aws.amazon.com/cli/latest/reference/pi/get-dimension-key-details.html)  |  擷取資料庫執行個體或資料來源之指定維度群組的屬性。例如，如果您指定查詢 ID，而且有可用的維度詳細資訊， 會`GetDimensionKeyDetails`擷取與此 ID `db.query.statement`相關聯的維度全文。此操作非常有用，因為 `GetResourceMetrics`和 `DescribeDimensionKeys` 不支援擷取大型查詢陳述式文字。  | 
| [GetResourceMetadata](https://docs.aws.amazon.com/performance-insights/latest/APIReference/API_GetResourceMetadata.html) |  [https://docs.aws.amazon.com/cli/latest/reference/pi/get-resource-metadata.html](https://docs.aws.amazon.com/cli/latest/reference/pi/get-resource-metadata.html)  |  檢索不同功能的中繼資料。例如，中繼資料可能指出特定資料庫執行個體上某項功能已開啟或關閉。  | 
|  [https://docs.aws.amazon.com/performance-insights/latest/APIReference/API_GetResourceMetrics.html](https://docs.aws.amazon.com/performance-insights/latest/APIReference/API_GetResourceMetrics.html)  |  [https://docs.aws.amazon.com/cli/latest/reference/pi/get-resource-metrics.html](https://docs.aws.amazon.com/cli/latest/reference/pi/get-resource-metrics.html)  |  擷取一組資料來源某個時段的績效詳情指標。您可以提供特定維度群組和維度，以及為每個群組提供彙總和篩選條件。  | 
| [ListAvailableResourceDimensions](https://docs.aws.amazon.com/performance-insights/latest/APIReference/API_ListAvailableResourceDimensions.html) |  [https://docs.aws.amazon.com/cli/latest/reference/pi/list-available-resource-dimensions.html](https://docs.aws.amazon.com/cli/latest/reference/pi/list-available-resource-dimensions.html)  |  檢索指定執行個體上每個指定指標類型可查詢的維度。  | 
| [ListAvailableResourceMetrics](https://docs.aws.amazon.com/performance-insights/latest/APIReference/API_ListAvailableResourceMetrics.html) |  [https://docs.aws.amazon.com/cli/latest/reference/pi/list-available-resource-metrics.html](https://docs.aws.amazon.com/cli/latest/reference/pi/list-available-resource-metrics.html)  |  檢索可為指定資料庫執行個體查詢的指定指標類型中所有可用的指標。  | 

**Topics**
+ [AWS CLI for Performance Insights](#performance-insights-metrics-CLI)
+ [擷取時間序列指標](#performance-insights-metrics-time-series)
+ [AWS CLI 績效詳情的範例](#performance-insights-metrics-api-examples)

## AWS CLI for Performance Insights
<a name="performance-insights-metrics-CLI"></a>

您可以使用 AWS CLI檢視績效詳情資料。您可以透過在命令列輸入以下內容來檢視績效詳情 AWS CLI 命令的說明。

```
aws pi help
```

如果您尚未 AWS CLI 安裝 ，請參閱*AWS CLI 《 使用者指南*》中的[安裝 AWS 命令列界面](https://docs.aws.amazon.com/cli/latest/userguide/installing.html)，以取得安裝它的相關資訊。

## 擷取時間序列指標
<a name="performance-insights-metrics-time-series"></a>

`GetResourceMetrics` 操作會從績效詳情資料中擷取一或多個時間時間序列指標。`GetResourceMetrics` 需要指標和時間間隔，並傳回含資料點清單的回應。

例如， AWS 管理主控台 使用 `GetResourceMetrics` 填入**計數器指標**圖表和**資料庫負載**圖表，如下圖所示。

![\[計數器指標和資料庫負載圖表\]](http://docs.aws.amazon.com/zh_tw/documentdb/latest/developerguide/images/performance-insights/perf-insights-api-charts.png)


`GetResourceMetrics` 傳回的所有指標，除 `db.load` 之外，皆為標準的時間序列指標。此指標會顯示在 **Database Load (資料庫負載)** 圖表中。`db.load` 指標與其他時間序列指標不同，因為您可以將它分為名為*維度*的子元件。在先前的影像中，`db.load` 已被細分，分組依據為組成 `db.load` 的等待狀態。

**注意**  
`GetResourceMetrics` 也可以傳回 `db.sampleload` 指標，但 `db.load` 指標適用於大部分情況。

如需 `GetResourceMetrics` 所傳回指標的相關資訊，請參閱[計數器指標的績效詳情](performance-insights-counter-metrics.md)。

這些指標支援下列計算：
+ 平均值 – 指標在一段時間內的平均值。將 `.avg` 附加至指標名稱。
+ 最小值 – 指標在一段時間內的最小值。將 `.min` 附加至指標名稱。
+ 最大值 – 指標在一段時間內的最大值。將 `.max` 附加至指標名稱。
+ 總和 – 指標值在一段時間內的總和。將 `.sum` 附加至指標名稱。
+ 取樣計數 – 在一段時間內收集指標的次數。將 `.sample_count` 附加至指標名稱。

例如，假設收集指標的時間為 300 秒 (5 分鐘)，且每分鐘收集一次指標。每分鐘的值為 1、2、3、4 和 5。在此情況下，會傳回下列計算：
+ 平均值 – 3
+ 最小值 – 1
+ 最大值 – 5
+ 總和 – 15
+ 取樣計數 – 5

如需使用 `get-resource-metrics` AWS CLI 命令的詳細資訊，請參閱 [https://docs.aws.amazon.com/cli/latest/reference/pi/get-resource-metrics.html](https://docs.aws.amazon.com/cli/latest/reference/pi/get-resource-metrics.html)。

對於 `--metric-queries` 選項，請指定您要取得結果的一或多個查詢。每個查詢的組成為必要的 `Metric` 和選用的 `GroupBy` 及 `Filter` 參數。以下是 `--metric-queries` 選項規格的範例。

```
{
   "Metric": "string",
   "GroupBy": {
     "Group": "string",
     "Dimensions": ["string", ...],
     "Limit": integer
   },
   "Filter": {"string": "string"
     ...}
```

## AWS CLI 績效詳情的範例
<a name="performance-insights-metrics-api-examples"></a>

下列範例示範如何使用 AWS CLI for Performance Insights 的 。

**Topics**
+ [擷取計數器指標](#performance-insights-metrics-api-examples.CounterMetrics)
+ [擷取最高等待狀態的資料庫負載平均值](#performance-insights-metrics-api-examples.DBLoadAverage)
+ [擷取熱門查詢的資料庫負載平均值](#performance-insights-metrics-api-examples.topquery)
+ [擷取依查詢篩選的資料庫負載平均值](#performance-insights-metrics-api-examples.DBLoadAverageByQuery)

### 擷取計數器指標
<a name="performance-insights-metrics-api-examples.CounterMetrics"></a>

下列螢幕擷取畫面顯示 AWS 管理主控台中的兩個計數器指標圖表。

![\[計數器指標圖表。\]](http://docs.aws.amazon.com/zh_tw/documentdb/latest/developerguide/images/performance-insights/perf-insights-api-counters-charts.png)


下凸顯是如何蒐集 AWS 管理主控台 用來產生兩個計數器指標圖表的相同資料。

針對 Linux、macOS 或 Unix：

```
aws pi get-resource-metrics \
   --service-type DOCDB \
   --identifier db-ID \
   --start-time 2022-03-13T8:00:00Z \
   --end-time   2022-03-13T9:00:00Z \
   --period-in-seconds 60 \
   --metric-queries '[{"Metric": "os.cpuUtilization.user.avg"  },
                      {"Metric": "os.cpuUtilization.idle.avg"}]'
```

針對 Windows：

```
aws pi get-resource-metrics ^
   --service-type DOCDB ^
   --identifier db-ID ^
   --start-time 2022-03-13T8:00:00Z ^
   --end-time   2022-03-13T9:00:00Z ^
   --period-in-seconds 60 ^
   --metric-queries '[{"Metric": "os.cpuUtilization.user.avg"  },
                      {"Metric": "os.cpuUtilization.idle.avg"}]'
```

您也可以透過指定 `--metrics-query` 選項的檔案來提高命令的可讀性。以下範例會將名為 query.json 的檔案用於此選項。此檔案的內容如下。

```
[
    {
        "Metric": "os.cpuUtilization.user.avg"
    },
    {
        "Metric": "os.cpuUtilization.idle.avg"
    }
]
```

執行下列命令來使用檔案。

針對 Linux、macOS 或 Unix：

```
aws pi get-resource-metrics \
   --service-type DOCDB \
   --identifier db-ID \
   --start-time 2022-03-13T8:00:00Z \
   --end-time   2022-03-13T9:00:00Z \
   --period-in-seconds 60 \
   --metric-queries file://query.json
```

針對 Windows：

```
aws pi get-resource-metrics ^
   --service-type DOCDB ^
   --identifier db-ID ^
   --start-time 2022-03-13T8:00:00Z ^
   --end-time   2022-03-13T9:00:00Z ^
   --period-in-seconds 60 ^
   --metric-queries file://query.json
```

先前的範例會為選項指定下列值：
+ `--service-type` – `DOCDB`適用於 Amazon DocumentDB
+ `--identifier`– 資料執行個體的資源 ID
+ `--start-time` 和 `--end-time` – 要查詢期間的 ISO 8601 `DateTime` 值，支援多種格式

它會查詢一小時的時間範圍：
+ `--period-in-seconds`–`60` 適用於每分鐘的查詢
+ `--metric-queries`– 兩個查詢的陣列，一個指標剛好一個查詢。

  此指標名稱會使用點將指標分類在實用的類別，其中最後一個元素則做為函數。在此範例中，此函數是每個查詢的 `avg`。如同 Amazon CloudWatch，支援的函數是 `min`、`max`、`total` 和 `avg`。

回應看起來類似以下的內容。

```
{
    "AlignedStartTime": "2022-03-13T08:00:00+00:00",
    "AlignedEndTime": "2022-03-13T09:00:00+00:00",
    "Identifier": "db-NQF3TTMFQ3GTOKIMJODMC3KQQ4",
    "MetricList": [
        {
            "Key": {
                "Metric": "os.cpuUtilization.user.avg"
            },
            "DataPoints": [
                {
                    "Timestamp": "2022-03-13T08:01:00+00:00", //Minute1
                    "Value": 3.6
                },
                {
                    "Timestamp": "2022-03-13T08:02:00+00:00", //Minute2
                    "Value": 2.6
                },
                //.... 60 datapoints for the os.cpuUtilization.user.avg metric
        {
            "Key": {
                "Metric": "os.cpuUtilization.idle.avg"
            },
            "DataPoints": [
                {
                    "Timestamp": "2022-03-13T08:01:00+00:00",
                    "Value": 92.7
                },
                {
                    "Timestamp": "2022-03-13T08:02:00+00:00",
                    "Value": 93.7
                },
                //.... 60 datapoints for the os.cpuUtilization.user.avg metric 
            ]
        }
    ] //end of MetricList
} //end of response
```

回應具有 `Identifier`、`AlignedStartTime` 和 `AlignedEndTime`。`--period-in-seconds` 值為 `60`，開始和結束時間皆一致使用分鐘。如果 `--period-in-seconds` 是 `3600`，開始和結束時間則會一致使用小時。

回應中的 `MetricList` 擁有許多項目，每個都包含 `Key` 和 `DataPoints` 項目。每個 `DataPoint` 都有 `Timestamp` 和 `Value`。每個 `Datapoints` 清單有 60 個資料點，因為查詢是適用於一小時中的每分鐘資料，內含 `Timestamp1/Minute1`、`Timestamp2/Minute2` 等，最多可達 `Timestamp60/Minute60`。

因為此查詢是適用於兩個不同的計數器指標，回應 `MetricList` 中會有兩個元素。

### 擷取最高等待狀態的資料庫負載平均值
<a name="performance-insights-metrics-api-examples.DBLoadAverage"></a>

下列範例與 AWS 管理主控台 用來產生堆疊區域折線圖的查詢相同。此範例會擷取最後一個小時`db.load.avg`的 根據前七個等待狀態分割負載的 。此命令與 [擷取計數器指標](#performance-insights-metrics-api-examples.CounterMetrics) 中的命令相同。然而，查詢 query.json 檔案有以下內容。

```
[
    {
        "Metric": "db.load.avg",
        "GroupBy": { "Group": "db.wait_state", "Limit": 7 }
    }
]
```

執行下列命令。

針對 Linux、macOS 或 Unix：

```
aws pi get-resource-metrics \
   --service-type DOCDB \
   --identifier db-ID \
   --start-time 2022-03-13T8:00:00Z \
   --end-time   2022-03-13T9:00:00Z \
   --period-in-seconds 60 \
   --metric-queries file://query.json
```

針對 Windows：

```
aws pi get-resource-metrics ^
   --service-type DOCDB ^
   --identifier db-ID ^
   --start-time 2022-03-13T8:00:00Z ^
   --end-time   2022-03-13T9:00:00Z ^
   --period-in-seconds 60 ^
   --metric-queries file://query.json
```

此範例會指定 的指標，`db.load.avg`以及前七大等待狀態`GroupBy`的 。如需此範例有效值的詳細資訊，請參閱*績效詳情 API 參考*中的[DimensionGroup](https://docs.aws.amazon.com/performance-insights/latest/APIReference/API_DimensionGroup.html)。

回應看起來類似以下的內容。

```
{
    "AlignedStartTime": "2022-04-04T06:00:00+00:00",
    "AlignedEndTime": "2022-04-04T06:15:00+00:00",
    "Identifier": "db-NQF3TTMFQ3GTOKIMJODMC3KQQ4",
    "MetricList": [
        {//A list of key/datapoints
            "Key": {
                //A Metric with no dimensions. This is the total db.load.avg
                "Metric": "db.load.avg"
            },
            "DataPoints": [
                //Each list of datapoints has the same timestamps and same number of items
                {
                    "Timestamp": "2022-04-04T06:01:00+00:00",//Minute1
                    "Value": 0.0
                },
                {
                    "Timestamp": "2022-04-04T06:02:00+00:00",//Minute2
                    "Value": 0.0
                },
                //... 60 datapoints for the total db.load.avg key
                ]
        },
        {
            "Key": {
                //Another key. This is db.load.avg broken down by CPU
                "Metric": "db.load.avg",
                "Dimensions": {
                    "db.wait_state.name": "CPU"
                }
            },
            "DataPoints": [
                {
                    "Timestamp": "2022-04-04T06:01:00+00:00",//Minute1
                    "Value": 0.0
                },
                {
                    "Timestamp": "2022-04-04T06:02:00+00:00",//Minute2
                    "Value": 0.0
                },
                //... 60 datapoints for the CPU key
            ]
        },//... In total we have 3 key/datapoints entries, 1) total, 2-3) Top Wait States
    ] //end of MetricList
} //end of response
```

在此回應中， 中有三個項目`MetricList`。總計 有一個項目`db.load.avg`，根據前三個等待狀態之一`db.load.avg`分割的 有三個項目。由於有分組維度 （與第一個範例不同），因此指標的每個分組都必須有一個索引鍵。每個指標不能只有一個索引鍵，如同基本計數器指標使用案例。

### 擷取熱門查詢的資料庫負載平均值
<a name="performance-insights-metrics-api-examples.topquery"></a>

下列範例`db.wait_state`依前 10 個查詢陳述式分組。查詢陳述式有兩種不同的群組：
+ `db.query` – 完整的查詢陳述式，例如 `{"find":"customers","filter":{"FirstName":"Jesse"},"sort":{"key":{"$numberInt":"1"}}}`
+ `db.query_tokenized` – 字符化查詢陳述式，例如 `{"find":"customers","filter":{"FirstName":"?"},"sort":{"key":{"$numberInt":"?"}},"limit":{"$numberInt":"?"}}`

分析資料庫效能時，將僅因參數而不同的查詢陳述式視為一個邏輯項目非常有用。因此，您可以在查詢時使用 `db.query_tokenized`。不過，特別是當您對 感興趣時`explain()`，有時使用參數檢查完整的查詢陳述式會比較有用。字符化查詢與完整查詢之間存在父子關係，多個完整查詢 （子） 分組在相同的字符化查詢 （父） 下。

此範例中的命令與 [擷取最高等待狀態的資料庫負載平均值](#performance-insights-metrics-api-examples.DBLoadAverage) 中的命令類似。然而，查詢 query.json 檔案有以下內容。

```
[
    {
        "Metric": "db.load.avg",
        "GroupBy": { "Group": "db.query_tokenized", "Limit": 10 }
    }
]
```

以下範例使用 `db.query_tokenized`。

針對 Linux、macOS 或 Unix：

```
aws pi get-resource-metrics \
   --service-type DOCDB \
   --identifier db-ID \
   --start-time 2022-03-13T8:00:00Z \
   --end-time   2022-03-13T9:00:00Z \
   --period-in-seconds 3600 \
   --metric-queries file://query.json
```

針對 Windows：

```
aws pi get-resource-metrics ^
   --service-type DOCDB ^
   --identifier db-ID ^
   --start-time 2022-03-13T8:00:00Z ^
   --end-time   2022-03-13T9:00:00Z  ^
   --period-in-seconds 3600 ^
   --metric-queries file://query.json
```

此範例查詢時間超過 1 小時，且間隔為一分鐘period-in-seconds

此範例會指定 的指標，`db.load.avg`以及前七大等待狀態`GroupBy`的 。如需此範例有效值的詳細資訊，請參閱*績效詳情 API 參考*中的[DimensionGroup](https://docs.aws.amazon.com/performance-insights/latest/APIReference/API_DimensionGroup.html)。

回應看起來類似以下的內容。

```
{
    "AlignedStartTime": "2022-04-04T06:00:00+00:00",
    "AlignedEndTime": "2022-04-04T06:15:00+00:00",
    "Identifier": "db-NQF3TTMFQ3GTOKIMJODMC3KQQ4",
    "MetricList": [
        {//A list of key/datapoints
            "Key": {
                "Metric": "db.load.avg"
            },
            "DataPoints": [
                //... 60 datapoints for the total db.load.avg key
                ]
        },
               {
            "Key": {//Next key are the top tokenized queries
                "Metric": "db.load.avg",
                "Dimensions": {
                    "db.query_tokenized.db_id": "pi-1064184600",
                    "db.query_tokenized.id": "77DE8364594EXAMPLE",
                    "db.query_tokenized.statement": "{\"find\":\"customers\",\"filter\":{\"FirstName\":\"?\"},\"sort\":{\"key\":{\"$numberInt\":\"?\"}},\"limit\"
:{\"$numberInt\":\"?\"},\"$db\":\"myDB\",\"$readPreference\":{\"mode\":\"primary\"}}"
                }
            },
            "DataPoints": [
            //... 60 datapoints 
            ]
        },
        // In total 11 entries, 10 Keys of top tokenized queries, 1 total key 
    ] //End of MetricList
} //End of response
```

此回應在 中有 11 個項目 `MetricList`（總計 1 個，最多 10 個字符化查詢），每個項目每小時 24 個`DataPoints`。

對於字符化查詢，每個維度清單中有三個項目：
+ `db.query_tokenized.statement` – 字符化查詢陳述式。
+ `db.query_tokenized.db_id ` – Performance Insights 為您產生的合成 ID。此範例會傳回 `pi-1064184600` 合成 ID。
+ `db.query_tokenized.id`– 績效詳情中查詢的 ID。

  在 中 AWS 管理主控台，此 ID 稱為支援 ID。其名稱為這個，因為 ID 是 AWS Support 可以檢查的資料，以協助您對資料庫的問題進行疑難排解。 非常重視資料 AWS 的安全性和隱私權，而且幾乎所有資料都會以您的 加密儲存 AWS KMS key。因此，內部沒有人 AWS 可以查看此資料。在先前的範例中，`tokenized.statement` 和 `tokenized.db_id` 都同時會以加密的形式存放。如果您的資料庫發生問題， AWS Support 可以透過參考支援 ID 來協助您。

進行查詢時，在 `Group` 中指定 `GroupBy` 可能會讓您省下不少心力。然而，如需對已傳回的資料進行更精細的控制，請指定維度的清單。例如，如果所需的是 `db.query_tokenized.statement`，則可將 `Dimensions` 屬性新增至 query.json 檔案。

```
[
    {
        "Metric": "db.load.avg",
        "GroupBy": {
            "Group": "db.query_tokenized",
            "Dimensions":["db.query_tokenized.statement"],
            "Limit": 10
        }
    }
]
```

### 擷取依查詢篩選的資料庫負載平均值
<a name="performance-insights-metrics-api-examples.DBLoadAverageByQuery"></a>

此範例中的對應 API 查詢與 [擷取熱門查詢的資料庫負載平均值](#performance-insights-metrics-api-examples.topquery) 中的命令類似。然而，查詢 query.json 檔案有以下內容。

```
[
 {
        "Metric": "db.load.avg",
        "GroupBy": { "Group": "db.wait_state", "Limit": 5  }, 
        "Filter": { "db.query_tokenized.id": "AKIAIOSFODNN7EXAMPLE" }
    }
]
```

在此回應中，會根據 query.json 檔案中指定的字符化查詢 AKIAIOSFODNN7EXAMPLE 貢獻來篩選所有值。金鑰也可能遵循與沒有篩選條件的查詢不同的順序，因為這是影響篩選查詢的前五個等待狀態。

# Performance Insights 的 Amazon CloudWatch 指標
<a name="performance-insights-cloudwatch"></a>

績效詳情會自動將指標發佈至 Amazon CloudWatch。您可以透過績效詳情來查詢相同的資料，但在 CloudWatch 中具備這些指標可讓您輕鬆新增 CloudWatch 警示。您也可以輕鬆將指標新增至現有的 CloudWatch 儀表板。


| 指標 | 描述 | 
| --- | --- | 
|  DBLoad  |  Amazon DocumentDB 的作用中工作階段數目。您通常會需要平均作用中工作階段數量的資料。在績效詳情中，系統會以 `db.load.avg` 的形式來查詢此資料。  | 
|  DBLoadCPU  |  等待狀態類型為 CPU 的作用中工作階段數目。在績效詳情中，此資料會查詢為 `db.load.avg`，並依等待狀態類型 篩選`CPU`。  | 
|  DBLoadNonCPU  |  等待狀態類型不是 CPU 的作用中工作階段數量。  | 

**注意**  
只有當資料庫執行個體上有負載時，這些指標才會發佈至 CloudWatch。

您可以使用 CloudWatch 主控台、 AWS CLI或 CloudWatch API 來檢查這些指標。

例如，您可以執行 [get-metric-statistics](https://docs.aws.amazon.com/cli/latest/reference/cloudwatch/get-metric-statistics.html) 命令來取得 `DBLoad` 指標的統計。

```
aws cloudwatch get-metric-statistics \
    --region ap-south-1 \
    --namespace AWS/DocDB \
    --metric-name DBLoad  \
    --period 360 \
    --statistics Average \
    --start-time 2022-03-14T8:00:00Z \
    --end-time 2022-03-14T9:00:00Z \
    --dimensions Name=DBInstanceIdentifier,Value=documentdbinstance
```

此範例會產生類似下列範例的輸出結果。

```
{
    "Datapoints": [
        {
            "Timestamp": "2022-03-14T08:42:00Z", 
            "Average": 1.0, 
            "Unit": "None"
        }, 
        {
            "Timestamp": "2022-03-14T08:24:00Z", 
            "Average": 2.0, 
            "Unit": "None"
        }, 
        {
            "Timestamp": "2022-03-14T08:54:00Z", 
            "Average": 6.0, 
            "Unit": "None"
        }, 
        {
            "Timestamp": "2022-03-14T08:36:00Z", 
            "Average": 5.7, 
            "Unit": "None"
        }, 
        {
            "Timestamp": "2022-03-14T08:06:00Z", 
            "Average": 4.0, 
            "Unit": "None"
        }, 
        {
            "Timestamp": "2022-03-14T08:00:00Z", 
            "Average": 5.2, 
            "Unit": "None"
        }
    ], 
    "Label": "DBLoad"
}
```

您可以使用 CloudWatch 主控台中的`DB_PERF_INSIGHTS`指標數學函數來查詢 Amazon DocumentDB Performance Insights 計數器指標。`DB_PERF_INSIGHTS` 函數也包含以次分鐘為間隔的 `DBLoad` 指標。您可以根據這些指標設定 CloudWatch 警示。如需如何建立警示的詳細資訊，請參閱[從 AWS 資料庫在績效詳情計數器指標上建立警示](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/CloudWatch_alarm_database_performance_insights.html)。

如需 CloudWatch 的詳細資訊，請參閱 *Amazon CloudWatch 使用者指南*中的[什麼是 Amazon CloudWatch？](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/WhatIsCloudWatch.html)。

# 計數器指標的績效詳情
<a name="performance-insights-counter-metrics"></a>

計數器指標是績效詳情儀表板中的作業系統指標。若要協助識別並分析效能問題，您可以將計數器指標與資料庫負載相互關聯。

## 績效詳情作業系統計數器
<a name="performance-insights-counter-metrics-counters"></a>

Amazon DocumentDB Performance Insights 提供下列作業系統計數器。


| 計數器 | 類型 | 指標 | 
| --- | --- | --- | 
| 作用中 | memory | os.memory.active | 
| buffers | memory | os.memory.buffers | 
| cached | memory | os.memory.cached | 
| dirty | memory | os.memory.dirty | 
| free | memory | os.memory.free | 
| inactive | memory | os.memory.inactive | 
| mapped | memory | os.memory.mapped | 
| pageTables | memory | os.memory.pageTables | 
| slab | memory | os.memory.slab | 
| total | memory | os.memory.total | 
| writeback | memory | os.memory.writeback | 
| idle | cpuUtilization | os.cpuUtilization.idle | 
| system | cpuUtilization | os.cpuUtilization.system | 
| total | cpuUtilization | os.cpuUtilization.total | 
| user | cpuUtilization | os.cpuUtilization.user | 
| wait | cpuUtilization | os.cpuUtilization.wait | 
| one | loadAverageMinute | os.loadAverageMinute.one | 
| fifteen | loadAverageMinute | os.loadAverageMinute.fifteen | 
| five | loadAverageMinute | os.loadAverageMinute.five | 
| cached | 交換 | os.swap.cached | 
| free | 交換 | os.swap.free | 
| in | 交換 | os.swap.in | 
| out | 交換 | os.swap.out | 
| total | 交換 | os.swap.total | 
| rx | 網路 | os.network.rx | 
| tx | 網路 | os.network.tx | 
| numVCPUs | 一般 | os.general.numVCPUs | 