Last active
March 14, 2024 01:36
-
-
Save chrismckelt/bb864a44d50c9586097358c4d963f912 to your computer and use it in GitHub Desktop.
Cosmos DB Queries
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Consumed RU/s in last 24 hours | |
// Identify consumed RU/s on Cosmos databases and collections. | |
// To create an alert for this query, click '+ New alert rule' | |
//You can compare the RU/s consumption with your provisioned RU/s to determine if you should scale up or down RU/s based on your workload. | |
AzureDiagnostics | |
| where Category == "DataPlaneRequests" | |
//| where collectionName_s == "CollectionToAnalyze" //Replace to target the query to a collection | |
| summarize ConsumedRUsPerMinute = sum(todouble(requestCharge_s)) by collectionName_s, _ResourceId, bin(TimeGenerated, 1m) | |
| project TimeGenerated , ConsumedRUsPerMinute , collectionName_s, _ResourceId | |
| render timechart | |
// RU charges by | |
CDBPartitionKeyRUConsumption | |
| where DatabaseName == "dsp-db" | |
| summarize sum(RequestCharge) by PartitionKey | |
| order by sum_RequestCharge desc | |
// RU charges by | |
CDBPartitionKeyRUConsumption | |
| where DatabaseName == "dsp-db" | |
| summarize sum(RequestCharge) by PartitionKey | |
| order by sum_RequestCharge desc | |
// RU per query | |
CDBQueryRuntimeStatistics | |
| join kind=inner ( | |
CDBDataPlaneRequests | |
| project RequestCharge, ActivityId | |
) on $left.ActivityId == $right.ActivityId | |
| distinct RequestCharge, QueryText | |
| order by RequestCharge desc | |
| limit 10 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
//Determine what requests are returning 429 responses
CDBDataPlaneRequests
| summarize throttledOperations = dcountif(ActivityId, StatusCode == 429), totalOperations = dcount(ActivityId), totalConsumedRUPerMinute = sum(RequestCharge) by DatabaseName, CollectionName, OperationName, bin(TimeGenerated, 1min)
| extend averageRUPerOperation = 1.0 * totalConsumedRUPerMinute / totalOperations
| extend Most429s = 1.0 * throttledOperations / totalOperations
| order by Most429s desc