Compartilhar via

使用 Azure Cosmos DB for MongoDB 排查高级诊断查询问题

适用对象: NoSQL MongoDB Cassandra 格林姆林

重要

你是否正在寻找一种数据库解决方案,以应对需要高扩展性、99.999% 可用性服务级别协议(SLA)、即时自动扩展和跨多个区域的自动故障转移的场景? 请考虑使用 Azure Cosmos DB for NoSQL

在本文中,我们将介绍如何编写更高级的查询,使用发送到 Azure Diagnostics(旧版)和特定资源(预览)表的诊断日志,以协助排查 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  

后续步骤