診斷查詢相關問題的疑難排解

適用於: NoSQL MongoDB Cassandra Gremlin Table

在本文中,我們將討論如何使用傳送至 AzureDiagnostics 的 診斷記錄, (舊版) 和資源 特定 (預覽) 資料表,協助針對 Azure Cosmos DB 帳戶的問題進行疑難排解。

對於Azure 診斷資料表,所有資料都會寫入一個單一資料表,而使用者必須指定想要查詢的類別。

針對資源專屬的資料表,資料則會個別寫入該資源的各類別資料表 (不適用於資料表 API)。 建議您使用此模式,因為資料使用更為便利、也強化了結構描述的探索能力,並改善擷取延遲和查詢時間的效能。

常用查詢

以下是常見的疑難排解查詢清單。

查詢執行時間超過 3 毫秒的作業

尋找持續時間大於 3 毫秒的作業。

AzureDiagnostics 
| where toint(duration_s) > 3 and ResourceProvider=="MICROSOFT.DOCUMENTDB" and Category=="DataPlaneRequests" 
| summarize count() by clientIpAddress_s, TimeGenerated

查詢正在執行作業的使用者代理程式

尋找與每項作業相關聯的使用者代理程式。

AzureDiagnostics 
| where ResourceProvider=="MICROSOFT.DOCUMENTDB" and Category=="DataPlaneRequests" 
| summarize count() by OperationName, userAgent_s

查詢長時間執行的作業

尋找長時間執行的作業,方法是將其執行時間量化為五秒間隔。

AzureDiagnostics 
| where ResourceProvider=="MICROSOFT.DOCUMENTDB" and Category=="DataPlaneRequests" 
| project TimeGenerated , duration_s 
| summarize count() by bin(TimeGenerated, 5s)
| render timechart

取得分割區索引鍵統計資料,以評估資料庫帳戶的前三個分割區扭曲

取得實體分割區的常見統計資料,以測量扭曲。

AzureDiagnostics 
| where ResourceProvider=="MICROSOFT.DOCUMENTDB" and Category=="PartitionKeyStatistics" 
| project SubscriptionId, regionName_s, databaseName_s, collectionName_s, partitionKey_s, sizeKb_d, ResourceId 

取得昂貴查詢的要求費用

