Flow Run Duration Monitor and Alert
Check flow run durations against SLA thresholds; if a flow takes too long, alert the team in Teams with run details.
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
The Flow Run Duration Monitor and Alert flow is a scheduled monitoring solution that checks Power Automate flow run durations against configurable SLA thresholds. When any flow run exceeds the defined time limit, it posts a detailed HTML alert to a Microsoft Teams channel — enabling IT admins and developers to quickly identify and investigate slow-running automations before they impact business operations.
Use Case
In enterprise environments with dozens or hundreds of Power Automate flows, long-running executions can indicate performance degradation, API throttling, infinite loops, or upstream system failures. This flow provides proactive SLA monitoring by scanning all active flows, querying recent run history via the Flow Management REST API, calculating actual run durations (including still-running executions), and aggregating any SLA breaches into a single formatted Teams alert.
The flow is ideal for teams that:
- Scanning all active flows in the environment every hour
- Querying recent run history for each active flow via the Flow Management REST API
- Calculating actual run duration (start-to-end for completed runs, start-to-now for still-running executions)
- Aggregating breaches into a single formatted Teams alert with flow name, run ID, start time, duration, and status
Flow Architecture
Recurrence - Every Hour
RecurrenceFires on a 1-hour interval to check flow run durations.
Initialize Variable - SLA Threshold Minutes
Initialize variableReads the `flowlibs_FlowRunSLAThresholdMinutes` environment variable as an integer (default: 30).
Initialize Variable - Teams Group ID
Initialize variableReads the `flowlibs_FlowRunMonitorTeamsGroupId` environment variable.
Initialize Variable - Teams Channel ID
Initialize variableReads the `flowlibs_FlowRunMonitorTeamsChannelId` environment variable.
Initialize Variable - Environment Name
Initialize variableReads the `flowlibs_FlowRunMonitorEnvironmentName` environment variable.
Initialize Variable - Tenant ID
Initialize variableReads the `flowlibs_FlowRunMonitorTenantId` environment variable for OAuth.
Initialize Variable - Client ID
Initialize variableReads the `flowlibs_FlowRunMonitorClientId` environment variable for OAuth.
Initialize Variable - Client Secret
Initialize variableReads the `flowlibs_FlowRunMonitorClientSecret` environment variable for OAuth.
Initialize Variable - Alert Body HTML
Initialize variableEmpty string used to accumulate alert table rows.
Initialize Variable - Breach Count
Environment Variables
| Schema name | Type | Default | Description |
|---|---|---|---|
| flowlibs_FlowRunSLAThresholdMinutes | String | 30 | Maximum acceptable run duration in minutes before a flow run is treated as an SLA breach. |
| flowlibs_FlowRunMonitorTeamsGroupId | String | 00000000-0000-0000-0000-000000000000 | Teams team/group ID where SLA breach alerts are posted. |
| flowlibs_FlowRunMonitorTeamsChannelId | String | 19:example@thread.tacv2 | Teams channel ID where SLA breach alerts are posted. |
| flowlibs_FlowRunMonitorEnvironmentName | String | <your-tenant-id> | Power Platform environment name (the GUID portion after `default-`) that the flow scans for active flows. |
| flowlibs_FlowRunMonitorTenantId | String | <your-tenant-id> | Azure AD tenant ID used by the HTTP action's OAuth authentication. |
| flowlibs_FlowRunMonitorClientId | String | <configure> | Client ID of the Azure AD app registration that has the `Flows.Read.All` permission on the Power Automate REST API. |
| flowlibs_FlowRunMonitorClientSecret | String | <configure> | Client secret for the Azure AD app registration. Recommended: store in Azure Key Vault and reference via a Key Vault-backed environment variable in production. |
Connectors & Connections
| Connector | API name | Actions used |
|---|---|---|
| Power Automate Management | shared_flowmanagement | ListMyFlowsAsAdmin (Lists all flows in the target environment) |
| Microsoft Teams | shared_teams | PostMessageToChannelV3 (Posts the SLA breach alert to a channel) |
| HTTP (built-in) | N/A | HTTP (Calls the Flow API `/flows/{flowId}/runs` endpoint with ActiveDirectoryOAuth) |
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.
- Create an Azure AD App Registration
- Create an app registration with the Flows.Read.All permission (or equivalent) on the Power Automate REST API. Record the Client ID and generate a Client Secret.
- Update OAuth environment variables
- Set flowlibs_FlowRunMonitorClientId, flowlibs_FlowRunMonitorClientSecret, and flowlibs_FlowRunMonitorTenantId to the values for your app registration and tenant. For production, store the client secret in Azure Key Vault and reference it via a Key Vault env var.
- Configure the Teams alert target
- Set flowlibs_FlowRunMonitorTeamsGroupId and flowlibs_FlowRunMonitorTeamsChannelId to the team and channel that should receive SLA alerts.
- Set the SLA threshold
- Adjust flowlibs_FlowRunSLAThresholdMinutes to the maximum run duration you want to tolerate (default is 30 minutes).
- Update connection references
- Ensure the Power Automate Management and Teams connection references are valid in the target environment.
- Turn on the flow
- After configuration, change the flow state from Stopped to Started.
- Tune the recurrence and run window
- Adjust the Recurrence trigger interval (default: 1 hour) for how urgently you need breaches detected, and tweak the HTTP action's $top=10 parameter to inspect more or fewer recent runs per flow.
- Add email notifications alongside Teams
- In the breach-found branch, add an Outlook Send an email (V2) action after the Teams post to send the same HTML alert by email.
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.01Run duration (completed runs)
Converts the tick difference between end and start into minutes for runs that have already completed.
EXPR.02Run duration (still-running runs)
Calculates elapsed minutes from a run's start time to now for runs that are still executing.
EXPR.03SLA threshold comparison
Drives the per-run condition that appends a row to the alert body when the duration exceeds the configured SLA threshold.
EXPR.04Active flow filter
Filter Array predicate that keeps only flows whose state is `Started`.
Comments
Sign in to join the conversation.
Sign inNo comments yet. Be the first to share your experience with this flow.