Azure Cosmos DB for NoSQL을 사용하여 고급 진단 쿼리 문제 해결

적용 대상: NoSQL

이 문서에서는 Azure Diagnostics(레거시)리소스 관련(미리 보기) 테이블로 전송된 진단 로그를 사용하여 Azure Cosmos DB 계정 관련 문제 해결에 도움이 되는 고급 쿼리를 작성하는 방법을 설명합니다.

Azure Diagnostics 테이블의 경우 모든 데이터가 하나의 단일 테이블에 기록됩니다. 사용자는 쿼리할 범주를 지정합니다. 요청의 전체 텍스트 쿼리를 보려면 Azure에서 진단 설정을 사용하여 Azure Cosmos DB 데이터 모니터링을 참조하여 이 기능을 사용하는 방법을 알아봅니다.

리소스별 테이블의 경우 데이터는 리소스의 각 범주에 대한 개별 테이블에 기록됩니다. 다음과 같은 이유로 이 모드를 권장합니다.

  • 데이터 작업을 훨씬 쉽게 만듭니다.
  • 스키마의 더 나은 검색 가능성을 제공합니다.
  • 수집 대기 시간과 쿼리 시간 모두에서 성능이 향상됩니다.

일반 쿼리

일반적인 쿼리는 리소스별 및 Azure Diagnostics 표에 나와 있습니다.

특정 시간 프레임의 RU(요청 단위) 소비에 따라 정렬된 상위 N(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  

다음 단계