針對最大的查詢,測量 RU) 中要求費用 (。

AzureDiagnostics
| where ResourceProvider=="MICROSOFT.DOCUMENTDB" and Category=="DataPlaneRequests" and todouble(requestCharge_s) > 10.0
| project activityId_g, requestCharge_s
| join kind= inner (
AzureDiagnostics
| where ResourceProvider =="MICROSOFT.DOCUMENTDB" and Category == "QueryRuntimeStatistics"
| project activityId_g, querytext_s
) on $left.activityId_g == $right.activityId_g
| order by requestCharge_s desc
| limit 100

尋找哪些作業採用大部分的 RU/秒

依所使用的 RU/秒數量排序作業。

AzureDiagnostics
| where ResourceProvider=="MICROSOFT.DOCUMENTDB" and Category=="DataPlaneRequests"
| where TimeGenerated >= ago(2h) 
| summarize max(responseLength_s), max(requestLength_s), max(requestCharge_s), count = count() by OperationName, requestResourceType_s, userAgent_s, collectionRid_s, bin(TimeGenerated, 1h)

取得耗用超過 100 RU/秒的所有查詢

尋找比基準數量更多的 RU/秒的查詢。

此查詢會與 和 QueryRunTimeStatistics 的資料 DataPlaneRequests 聯結。

AzureDiagnostics
| where ResourceProvider=="MICROSOFT.DOCUMENTDB" and Category=="DataPlaneRequests" and todouble(requestCharge_s) > 100.0
| project activityId_g, requestCharge_s
| join kind= inner (
        AzureDiagnostics
        | where ResourceProvider =="MICROSOFT.DOCUMENTDB" and Category == "QueryRuntimeStatistics"
        | project activityId_g, querytext_s
) on $left.activityId_g == $right.activityId_g
| order by requestCharge_s desc
| limit 100

取得要求費用和查詢的執行持續時間

取得特定查詢要求費用和持續時間的統計資料。

AzureDiagnostics
| where TimeGenerated >= ago(24hr)
| where Category == "QueryRuntimeStatistics"
| join (
AzureDiagnostics
| where TimeGenerated >= ago(24hr)
| where Category == "DataPlaneRequests"
) on $left.activityId_g == $right.activityId_g
| project databasename_s, collectionname_s, OperationName1 , querytext_s,requestCharge_s1, duration_s1, bin(TimeGenerated, 1min)

取得不同作業的散發

依資源分佈分組作業。

AzureDiagnostics
| where ResourceProvider=="MICROSOFT.DOCUMENTDB" and Category=="DataPlaneRequests"
| where TimeGenerated >= ago(2h) 
| summarize count = count()  by OperationName, requestResourceType_s, bin(TimeGenerated, 1h) 

取得分割區已耗用的最大輸送量

取得實體分割區的最大輸送量。

AzureDiagnostics
| where ResourceProvider=="MICROSOFT.DOCUMENTDB" and Category=="DataPlaneRequests"
| where TimeGenerated >= ago(2h) 
| summarize max(requestCharge_s) by bin(TimeGenerated, 1h), partitionId_g

取得每秒分割區索引鍵 RU/秒耗用量的相關資訊

測量每個分割區索引鍵每秒的 RU/秒耗用量。

AzureDiagnostics 
| where ResourceProvider == "MICROSOFT.DOCUMENTDB" and Category == "PartitionKeyRUConsumption" 
| summarize total = sum(todouble(requestCharge_s)) by databaseName_s, collectionName_s, partitionKey_s, TimeGenerated 
| order by TimeGenerated asc 

取得特定分割區索引鍵的要求費用

測量每個分割區索引鍵的要求費用。

AzureDiagnostics 
| where ResourceProvider == "MICROSOFT.DOCUMENTDB" and Category == "PartitionKeyRUConsumption" 
| where parse_json(partitionKey_s)[0] == "2" 

取得特定期間內耗用大部分 RU/秒的頂端分割區索引鍵

根據時間範圍內的要求單位耗用量排序分割區索引鍵。

AzureDiagnostics 
| where ResourceProvider == "MICROSOFT.DOCUMENTDB" and Category == "PartitionKeyRUConsumption" 
| where TimeGenerated >= datetime("11/26/2019, 11:20:00.000 PM") and TimeGenerated <= datetime("11/26/2019, 11:30:00.000 PM") 
| summarize total = sum(todouble(requestCharge_s)) by databaseName_s, collectionName_s, partitionKey_s 
| order by total desc

取得儲存體大小大於 8 GB 的資料分割索引鍵記錄

尋找依每個分割區索引鍵儲存體大小篩選的資料分割索引鍵記錄。

AzureDiagnostics
| where ResourceProvider=="MICROSOFT.DOCUMENTDB" and Category=="PartitionKeyStatistics"
| where todouble(sizeKb_d) > 800000

取得作業、要求費用或回應長度的 P99 或 P50 延遲

測量的效能;作業延遲、RU/秒使用量和回應長度。

AzureDiagnostics
| where ResourceProvider=="MICROSOFT.DOCUMENTDB" and Category=="DataPlaneRequests"
| where TimeGenerated >= ago(2d)
| summarize percentile(todouble(responseLength_s), 50), percentile(todouble(responseLength_s), 99), max(responseLength_s), percentile(todouble(requestCharge_s), 50), percentile(todouble(requestCharge_s), 99), max(requestCharge_s), percentile(todouble(duration_s), 50), percentile(todouble(duration_s), 99), max(duration_s), count() by OperationName, requestResourceType_s, userAgent_s, collectionRid_s, bin(TimeGenerated, 1h)

取得控制平面記錄

使用 ControlPlaneRequests 取得控制平面長。

提示

請記得開啟停用金鑰型中繼資料寫入存取中所述的旗標,並使用 Azure PowerShell、Azure CLI 或 Azure Resource Manager來執行作業。

AzureDiagnostics 
| where Category =="ControlPlaneRequests"
| summarize by OperationName 

下一步