Monitor Fabric Open Mirroring Without Burning Your Capacity
A cost-aware alternative to Workspace Monitoring using Azure Functions, Application Insights, Log Analytics, and Azure Monitor.
For one of our clients I was implementing Open Mirroring to mirror a MongoDB database into Microsoft Fabric. I needed to monitor that process though. Sometimes I would have a replication failure and I want to get an email when that happens so that I could fix that.
One of my first thoughts was: let's just use Workspace Monitoring and an Activator that does some KQL query that triggers when a replication error is there. Native, no extra infrastructure, done in twenty minutes.
But then I looked at the CU usage.

Just to extract and monitor logs via Workspace Monitoring + Activator.
To put that in perspective: an F8 gives you 8 CU/hour × 60 minutes/hour × 60 seconds/minute × 24 hours/day = 691,200 CUsec per day (the maximum theoretically possible). So 126,000 CUsec is roughly 18%, nearly a fifth of the entire capacity gone before any actual workload runs.
The cheaper setup
I moved the monitoring outside Fabric capacity entirely.
An Azure Function polls the Fabric REST API every five minutes. When it finds something unhealthy, it logs an event. The function runs on a Consumption plan: 12 times per hour × 24 hours/day × 30 days/month = 8,640 executions a month against a free grant of 1 million, so effectively zero cost.
These logs end up in a Log Analytics workspace, which means all traces end up in the AppTraces table and become queryable with KQL. To interact with a Log Analytics workspace from an Azure Function, you have to use App Insights as a bridge. But if you use the standard logging library in Python, the Azure Functions SDK automatically ships every log record to App Insights (and thus to Log Analytics). Ingestion is free up to 5 GB per month, which we never approach.
The last piece is an Azure Monitor Scheduled Query Alert. It runs a KQL query every five minutes and fires an Action Group when rows come back. An Action Group is a reusable resource that defines who gets notified and through what channel. Keeping it separate from the alert rule means multiple alerts can share the same notification target.
To authenticate with Fabric, the Azure Function uses a User-assigned Managed Identity with Viewer access on the Fabric workspace, so there are no secrets to manage. You do need to enable the Service Principals can use Fabric APIs tenant setting first.
Building the monitor
Step 1: The function app
The function runs on a timer. A cron expression in the timer_trigger decorator fires it every five minutes automatically. Each run calls two Fabric REST API endpoints:
getMirroringStatus: returns the overall database status (Running,Stopped,Failed) and a human-readable message. One call per poll.getTablesMirroringStatus: returns a paginated list of every mirrored table with its individual status, processed row and byte counts, last sync timestamp, and the Fabric error code and message if something went wrong.
Both checks always run, because a database reporting Running does not mean all its tables are healthy. Tables can be stuck in Failed while the database looks fine.
The entry point is the timer trigger. The schedule is read from an app setting so you can change the polling interval without redeploying. It fetches a token, runs the database check, and if that succeeds it always runs the table check as well.
@app.timer_trigger(schedule="%FUNCTION_POLL_SCHEDULE%", arg_name="mytimer", run_on_startup=False)
def fabric_mirroring_monitor(mytimer: func.TimerRequest) -> None:
token = get_token()
result = check_mirroring_status(token)
if result is None:
return # fatal auth error, already logged
# Always check tables — a Running DB doesn't mean all tables are healthy
check_tables_status(token)
get_token uses the Managed Identity to request a bearer token scoped to the Fabric API. If the credential call throws, it logs the error and returns None, which the caller uses as the signal to abort.
def get_token() -> str | None:
try:
credential = ManagedIdentityCredential()
token = credential.get_token("https://api.fabric.microsoft.com/.default")
return token.token
except Exception as e:
logging.error(f"Failed to acquire token: {e}")
return None
check_mirroring_status calls getMirroringStatus and logs a warning if the database is not Running. A 401 is treated as fatal and returns None to abort the rest of the run.
def check_mirroring_status(token: str) -> dict | None:
url = f"{FABRIC_API_BASE}/workspaces/{WORKSPACE_ID}/mirroredDatabases/{DATABASE_ID}/getMirroringStatus"
resp = requests.post(url, headers={"Authorization": f"Bearer {token}"})
if resp.status_code == 401:
logging.error("Auth error — aborting")
return None
data = resp.json()
if data.get("status") != "Running":
logging.warning(
f"Fabric database is unhealthy"
f" | status={data.get('status')}"
f" | message={data.get('message')}"
)
return data
check_tables_status calls getTablesMirroringStatus and pages through the full table list. For each unhealthy table it writes a structured log message with the error details embedded. The retry helper backs off 10 seconds on 429 and 5xx responses and aborts immediately on 401.
def check_tables_status(token: str) -> None:
url = f"{FABRIC_API_BASE}/workspaces/{WORKSPACE_ID}/mirroredDatabases/{DATABASE_ID}/getTablesMirroringStatus"
continuation_token = None
while True:
resp = _get_with_retry(url, token, continuation_token)
if resp is None:
return
for table in resp.json().get("data", []):
if table.get("status") != "Running":
error = table.get("error") or {}
logging.warning(
f"Fabric mirrored table is unhealthy"
f" | database={DATABASE_NAME}"
f" | table={table.get('sourceSchemaName')}.{table.get('sourceTableName')}"
f" | status={table.get('status')}"
f" | error={error.get('message')}"
f" | details={json.dumps(table)}"
)
continuation_token = resp.json().get("continuationToken")
if not continuation_token:
break
def _get_with_retry(url, token, continuation_token):
params = {"continuationToken": continuation_token} if continuation_token else {}
for _ in range(3):
resp = requests.get(url, headers={"Authorization": f"Bearer {token}"}, params=params)
if resp.status_code == 401:
logging.error("Auth error — aborting")
return None
if resp.status_code in (429, 500, 502, 503, 504):
time.sleep(10)
continue
resp.raise_for_status()
return resp
logging.error(f"Failed after retries: {url}")
return None
One thing worth knowing about the getTablesMirroringStatus response: metrics and error details are nested inside sub-objects, not at the top level:
{
"sourceSchemaName": "dbo",
"sourceTableName": "Orders",
"status": "Failed",
"metrics": {
"processedRows": 0,
"processedBytes": 0,
"lastSyncDateTime": null,
"lastSyncLatencyInSeconds": null
},
"error": {
"errorCode": "UserError",
"message": "We encountered an error while parsing metadata file..."
}
}
The error.message field is the actual human-readable error from Fabric. I embed it and the full raw response directly in the log message string so it shows up verbatim in the alert email:
"message": (
f"Fabric mirrored table is unhealthy"
f" | database={DATABASE_NAME}"
f" | table={table.get('sourceSchemaName')}.{table.get('sourceTableName')}"
f" | status={table.get('status')}"
f" | error={error.get('message')}"
f" | details={json.dumps(table)}"
),
Step 2: The alert
The Scheduled Query Alert evaluates every 5 minutes over a 15-minute window and parses the message fields back into typed columns:
AppTraces
| where AppRoleName == "func-fabric-mirroring-monitor"
| where SeverityLevel >= 2
| where Message startswith "Fabric mirrored"
| extend d = parse_json(extract(@"\| details=(\{.*\})", 1, Message))
| project
TimeGenerated,
database = extract(@"\| database=([^|]+)", 1, Message),
table = extract(@"\| table=([^|]+)", 1, Message),
status = extract(@"\| status=([^|]+)", 1, Message),
errorCode = tostring(d["error"]["errorCode"]),
errorMsg = tostring(d["error"]["message"]),
rows = toint(d["metrics"]["processedRows"]),
lastSync = todatetime(d["metrics"]["lastSyncDateTime"]),
latencySecs = toint(d["metrics"]["lastSyncLatencyInSeconds"])
One thing to get right: the alert must be scoped to the Log Analytics workspace resource ID, not Application Insights. The AppTraces table lives in Log Analytics, and pointing at App Insights gives you a "table not found" error. I also set failing_periods to 1 of 1. With auto_mitigation_enabled = true you get one email when the alert fires and one when it resolves.

