本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。
適用於 DynamoDB 的 CloudWatch Contributor Insights 入門
本節說明如何在不同模式下啟用和使用 Amazon CloudWatch Contributor Insights,以使用 Amazon DynamoDB 主控台或 AWS Command Line Interface () 滿足您的監控需求AWS CLI。
在下列範例中,您會用到 DynamoDB 入門教學課程中定義的資料表。
選擇 Contributor Insights 模式
在啟用 Contributor Insights 之前,您應該了解兩種可用的模式。檢閱模式比較,以選取最符合您特定需求的選項。
| Aspect | 存取和限流金鑰模式 | 調節鍵模式 |
|---|---|---|
| 監視器 | 所有請求 (成功和限流) | 僅限流請求 |
| 圖表 | 存取最多的項目 + 調節最多的項目 | 僅限大多數調節項目 |
| 最適合 | 目標分析和最佳化 | 調節監控 |
| 使用時機 | 您需要完全了解存取模式。您正在執行短期分析或偵錯。 | 您的主要考量是識別和解決限流問題。您想要持續啟用 Contributor Insights 以即時調節警示。 |
使用 Contributor Insights (主控台)
主控台提供直覺式的方式來啟用 Contributor Insights,並為您的監控需求選取適當的模式。
在主控台中使用 Contributor Insights
登入 AWS Management Console ,並在 https://https://console.aws.amazon.com/dynamodb/
開啟 DynamoDB 主控台。 -
在主控台左側的導覽窗格中,選擇 Tables (資料表)。
-
選擇
Music資料表。 -
選擇 監控 索引標籤。
-
選擇開啟 CloudWatch Contributor Insights。
-
在管理 CloudWatch Contributor Insights 設定對話方塊中,為
Music基底資料表和AlbumTitle-index全域次要索引切換開啟。 -
將僅限調節索引鍵模式開關保留在兩者的關閉位置,然後選擇儲存變更。
這會啟用資料表和 GSI 的預設存取和調節金鑰模式,這可提供存取和調節項目的監控。將僅限調節金鑰模式切換到開啟位置會啟用調節金鑰模式。
如果操作失敗,請參閱《Amazon DynamoDB API 參考》中的 DescribeContributorInsights FailureException 找出可能的原因。
-
CloudWatch Contributor Insights 圖形現在會顯示在
Music資料表的監控索引標籤上。由於您已啟用存取和限流金鑰模式,因此您會看到存取和限流項目圖表。
在模式之間切換
您可以隨時在模式之間切換,而無需停用 Contributor Insights。
切換 Contributor Insights 模式
-
在資料表的監控索引標籤上,選擇管理 CloudWatch Contributor Insights。
-
在管理 Contributor Insights 設定對話方塊中,針對每個基礎資料表或 GSIs:
-
開啟或關閉僅限限流金鑰模式,以啟用限流金鑰模式,或返回預設的存取和限流金鑰模式。
-
切換關閉以停用資料表或 GSI 的 CloudWatch Contributor Insight。
-
-
選擇儲存變更。
完成後,圖形將反映新模式。
建立 CloudWatch 警示
請依照下列步驟建立 CloudWatch 警示,並在任何分割區索引鍵使用超過 50,000 個 ConsumedThroughputUnits 或遇到限流時收到通知。
-
登入 AWS Management Console ,並在 https://https://console.aws.amazon.com/cloudwatch/
開啟 CloudWatch 主控台 -
在主控台左側的導覽窗格中,選擇 Contributor Insights。
-
根據您的模式和您要監控的內容,選擇適當的規則:
-
針對存取的項目監控 (僅限存取和限流金鑰模式):選擇 DynamoDBContributorInsights-PKC-Music
-
對於限流項目監控 (兩種模式):選擇 DynamoDBContributorInsights-PKT-Music
-
-
選擇 Actions (動作) 下拉式功能表。
-
選擇 View in metrics (在指標中檢視)。
-
選擇 Max Contributor Value (作者值上限)。
注意
只有
Max Contributor Value和Maximum會傳回有用的統計數字。此清單中的其他統計數字不會傳回有意義的值。
-
在 Actions (動作) 欄中,選擇 Create Alarm (建立警示)。
-
輸入適當的閾值,然後選擇下一步:
-
對於存取的項目 (PKC 規則):輸入 50000
ConsumedThroughputUnits -
對於限流項目 (PKT 規則):輸入 1
ThrottleCount讓 在任何限流時收到提醒
-
-
如需如何設定警示通知的詳細資訊,請參閱使用 Amazon CloudWatch 警示。
使用 Contributor Insights (AWS CLI)
AWS CLI 提供對 Contributor Insights 的程式設計存取,並完整支援這兩種模式。您可以在啟用 Contributor Insights 或稍後切換模式時指定 模式。
預設模式的基本操作
使用具有預設設定的 Contributor Insights
-
使用存取和調節的金鑰模式,在
Music基礎資料表上啟用 DynamoDB 的 CloudWatch Contributor Insights。由於ACCESSED_AND_THROTTLED_KEYS是預設模式,因此您可以省略--contributor-insights-mode=ACCESSED_AND_THROTTLED_KEYS參數。aws dynamodb update-contributor-insights \ --table-name Music \ --contributor-insights-action=ENABLE -
在
AlbumTitle-index全域次要索引上啟用 DynamoDB 專用 Contributor Insights。aws dynamodb update-contributor-insights \ --table-name Music \ --index-name AlbumTitle-index \ --contributor-insights-action=ENABLE -
取得
Music資料表及其所有索引的狀態和規則。aws dynamodb describe-contributor-insights --table-name Music回應將包含顯示
ContributorInsightsMode的欄位ACCESSED_AND_THROTTLED_KEYS。 -
列出
Music資料表及其所有索引的狀態。aws dynamodb list-contributor-insights --table-name Music
啟用限流金鑰模式
在限流金鑰模式中啟用 Contributor Insights
-
在
Music具有調節金鑰模式的基礎資料表上啟用 DynamoDB 的 CloudWatch Contributor Insights。aws dynamodb update-contributor-insights \ --table-name Music \ --contributor-insights-action=ENABLE \ --contributor-insights-mode=THROTTLED_KEYS -
在全域
AlbumTitle-index次要索引的限流索引鍵模式中啟用 Contributor Insights。aws dynamodb update-contributor-insights \ --table-name Music \ --index-name AlbumTitle-index \ --contributor-insights-action=ENABLE \ --contributor-insights-mode=THROTTLED_KEYS -
透過描述 Contributor Insights 組態來驗證 模式。
aws dynamodb describe-contributor-insights --table-name Music與預設模式相比,回應會顯示
ContributorInsightsMode為THROTTLED_KEYS和較少的規則。
在模式之間切換
切換 Contributor Insights 模式
-
從限流金鑰模式切換到存取和限流金鑰模式。
aws dynamodb update-contributor-insights \ --table-name Music \ --contributor-insights-action=ENABLE \ --contributor-insights-mode=ACCESSED_AND_THROTTLED_KEYS -
從存取和限流金鑰模式切換到限流金鑰模式。
aws dynamodb update-contributor-insights \ --table-name Music \ --contributor-insights-action=ENABLE \ --contributor-insights-mode=THROTTLED_KEYS -
在轉換期間檢查狀態。
aws dynamodb describe-contributor-insights --table-name Music在模式切換期間,
ContributorInsightsStatus會顯示為ENABLING。完成後,它會ENABLED以新模式顯示為 。
管理 Contributor Insights
管理 Contributor Insights 設定
-
在
AlbumTitle-index全域次要索引上停用 DynamoDB 專用 CloudWatch Contributor Insights。aws dynamodb update-contributor-insights \ --table-name Music --index-name AlbumTitle-index \ --contributor-insights-action=DISABLE -
列出您帳戶中的所有 Contributor Insights 組態。
aws dynamodb list-contributor-insights這會顯示已啟用 Contributor Insights 的所有資料表和索引,以及其模式。
-
取得特定組態的詳細資訊。
aws dynamodb describe-contributor-insights \ --table-name Music \ --index-name AlbumTitle-index
回應範例
以下是顯示模式間差異的範例回應:
存取和限流金鑰模式回應
{ "TableName": "Music", "ContributorInsightsRuleList": [ "DynamoDBContributorInsights-PKC-Music-1234567890123", "DynamoDBContributorInsights-PKT-Music-1234567890123", "DynamoDBContributorInsights-SKC-Music-1234567890123", "DynamoDBContributorInsights-SKT-Music-1234567890123" ], "ContributorInsightsStatus": "ENABLED", "ContributorInsightsMode": "ACCESSED_AND_THROTTLED_KEYS", "LastUpdateDateTime": "2024-01-15T10:30:00.000Z" }
調節索引鍵模式回應
{ "TableName": "Music", "ContributorInsightsRuleList": [ "DynamoDBContributorInsights-PKT-Music-1234567890123", "DynamoDBContributorInsights-SKT-Music-1234567890123" ], "ContributorInsightsStatus": "ENABLED", "ContributorInsightsMode": "THROTTLED_KEYS", "LastUpdateDateTime": "2024-01-15T10:35:00.000Z" }
請注意,限流金鑰模式的規則較少 (僅 PKT 和 SKT),對應於更集中的監控。