Monitor Azure Cosmos DB for MongoDB vCore diagnostics logs with Azure Monitor

APPLIES TO: MongoDB vCore

Azure's diagnostic logs are essential to capture Azure resource logs for an Azure Cosmos DB for MongoDB vCore account. These logs furnish detailed and frequent insights into the operations for resources with the account.

Important

This feature is not available with M25 (burstable) or M30 (free-tier) SKUs.

Prerequisites

Create diagnostic settings

Platform metrics and activity logs are gathered automatically. To collect resource logs and route them externally from Azure Monitor, you must establish a diagnostic setting. To learn how, see Create diagnostic settings in Azure Monitor.

Manage diagnostic settings

Sometimes you need to manage settings by finding or removing them. The az monitor diagnostic-settings command group includes subcommands for the management of diagnostic settings.

  1. List all diagnostic settings associated with the API for MongoDB vCore cluster.

    az monitor diagnostic-settings list \
        --resource-group $resourceGroupName \
        --resource $clusterResourceId
    
  2. Delete a specific setting using the associated resource and the name of the setting.

    az monitor diagnostic-settings delete \
        --resource-group $resourceGroupName \
        --name $diagnosticSettingName \
        --resource $clusterResourceId
    

Use advanced diagnostics queries

Use these resource-specific queries to perform common troubleshooting research in an API for MongoDB vCore cluster.

Important

This section assumes that you are using a Log Analytics workspace with resource-specific logs.

  1. Navigate to Logs section of the API for MongoDB vCore cluster. Observe the list of sample queries.

    Screenshot of the diagnostic queries list of sample queries.

  2. Run this query to count the number of failed API for MongoDB vCore requests grouped by error code.

    VCoreMongoRequests
    // Time range filter:  | where TimeGenerated between (StartTime .. EndTime)
    // Resource id filter: | where _ResourceId == "/subscriptions/aaaa0a0a-bb1b-cc2c-dd3d-eeeeee4e4e4e/resourcegroups/my-resource-group-name/providers/microsoft.documentdb/mongoclusters/my-cluster-name"
    | where ErrorCode != 0
    | summarize count() by bin(TimeGenerated, 5m), ErrorCode=tostring(ErrorCode)
    
  3. Run this query to get the API for MongoDB vCore requests P99 runtime duration by operation name.

    // Mongo vCore requests P99 duration by operation 
    // Mongo vCore requests P99 runtime duration by operation name. 
    VCoreMongoRequests
    // Time range filter:  | where TimeGenerated between (StartTime .. EndTime)
    // Resource id filter: | where _ResourceId == "/subscriptions/aaaa0a0a-bb1b-cc2c-dd3d-eeeeee4e4e4e/resourcegroups/my-resource-group-name/providers/microsoft.documentdb/mongoclusters/my-cluster-name"
    | summarize percentile(DurationMs, 99) by bin(TimeGenerated, 1h), OperationName
    
  4. Run this query to get the count of API for MongoDB vCore requests grouped by total runtime duration.

    // Mongo vCore requests binned by duration 
    // Count of Mongo vCore requests binned by total runtime duration. 
    VCoreMongoRequests
    // Time range filter:  | where TimeGenerated between (StartTime .. EndTime)
    // Resource id filter: | where _ResourceId == "/subscriptions/aaaa0a0a-bb1b-cc2c-dd3d-eeeeee4e4e4e/resourcegroups/my-resource-group-name/providers/microsoft.documentdb/mongoclusters/my-cluster-name"
    | project TimeGenerated, DurationBin=tostring(bin(DurationMs, 5))
    | summarize count() by bin(TimeGenerated, 1m), tostring(DurationBin)
    
  5. Run this query to get the count of API for MongoDB vCore requests by user agent.

    // Mongo vCore requests by user agent 
    // Count of Mongo vCore requests by user agent. 
    VCoreMongoRequests
    // Time range filter:  | where TimeGenerated between (StartTime .. EndTime)
    // Resource id filter: | where _ResourceId == "/subscriptions/aaaa0a0a-bb1b-cc2c-dd3d-eeeeee4e4e4e/resourcegroups/my-resource-group-name/providers/microsoft.documentdb/mongoclusters/my-cluster-name"
    | summarize count() by bin(TimeGenerated, 1h), UserAgent