如何在Mongo API版Cosmos DB中查找高RU消耗的耗时查询
查找Azure Cosmos DB MongoDB API高RU消耗查询的正确方法
你之前的查询无效是因为CDBQueryRuntimeStatistics是SQL API专属的日志表,MongoDB API的查询文本直接记录在CDBMongoRequests表中,不需要跨表关联。
正确的Kusto查询语句
CDBMongoRequests // 过滤RU消耗大于10的请求,可根据实际情况调整阈值 | where todouble(RequestCharge) > 10.0 // 筛选出查询类操作(可按需扩展,比如包含update/delete等写操作) | where CommandName in ("find", "aggregate", "count") // 提取关键字段:请求ID、RU消耗、查询语句、操作类型、集合名 | project ActivityId, RequestCharge = todouble(RequestCharge), QueryText = CommandText, CommandName, CollectionName // 按RU消耗降序排序,取Top 100 | order by RequestCharge desc | limit 100
关键说明
- CommandText字段:MongoDB API的所有命令(查询、更新、聚合等)的具体语句都存在这个字段里,无需额外关联其他表。
- CommandName筛选:如果只关注查询类操作,保留
find/aggregate/count即可;若要包含高消耗的写操作,可添加update/delete/insert等。 - 日志配置验证:确保诊断设置中,
CDBMongoRequests日志的详细级别设置为“信息”或更高级别,否则可能不会记录CommandText内容。 - 日志延迟:诊断日志通常有5-15分钟的延迟,若刚执行查询,需等待一段时间再检索。
额外优化技巧
如果需要精准分析特定时间段的日志,可添加时间范围过滤:
CDBMongoRequests | where TimeGenerated > ago(1h) // 仅查询最近1小时的日志 | where todouble(RequestCharge) > 10.0 | where CommandName in ("find", "aggregate") | project ActivityId, RequestCharge, QueryText, CollectionName | order by RequestCharge desc | limit 100
内容的提问来源于stack exchange,提问作者Rajan
相关产品推荐
相关产品推荐

