Domain 2 β€” Module 6 of 11 55%
21 of 31 overall
Domain 2: Secure, optimize, and deploy database solutions Free ⏱ ~16 min read

Monitoring: Metrics, Logs, and Alerts

Monitor Cosmos DB health with current throughput and connection-mode latency metrics, SDK request duration, diagnostic logs, Azure Monitor workbooks and application-specific alert rules.

Why monitoring matters

Simple explanation

Think of monitoring as the dashboard gauges in your car. You need to know when the engine is overheating (throttling), when you’re running low on fuel (RU/s budget), and when something unusual happens (error spikes). Without gauges, you’re driving blind.

Marcus’s monitoring mission

βš™οΈ Marcus at FinSecure runs Cosmos DB in three production environments with SOC 2 compliance requirements. He needs to:

  • Detect 429 throttling within minutes
  • Track query performance trends
  • Maintain audit logs for compliance
  • Get alerted when latency exceeds SLA thresholds

Key metrics

Treat alert thresholds as application-specific design choices, not universal Cosmos DB SLA limits. Check the current monitoring reference for supported names, dimensions and aggregations.

MetricWhat It Tells YouAlert Threshold
NormalizedRUConsumption% of provisioned RU/s consumed (0-100%); inspect partition dimensionsExample warning at >80% sustained, then check actual 429s
TotalRequestsNumber of requests (including 429s)Alert on sudden spikes
TotalRequestUnitsTotal RU consumedTrack for cost trends
ServerSideLatencyDirect / ServerSideLatencyGatewayServer processing latency for the corresponding connection modeUse supported Average/Maximum aggregations and a workload-specific threshold
DataUsage / IndexUsageData and index storage usageTrack growth; inspect logical-key storage separately
MetadataRequestsMetadata requests such as resource enumerationInvestigate unexpected increases
Exam tip: NormalizedRUConsumption is the key metric

NormalizedRUConsumption helps detect throughput pressure. A physical partition at 100% is at its RU budget; check actual 429 responses and request distribution rather than assuming every request is throttled.

Key details:

  • It’s per-physical-partition β€” a hot partition can show 100% while the account average is 30%
  • An example sustained >80% warning should trigger investigation of demand, throttling and partition skew before a capacity change
  • The exam often presents this metric in scenarios asking β€œwhat should you monitor for throttling?”

Monitor the whole request

Backend processing time is not end-to-end application latency. Track SDK request duration and application percentiles against the service objective; network time, retries, connection setup and client resource pressure can all add delay. Capture diagnostics for slow requests and correlate region, activity id, status and RU charge before deciding whether the database backend is the bottleneck.

The retired AvailableStorage and ServerSideLatency metrics are not the current alert targets. Use the connection-mode latency metrics above. For logical-partition storage, enable PartitionKeyStatistics logs and monitor growth toward the standard 20 GB complete-key boundary. Those statistics sample large keys and are approximate, not a complete inventory of every key.

Diagnostic logging

Enable diagnostic logs to capture detailed operation data. This example exports to resource-specific tables used by the KQL below; replace the placeholder resource identifiers:

az monitor diagnostic-settings create \
  --name "cosmos-diagnostics" \
  --resource "/subscriptions/<subscription-id>/resourceGroups/<resource-group>/providers/Microsoft.DocumentDB/databaseAccounts/finsecure-cosmos" \
  --workspace "/subscriptions/<subscription-id>/resourceGroups/<resource-group>/providers/Microsoft.OperationalInsights/workspaces/finsecure-logs" \
  --export-to-resource-specific true \
  --logs '[
    {"category": "QueryRuntimeStatistics", "enabled": true},
    {"category": "DataPlaneRequests", "enabled": true},
    {"category": "PartitionKeyStatistics", "enabled": true},
    {"category": "PartitionKeyRUConsumption", "enabled": true},
    {"category": "ControlPlaneRequests", "enabled": true}
  ]'
