다음을 통해 공유

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

本文介绍如何编写更高级的查询,以使用发送到 Azure 诊断(旧版)资源特定(预览)表 的诊断日志,帮助排查 Azure Cosmos DB 帐户中的问题。

对于 Azure 诊断表,所有数据都写入一个表中。 用户指定要查询的类别。 若要查看请求的全文查询,请参阅使用 Azure 中的诊断设置监视 Azure Cosmos DB 数据,了解如何启用此功能。

对于特定于资源的表,数据将写入每个资源类别的各个表中。 出于以下目的,我们建议采用此模式:

  • 简化数据处理程序。
  • 可提高架构的可发现性。
  • 改善了引入延迟和查询时间的性能。

常见查询

常见查询显示在资源专用表和 Azure 诊断表中。

特定时间范围内根据请求单位(RU)消耗排序的前10个查询

let topRequestsByRUcharge = CDBDataPlaneRequests 
| where TimeGenerated > ago(24h)
| project  RequestCharge , TimeGenerated, ActivityId;
CDBQueryRuntimeStatistics
| project QueryText, ActivityId, DatabaseName , CollectionName
| join kind=inner topRequestsByRUcharge on ActivityId
| project DatabaseName , CollectionName , QueryText , RequestCharge, TimeGenerated
| order by RequestCharge desc
| take 10

在给定时间范围内限制的请求数 (statusCode = 429)

let throttledRequests = CDBDataPlaneRequests
| where StatusCode == "429"
| project  OperationName , TimeGenerated, ActivityId;
CDBQueryRuntimeStatistics
| project QueryText, ActivityId, DatabaseName , CollectionName
| join kind=inner throttledRequests on ActivityId
| project DatabaseName , CollectionName , QueryText , OperationName, TimeGenerated

具有最大响应长度的查询(服务器响应的有效负载大小)

let operationsbyUserAgent = CDBDataPlaneRequests
| project OperationName, DurationMs, RequestCharge, ResponseLength, ActivityId;
CDBQueryRuntimeStatistics
//specify collection and database
//| where DatabaseName == "DBNAME" and CollectionName == "COLLECTIONNAME"
| join kind=inner operationsbyUserAgent on ActivityId
| summarize max(ResponseLength) by QueryText
| order by max_ResponseLength desc

按物理分区划分的 RU 使用量(跨副本集中的所有副本)

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

后续步骤