Infrastructure

Azure Monitor Agent: diagnose DCR association drift before reinstalling the agent

A production runbook for separating DCR association, rule content, Azure Monitor Agent health and ingestion before reinstalling AMA or launching broad remediation.

12 Oct 2026 azureazure-monitorazure-monitor-agentdcrdcraobservabilityresource-graphkqlazure-policyrunbookrollbackproduction

After an Azure Policy remediation or a new VM rollout, part of a production fleet stops sending Syslog, WindowsEvent or a custom stream. The Azure Monitor Agent extension still reports success. Reinstalling AMA looks like the shortest recovery path, but it rarely explains the failure: the resource may have lost its Data Collection Rule association, retained a stale association, or received a rule that does not collect the expected stream.

The running case is a production VM fleet monitored with Azure Monitor Agent. A reference DCR sends heartbeat, operating system events and performance counters to a Log Analytics workspace. After a policy change, only a subset loses one stream. The goal is to locate the broken contract, repair one canary resource, then decide whether to promote, correct the policy path or roll back.

Freeze the collection contract

“A VM has no logs” is not a bounded symptom. Select one affected machine and one healthy peer with the same OS, role and policy scope. Record their resource IDs, the expected DCR, destination workspace, required streams and the UTC window in which they diverged.

yaml 01-collection-contract.yml
scope:
affected_vm: /subscriptions/.../virtualMachines/app-07
healthy_peer: /subscriptions/.../virtualMachines/app-03
expected_dcr: /subscriptions/.../dataCollectionRules/dcr-linux-prod
destination: law-platform-prod

expected_signals:
heartbeat: every_few_minutes
streams: [Microsoft-Syslog, Microsoft-Perf]
tables: [Heartbeat, Syslog, Perf]

change_window:
start_utc: 2026-10-12T14:00:00Z
suspected_changes:
  - policy_assignment_update
  - remediation_task
  - vm_scale_out

decision:
canary: app-07
promotion: expected_streams_resume_without_duplicate_volume
rollback: restore_previous_association

Preserve the association name as well. A DCRA is a child resource of the monitored resource; its presence, name and dataCollectionRuleId are production state. The existence of the DCR itself does not prove that it applies to the VM.

Separate four failure planes

Treat four planes independently before changing anything.

  1. Association: does the VM have a DCRA pointing to the intended DCR?
  2. Rule contract: does that DCR contain the expected source, stream, transformation and destination?
  3. Agent: is AMA provisioned, and did it obtain usable configuration?
  4. Ingestion: are heartbeat and the operational stream arriving in the correct workspace and table?

An extension in Succeeded mainly answers a deployment question. It does not prove the association, DCR content or arrival of a recent event. Conversely, a recent heartbeat proves agent communication, not correct Syslog or WindowsEvent collection.

Measure fleet-wide drift

Inventory the scope before repairing one VM. Azure Resource Graph can compare associations across resources without opening each machine. Run it with an identity that can see the intended production scope.

kusto 02-dcra-resource-graph-inventory.kql
resources
| where type =~ "microsoft.insights/datacollectionruleassociations"
| extend TargetResourceId = tostring(split(id, "/providers/microsoft.insights/datacollectionruleassociations/")[0]),
       DcrId = tostring(properties.dataCollectionRuleId),
       DceId = tostring(properties.dataCollectionEndpointId)
| project subscriptionId, resourceGroup, name,
        TargetResourceId, DcrId, DceId
| order by TargetResourceId asc, name asc

Compare that inventory with the expected population from a CMDB, stable tag, dynamic group or policy scope. A DCRA list alone cannot reveal missing VMs. Start from the target population and anti-join it against observed associations.

Classify three different gaps: no association, an association to an old DCR ID, or multiple rules collecting the same stream into the same destination. The last case can duplicate records and cost. Do not create another DCRA only because the preferred association name is absent.

Confirm one resource from both sides

On the canary VM, list associations from the resource and then inspect the extension. Save the JSON outputs with the incident evidence.

bash 03-canary-state.sh
az monitor data-collection rule association list-by-resource \
--resource "$VM_ID" \
--output json

