Cosmos DB RU Cost and Throttling Monitor
On a schedule, the flow checks Cosmos DB RU consumption and 429 throttling rates from metrics, flags hot partitions and containers nearing provisioned limits, recommends scaling, and alerts engineering in Teams. Guards Cosmos performance and cost.
Provided as-is, without warranty of any kind. Review and test each pattern in a non-production environment before deploying it to live automations. See our Terms.
Overview
This solution guards Azure Cosmos DB performance and cost. On a 30-minute schedule it queries Azure Log Analytics (KQL over Cosmos diagnostic logs) for RU consumption and 429 throttling rates per container, flags containers that breach a configurable throttle threshold, and posts a formatted alert with a scaling recommendation to an engineering Microsoft Teams channel.
Why it matters: RU exhaustion causes throttling (429s) and outages, while over-provisioning wastes money. Continuous monitoring keeps Cosmos right-sized and healthy, and surfaces hot containers before they impact users.
Status: Built as a FlowLibs reference demo. Ships Off. Going live requires only authorizing the Azure Log Analytics connection and setting the environment variable values - no logic changes.
Use Case
A team running Azure Cosmos DB wants early warning on throttling and cost. Rather than manually watching the Azure portal metrics blade, this flow runs on a schedule, evaluates the last 30 minutes of data-plane telemetry, and only pings the team when a container actually exceeds the alert threshold - turning reactive firefighting into proactive capacity management.
Flow Architecture
Every 30 Minutes
Recurrence (Minute / 30)Runs the health check every 30 minutes.
Initialize SubscriptionId
Initialize Variable (String)Azure subscription id (from env var).
Initialize ResourceGroup
Initialize Variable (String)Log Analytics workspace resource group.
Initialize Workspace
Initialize Variable (String)Log Analytics workspace name.
Initialize ThrottleThreshold
Initialize Variable (String)429 throttle-rate percent alert threshold.
Initialize TeamsGroupId
Initialize Variable (String)Teams team (group) id for alerts.
Initialize TeamsChannelId
Initialize Variable (String)Teams channel id for alerts.
Initialize KQL Query
Initialize Variable (String)Builds the KQL string, injecting the threshold var so it is configurable without editing logic.
Query Cosmos Metrics
Azure Log Analytics - RunOmsQueryRuns the KQL query against the workspace; returns one row per flagged container under body/value.
Check For Throttling
Condition (If)True when any flagged container is returned.
Environment Variables
| Schema name | Type | Default | Description |
|---|---|---|---|
| flowlibs_AzureSubscriptionId | String | 00000000-... | Subscription containing the Cosmos account and Log Analytics workspace (subscriptions param). |
| flowlibs_LogAnalyticsResourceGroup | String | REPLACE_WITH_RESOURCE_GROUP | Resource group of the workspace (resourcegroups param). |
| flowlibs_LogWorkspaceId | String | REPLACE_WITH_WORKSPACE_NAME | Log Analytics workspace name (workspaces param). |
| flowlibs_ThrottleThreshold | String | 1 | 429 throttle-rate percent above which a container is flagged. |
| flowlibs_TeamsGroupId | String | <your-team-id> | Teams team (group) id for the alert channel. |
| flowlibs_TeamsChannelId | String | <your-channel-id> | Teams channel id for the alert channel. |
Connectors & Connections
| Connector | API name | Actions used |
|---|---|---|
| Azure Log Analytics | shared_azureloganalytics | RunOmsQuery |
| Microsoft Teams | shared_teams | PostMessageToConversation |
Note — All connections are referenced as solution connection references; the flow is portable between environments as long as a connection is mapped at import time.
Customization Guide
Almost every realistic variant of this flow can be implemented by changing environment variable values. A few cases require small edits inside the flow definition — those are called out explicitly below.
- Tune the threshold
- Raise or lower flowlibs_ThrottleThreshold (the value is injected into the KQL where ThrottleRatePct >= clause at runtime).
- Change cadence
- Edit the Recurrence interval (e.g. 15 min for tighter SLAs).
- Hot-partition detection
- Add a second KQL block using CDBPartitionKeyRUConsumption to identify skewed partition keys, and surface the top partitions in the alert.
- Autoscale toggle
- Extend the True branch with an Azure Resource Manager Resources_CreateOrUpdateById call to enable autoscale on the flagged container automatically.
- Cost trend
- Persist each run's RU totals to a Dataverse table for week-over-week spend reporting.
Key Expressions
The flow is intentionally light on Power Fx / WDL gymnastics — the heaviest expressions are the branch-name concatenation and the approval outcome check. They are listed below in the order they appear in the flow.
EXPR.01Build the KQL (threshold-driven)
Builds the KQL query with the configurable throttle threshold injected.
EXPR.02Any container flagged?
True when at least one flagged container row is returned.
EXPR.03Unwrap Select rows
Unwraps the Select output into a clean HTML row string.
Customize & download
Generate a ready-to-import copy of this solution with your environment-variable values baked in — available on Base, Pro, or Team.
Upgrade to customize
Comments
Sign in to join the conversation.
Sign inNo comments yet. Be the first to share your experience with this flow.