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

Kanisius Raychitra Lieka Avisena 0 Reputation points

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.


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

1 answer

Sort by: Most helpful
  1. Amira Bedhiafi 16,146 Reputation points

    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.

    | 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