Results
| Approach | Daily Fabric CU cost | Azure cost | Extra infrastructure |
|---|---|---|---|
| Workspace Monitoring + Activator BEFORE | 126,000 CUsec ≈ 20% of F8 | ~$190/mo | None |
| Azure Function + App Insights + Log Analytics + Azure Monitor AFTER | 0 CUsec | ~$1.50/mo | Function App, App Insights, Log Analytics, Azure Monitor Alert |
The tradeoff is a small Azure Function to maintain. The code is under 200 lines of Python and all the infrastructure is in Terraform.
Full source code on GitHub
Azure Function, Terraform infrastructure, and unit tests. Ready to use.
View on GitHub ↗Cost breakdown
The before number comes from the F8 pay-as-you-go price of $1,051.20/month. Workspace Monitoring consumed 126,000 CUsec/day out of 691,200 available, which is 18.2%, or $191/month gone before any actual workload runs.
The after number breaks down like this:
- Azure Function (Consumption): 8,640 executions/month against a free grant of 1 million. Cost: $0.
- Application Insights + Log Analytics: even if you exaggerate and put the total monthly ingestion at 1 GB, that is nowhere near the 5 GB free tier (per billing account). Cost: $0.
- Azure Monitor Scheduled Query Alert: standard log alert rules are priced at $1.50/rule/month. We have one. Cost: $1.50.
Total: $1.50/month against $191/month before.