Share via


針對 Azure Cosmos DB for MongoDB 的進階診斷查詢問題進行疑難排解

適用於:NoSQL MongoDB Cassandra Gremlin

在本文中,我們將探討如何使用傳送至 Azure 診斷 (舊版) 資源專屬 (預覽版) 資料表的診斷記錄,以便撰寫更進階的查詢,協助疑難排解 Azure Cosmos DB 帳戶的問題。

Azure 診斷資料表的所有資料皆會寫入單一資料表中。 使用者指定要查詢的類別。 若要檢視要求的全文檢索查詢,請參閱使用 Azure 中的診斷設定來監視 Azure Cosmos DB 資料,了解如何啟用這項功能。

資源專屬資料表的資料會寫入該資源各類別的個別資料表。 建議採用此模式,因為:

  • 使用資料時更方便。
  • 可更深入探索結構描述。
  • 同時改善擷取延遲及查詢時間兩者的效能。

常用查詢

資源專屬及 Azure 診斷資料表會顯示常用查詢。

在特定時間範圍內取用要求或查詢的前 N (10) 個要求單位 (RU)

//Enable full-text query to view entire query text
CDBMongoRequests
| where TimeGenerated > ago(24h)
| project PIICommandText, ActivityId, DatabaseName , CollectionName, RequestCharge
| order by RequestCharge desc
| take 10

在特定時間範圍內節流的要求 (statusCode = 429 或 16500)

CDBMongoRequests
| where TimeGenerated > ago(24h)
| where ErrorCode == "429" or ErrorCode == "16500"
| project DatabaseName, CollectionName, PIICommandText, OperationName, TimeGenerated

在特定時間範圍內的逾時要求 (statusCode = 50)

CDBMongoRequests
| where TimeGenerated > ago(24h)
| where ErrorCode == "50"
| project DatabaseName, CollectionName, PIICommandText, OperationName, TimeGenerated

回應長度 (伺服器回應的承載大小) 較大的查詢

CDBMongoRequests
//specify collection and database
//| where DatabaseName == "DB NAME" and CollectionName == "COLLECTIONNAME"
| summarize max(ResponseLength) by PIICommandText, RequestCharge, DurationMs, OperationName, TimeGenerated
| order by max_ResponseLength desc

實體分割區 (複本集的所有複本) 的 RU 耗用量

CDBPartitionKeyRUConsumption
| where TimeGenerated >= now(-1d)
//specify collection and database
//| where DatabaseName == "DB NAME" and CollectionName == "COLLECTIONNAME"
// filter by operation type
//| where operationType_s == 'Create'
| summarize sum(todouble(RequestCharge)) by toint(PartitionKeyRangeId)
| render columnchart

邏輯分割區 (複本集的所有複本) 的 RU 耗用量

CDBPartitionKeyRUConsumption
| where TimeGenerated >= now(-1d)
//specify collection and database
//| where DatabaseName == "DB NAME" and CollectionName == "COLLECTIONNAME"
// filter by operation type
//| where operationType_s == 'Create'
| summarize sum(todouble(RequestCharge)) by PartitionKey, PartitionKeyRangeId
| render columnchart  

下一步