az vm extension show \
--ids "$VM_ID/extensions/AzureMonitorLinuxAgent" \
--query "{name:name, provisioningState:provisioningState, version:typeHandlerVersion, autoUpgrade:enableAutomaticUpgrade}" \
--output json

az monitor data-collection rule show \
--ids "$EXPECTED_DCR_ID" \
--output json

Use the extension name deployed in the environment for Windows. A naming or version difference is not automatically the fault. Compare the affected machine with its healthy peer first.

Then inspect dataSources, dataFlows, destinations and any transformKql. A correct association is still ineffective when the expected stream is not routed to the destination, the source targets a different operating system, or a transformation removes the events.

Locate the break with KQL

Query heartbeat and the expected stream separately. This prevents an agent diagnosis when only one data source is missing.

kusto 04-ama-heartbeat.kql
let Window = 30m;
Heartbeat
| where TimeGenerated > ago(Window)
| where Category == "Azure Monitor Agent"
| summarize LastHeartbeat=max(TimeGenerated), Samples=count()
by _ResourceId
| order by LastHeartbeat asc
kusto 05-expected-stream.kql
let Window = 30m;
Syslog
| where TimeGenerated > ago(Window)
| summarize LastEvent=max(TimeGenerated), Events=count()
by _ResourceId, Facility, SeverityLevel
| order by LastEvent asc

Read the results as a matrix. No heartbeat and no stream point toward the agent, identity, network path or configuration retrieval. Heartbeat without the stream points back to the DCR, local source, data flow, transformation or destination. Data under another _ResourceId is more likely an inventory or resource identity mismatch.

An empty query is not validation. Confirm the workspace, table, time range and source clock. When possible, generate one bounded synthetic event on the canary and follow its timestamp from the machine to the table.

Reconstruct the drift owner

A DCRA may be owned by infrastructure as code, a direct deployment or Azure Policy. Identify that owner before applying a manual repair. Review association writes and deletes in the Activity Log, then correlate them with changes to a definition, assignment, managed identity or remediation task.

When Policy owns the desired state, separate compliance from execution. The definition may target the wrong resource type, the assignment may exclude the scope, the policy identity may lack rights, or an older remediation task may carry stale parameters. Manually repairing one VM without repairing this path schedules the next drift.

Repair one canary without duplicating data

Do not reinstall AMA while the association explains the symptom. After proving there is no equivalent association, create or replace the DCRA only on the canary with a stable name and the approved DCR.

bash 06-repair-canary-association.sh
az monitor data-collection rule association create \
--name "dcra-linux-prod" \
--rule-id "$EXPECTED_DCR_ID" \
--resource "$VM_ID" \
--output json

az monitor data-collection rule association list-by-resource \
--resource "$VM_ID" \
--output table

Delete an old association only after recording its name and DCR ID. Multiple rules can legitimately collect different streams. The risk is effective overlap in sources, streams and destinations, not the association count by itself.

Validate, promote or roll back

Validation must cover both control and data planes. Confirm that the DCRA points to the approved DCR, AMA remains healthy, a new heartbeat arrives, the synthetic event reaches the intended table, and volume does not unexpectedly double. Compare the canary with the healthy peer over the same window.

Promote in small batches only when every expected stream returns and the owning automation has been corrected. For Azure Policy, run remediation against the affected scope, then repeat the fleet anti-join. A compliant state without ingestion evidence is not enough.

Roll back when the new association targets the wrong workspace, duplicates a stream, applies an incorrect transformation or raises volume outside the contract. Remove only the canary association created during the change, or restore the previous DCR ID, then replay the same queries. Agent reinstallation remains a separate diagnostic branch for the case where association, rule and destination are correct but AMA still cannot retrieve or execute its configuration.

Conclusion

Missing logs behind a green AMA extension are not a reason to rebuild the agent. They are a collection-chain problem to qualify: target population, DCRA, DCR, agent configuration and ingestion.

The production decision should be explicit: repair the association and its owning automation, correct the DCR contract, continue toward the agent when the control plane is sound, or restore the previous association. The successful outcome is not a reinstalled extension. It is a visible canary event, no duplicate data and a proven rollback path.