Log CategoryWhat It Captures
DataPlaneRequestsEvery read, write, query with RU cost and latency
QueryRuntimeStatisticsQuery text and identifiers for correlation with request logs
PartitionKeyStatisticsApproximate sampled large logical-partition storage usage
PartitionKeyRUConsumptionRU consumption broken down by partition key
ControlPlaneRequestsAccount-level operations (create, delete, scale)

Query text and parameters can be obfuscated by default. Review data-handling requirements and logging costs before enabling more detailed query text.

KQL query examples

Query your diagnostic logs with Kusto Query Language (KQL) in Log Analytics:

// Find the most expensive queries in the last hour
let requestCharges = CDBDataPlaneRequests
| where TimeGenerated > ago(1h)
| project TimeGenerated, ActivityId, RequestCharge;
CDBQueryRuntimeStatistics
| where TimeGenerated > ago(1h)
| project ActivityId, QueryText, DatabaseName, CollectionName
| join kind=inner requestCharges on ActivityId
| project DatabaseName, CollectionName, QueryText, RequestCharge, TimeGenerated
| order by RequestCharge desc
| take 10
// Detect 429 throttling events
CDBDataPlaneRequests
| where TimeGenerated > ago(24h)
| where StatusCode == 429
| summarize ThrottledCount = count() by bin(TimeGenerated, 5m), CollectionName
| order by TimeGenerated desc
// Identify hot partitions
CDBPartitionKeyRUConsumption
| where TimeGenerated > ago(1h)
| summarize TotalRU = sum(RequestCharge) by PartitionKey
| order by TotalRU desc
| take 10

Azure Monitor workbooks

Azure provides built-in Cosmos DB insights β€” pre-built dashboards in the Azure portal:

  • Overview: Throughput, requests, storage, availability at a glance
  • Throughput: NormalizedRUConsumption with partition-level breakdown
  • Requests: Status code distribution, latency percentiles
  • Storage: Per-partition storage usage, index size
  • Failures: 429 rates, timeout rates, error categorisation

Diana’s tip: πŸ” Diana, Marcus’s security auditor, uses the ControlPlaneRequests log category to track who made configuration changes β€” required for SOC 2 audit trails.

Alert rules

# Alert when NormalizedRUConsumption exceeds 80% for 5 minutes
az monitor metrics alert create \
  --name "cosmos-throttle-warning" \
  --resource-group "<resource-group>" \
  --scopes "/subscriptions/<subscription-id>/resourceGroups/<resource-group>/providers/Microsoft.DocumentDB/databaseAccounts/finsecure-cosmos" \
  --condition "max NormalizedRUConsumption > 80" \
  --window-size 5m \
  --evaluation-frequency 1m \
  --action "/subscriptions/<subscription-id>/resourceGroups/<resource-group>/providers/Microsoft.Insights/actionGroups/ops-team"
AlertConditionSeverity
Throttling warningNormalizedRUConsumption > 80% for 5minWarning
Throttling criticalNormalizedRUConsumption > 95% for 5minCritical
Latency spikeAverage connection-mode server latency exceeds the application’s chosen threshold for 10min; investigate SDK percentiles separatelyWarning
Logical-partition growthLog alert from PartitionKeyStatistics before a sampled key reaches the standard 20 GB boundaryWarning
Error rateHTTP 5xx count > 10 in 5minCritical

🎬 Video walkthrough

Flashcards

Question

What is NormalizedRUConsumption and why is it the most important metric?

Click or press Enter to reveal answer

Question

Which diagnostic log category captures query execution details?

Click or press Enter to reveal answer

Question

How do you identify hot partitions in Cosmos DB?

Click or press Enter to reveal answer

Knowledge Check

Knowledge Check

Marcus notices NormalizedRUConsumption at 95% sustained for his orders container. What should he do first?

Knowledge Check

Diana needs an audit trail of who changed the Cosmos DB account configuration for SOC 2 compliance. Which diagnostic log category should she enable?

Knowledge Check

Marcus wants to find the top 10 most expensive queries in the last hour. Which tool and approach should he use?


Next up: Backup and Restore β€” choosing between periodic and continuous backup, configuring policies, and point-in-time restore.