你当前正在访问 Microsoft Azure Global Edition 技术文档网站。 如果需要访问由世纪互联运营的 Microsoft Azure 中国技术文档网站,请访问 https://docs.azure.cn

使用 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  

后续步骤