Microsoft Azure CosmosDB for MongoDB Deprecated Classic Metrics: Data+Index Size Consumed Per Partition Key Range

Kanisius Raychitra Lieka Avisena 0 Reputation points
2024-05-16T04:11:14.7+00:00

Hi All,

Given the Monitor Classic Metrics was deprecated. I would like to know is there any way to know the data size consumed per partition key for CosmosDB (MongoDB)? I had explored the Metrics in Monitoring blade at Azure Portal, but seems I could not find the alternative.

This metrics is important to us because there is 20GB limitation on each logical partition for CosmosDB. Knowing which shard key near its size limit will be very appreciated.

Thank you.

Regards,
Kanisius

Azure Monitor
Azure Monitor
An Azure service that is used to collect, analyze, and act on telemetry data from Azure and on-premises environments.
3,306 questions
Azure Cosmos DB
Azure Cosmos DB
An Azure NoSQL database service for app development.
1,658 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Amira Bedhiafi 25,866 Reputation points
    2024-05-20T20:13:53.0633333+00:00

    I don't think there is a direct solution for this. You can use the GetPartitionKeyStatisticsAsync method to get statistics about the partition keys.

    Similar functionality is available in the Node.js SDK.

    
    var container = client.GetContainer("databaseId", "containerId");
    
    var partitionKeyStats = await container.ReadPartitionKeyStatisticsAsync(partitionKeyValue);
    
    Console.WriteLine($"Partition key: {partitionKeyValue}, Size: {partitionKeyStats.SizeInKB} KB");
    
    
    

    You can enable diagnostics logs for your CosmosDB account. These logs contain detailed metrics that can be used to analyze the size of data per partition key. After exporting them to a Log Analytics workspace, you can run queries to analyze the data size per partition key.

    
    AzureDiagnostics
    
    | where ResourceType == "COSMOSDB_ACCOUNTS"
    
    | where OperationName == "MongoDBRequest"
    
    | summarize TotalSize = sum(toint(parse_json(RequestBody).size)) by PartitionKey
    
    | order by TotalSize desc
    
    

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.