Risolvere i problemi relativi alle query di diagnostica avanzate con Azure Cosmos DB for NoSQL

SI APPLICA A: NoSQL

Questo articolo illustra come scrivere query più avanzate per risolvere i problemi relativi all'account Azure Cosmos DB usando i log di diagnostica inviati a Diagnostica di Azure (legacy) e alle tabelle specifiche delle risorse (anteprima).

Per le tabelle di Diagnostica di Azure, tutti i dati vengono scritti in una singola tabella. Gli utenti specificano la categoria su cui si vuole eseguire una query. Per visualizzare la query full-text della richiesta, vedere Monitorare i dati di Azure Cosmos DB usando le impostazioni di diagnostica in Azure per informazioni su come abilitare questa funzionalità.

Per le tabelle specifiche delle risorse, i dati sono scritti in singole tabelle per ogni categoria della risorsa. È consigliabile usare questa modalità perché:

  • Semplifica notevolmente l'uso dei dati.
  • Offre una migliore individuabilità degli schemi.
  • Migliora le prestazioni sia nella latenza di inserimento dei dati che nei tempi di query.

Query comuni

Le query comuni vengono visualizzate nelle tabelle specifiche delle risorse e nelle tabelle di Diagnostica di Azure.

N(10) query principali ordinate in base al consumo di unità richiesta (UR) in un intervallo di tempo specifico

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

Richieste limitate (statusCode = 429) in un intervallo di tempo specifico

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

Query con lunghezza massima di risposta (dimensioni del payload di risposta del server)

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

Consumo di UR per partizione fisica (in tutte le repliche nel set di repliche)

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

Consumo di UR per partizione logica (in tutte le repliche nel set di repliche)

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  

Passaggi successivi