Azure Monitor Agent and data collection rules

The Azure Monitor Agent (AMA) gathers logs and performance counters from inside your VMs and sends them to a Log Analytics workspace. You don’t configure what it collects, or where it sends it, on the agent itself. That’s set by data collection rules (DCRs).

Platform metrics (Lesson 31) look at a VM from the outside, while AMA looks inside it: syslog, Windows event logs, memory and disk counters. It took over from the old Log Analytics agent (MMA/OMS), which retired on 31 August 2024.

You’ll build the workspace for the course, install AMA on both VMs and write a DCR, and then fix the two reasons an agent “runs fine” yet sends nothing.

TimeYou needCostBy the end you can
About 60 minutesweb01, win01, vnet-saat, the CLIAbout 10 US cents for a temporary NAT Gateway; the few MB of logs stay inside Log Analytics’ monthly allowance of 5 GBInstall AMA, write and associate DCRs, and troubleshoot missing data

What it is, in one line

The Azure Monitor Agent collects data inside a VM, and data collection rules tell it what to collect and where it should go.

In Simple Words

The class monitor and the instruction card

Every class has a monitor who writes things down: who came late, what broke, how hot the room got. That’s the agent. The head teacher hands each monitor an instruction card that says “note the temperature every hour and anything broken, and give it to the office”, and that card is a data collection rule, while the office filing cabinet is the Log Analytics workspace. A monitor without a card writes nothing, however hard-working they are, and a monitor who finds the office door locked can’t hand the notes in. Those are today’s two breaks.

Engineer's View

AMA, DCRs and workspaces

  • Azure Monitor Agent: it’s a VM extension (AzureMonitorLinuxAgent, AzureMonitorWindowsAgent) and it signs in with the VM’s managed identity, which is system-assigned by default.
  • Data collection rule: an Azure resource that lists the data sources (performance counters, syslog, Windows event logs with XPath, text logs), the destinations (workspaces, Azure Monitor metrics) and the data flows that connect them. A single DCR can serve lots of VMs, and a VM can have several DCRs.
  • Association: a DCR does nothing at all until you associate it with a VM, and Azure Policy can do those associations at scale.
  • Tables: Heartbeat (once a minute), Perf, Syslog and Event, plus custom tables for text logs.
  • Network: the agent needs HTTPS out to global.handler.control.monitor.azure.com, <region>.handler.control.monitor.azure.com, *.ods.opinsights.azure.com and *.ingest.monitor.azure.com, or else an Azure Monitor Private Link Scope. On a private subnet you have to give it an outbound path.
  • Costs: you pay for the data ingested and kept in the workspace, once you’re past 5 GB a month at no charge per billing account. Analytics logs are kept 31 days at no extra cost, and a daily cap saves your lab from nasty surprises.

How it works, step by step

Once you associate a DCR with web01, this is what happens:

Azure Monitor Agent flow from DCR association to Log Analytics tables
  1. AMA on web01 uses its managed identity to ask the handler endpoint which DCRs apply to it.
  2. It pulls down dcr-saat-basic, which says to collect CPU and memory every 60 seconds plus syslog at warning level and above.
  3. It reads the counters and the syslog messages on the VM.
  4. It sends them over HTTPS to the workspace’s ingestion endpoint, along with a heartbeat each minute.
  5. The data lands in the Perf, Syslog and Heartbeat tables, ready for KQL in Lesson 33.

If any of these steps fails, the portal still shows the agent as Succeeded. “Extension healthy” only tells you the agent got installed, not that any data is arriving.

Azure Monitor Agent sends no data: no DCR, no outbound path, no identity

So when data is missing, always look at the Heartbeat table first. If there’s no heartbeat, the problem is config or network, not the data source.

Hands-on lab: Azure Monitor Agent on web01 and win01

Before you run any command, double-check it

Read every command twice before you press Enter. Check the target: the system or account, the IDs, the names and the sizes. These commands are for learning and were tested in our lab, not on your system. At work, run the read-only list commands first, follow your change process, make sure a backup exists, and ask a second person to check anything that changes or deletes data. You run them at your own risk.

Load the network IDs and start both VMs:

$v = Get-Content C:\azure-lab\vnet-saat.json | ConvertFrom-Json
az vm start --resource-group rg-saat-vms --name web01
az vm start --resource-group rg-saat-vms --name win01

1Create the course Log Analytics workspace

You’ll keep this workspace for the rest of the course, and the daily cap of 0.1 GB stops a runaway bill:

az monitor log-analytics workspace create --resource-group rg-saat-core --name law-saat --location centralindia --retention-time 30 --quota 0.1 --tags course=saatvedha-azure lesson=32 keep=true -o none
$lawId = az monitor log-analytics workspace show --resource-group rg-saat-core --name law-saat --query id -o tsv
$ws = az monitor log-analytics workspace show --resource-group rg-saat-core --name law-saat --query customerId -o tsv
az monitor log-analytics workspace show --resource-group rg-saat-core --name law-saat --query "{name:name, sku:sku.name, retention:retentionInDays, dailyCapGb:workspaceCapping.dailyQuotaGb}" -o table

You should see this:

Name      Sku          Retention    DailyCapGb
--------  -----------  -----------  ------------
law-saat  PerGB2018    30           0.1

2Give the VMs a way out

It’s the same NAT Gateway as in Lesson 30, and only for this lab:

az network public-ip create --resource-group rg-saat-core --name pip-saat-natgw --sku Standard --location centralindia --tags course=saatvedha-azure lesson=32 -o none
az network nat gateway create --resource-group rg-saat-core --name natgw-saat --public-ip-addresses pip-saat-natgw --idle-timeout 4 --location centralindia --tags course=saatvedha-azure lesson=32 -o none
az network vnet subnet update --ids $v.'snet-web' --nat-gateway natgw-saat -o none
az network vnet subnet update --ids $v.'snet-mgmt' --nat-gateway natgw-saat -o none

3Install the agent on both VMs

Switch on the system-assigned identity first, and then add the extension:

az vm identity assign --resource-group rg-saat-vms --name web01 -o none
az vm identity assign --resource-group rg-saat-vms --name win01 -o none
az vm extension set --resource-group rg-saat-vms --vm-name web01 --name AzureMonitorLinuxAgent --publisher Microsoft.Azure.Monitor --enable-auto-upgrade true -o none
az vm extension set --resource-group rg-saat-vms --vm-name win01 --name AzureMonitorWindowsAgent --publisher Microsoft.Azure.Monitor --enable-auto-upgrade true -o none
az vm extension list --resource-group rg-saat-vms --vm-name win01 --query "[?publisher=='Microsoft.Azure.Monitor'].{name:name, state:provisioningState}" -o table

You should see this:

Name                      State
------------------------  ---------
AzureMonitorWindowsAgent  Succeeded

4Write a data collection rule

It collects CPU and memory every 60 seconds, syslog at warning and above, and errors and warnings from the Windows System and Application logs:

$dcr = @{
  location   = 'centralindia'
  properties = @{
    dataSources = @{
      performanceCounters = @(@{ name = 'perfBasic'; streams = @('Microsoft-Perf'); samplingFrequencyInSeconds = 60
        counterSpecifiers = @('\Processor Information(_Total)\% Processor Time', '\Memory\Available Bytes',
                              'Processor(*)\% Processor Time', 'Memory(*)\Available MBytes Memory') })
      syslog = @(@{ name = 'syslogBasic'; streams = @('Microsoft-Syslog'); facilityNames = @('auth', 'daemon', 'syslog', 'user')
        logLevels = @('Warning', 'Error', 'Critical', 'Alert', 'Emergency') })
      windowsEventLogs = @(@{ name = 'eventsBasic'; streams = @('Microsoft-Event')
        xPathQueries = @('System!*[System[(Level=1 or Level=2 or Level=3)]]', 'Application!*[System[(Level=1 or Level=2 or Level=3)]]') })
    }
    destinations = @{ logAnalytics = @(@{ name = 'law'; workspaceResourceId = $lawId }) }
    dataFlows = @(@{ streams = @('Microsoft-Perf', 'Microsoft-Syslog', 'Microsoft-Event'); destinations = @('law') })
  }
}
$dcr | ConvertTo-Json -Depth 10 | Set-Content -Path C:\azure-lab\dcr-basic.json
$sub = az account show --query id -o tsv
$dcrId = "/subscriptions/$sub/resourceGroups/rg-saat-core/providers/Microsoft.Insights/dataCollectionRules/dcr-saat-basic"
az rest --method put --url "https://management.azure.com${dcrId}?api-version=2022-06-01" --body '@C:\azure-lab\dcr-basic.json' --query "properties.provisioningState" -o tsv

You should see this:

Succeeded

5Associate it with web01 and check the data

Run this and give it about 10 minutes:

Set-Content -Path C:\azure-lab\dcr-assoc.json -Value ('{"properties": {"dataCollectionRuleId": "' + $dcrId + '"}}')
$id = az vm show --resource-group rg-saat-vms --name web01 --query id -o tsv
az rest --method put --url "https://management.azure.com${id}/providers/Microsoft.Insights/dataCollectionRuleAssociations/dcra-saat-basic?api-version=2022-06-01" --body '@C:\azure-lab\dcr-assoc.json' -o none
az vm run-command invoke --resource-group rg-saat-vms --name web01 --command-id RunShellScript --scripts 'logger -p user.err saatvedha test error' -o none
Start-Sleep -Seconds 600
az monitor log-analytics query --workspace $ws --analytics-query "Heartbeat | summarize LastSeen=max(TimeGenerated) by Computer, Category" -o table
az monitor log-analytics query --workspace $ws --analytics-query "Syslog | where SyslogMessage has 'saatvedha' | project TimeGenerated, Computer, SeverityLevel, SyslogMessage" -o table

You should see something like this:

Category              Computer    LastSeen                      TableName
--------------------  ----------  ----------------------------  -------------
Azure Monitor Agent   web01       2026-10-20T18:52:10.000Z      PrimaryResult
Computer    SeverityLevel    SyslogMessage            TableName      TimeGenerated
----------  ---------------  -----------------------  -------------  ----------------------------
web01       err              saatvedha test error     PrimaryResult  2026-10-20T18:44:31.000Z
Azure Monitor Agent lab: workspace, DCR and heartbeat query
The workspace, the DCR, and the first heartbeat and syslog record from web01.

✅ Checkpoint: law-saat exists with a 0.1 GB daily cap, AMA runs on both VMs, and web01 sends heartbeats and syslog through dcr-saat-basic.

Break It, Then Fix It

Keep both VMs running for these two breaks.

1Break it: agent installed, no data

win01 has the agent and it shows Succeeded. Write a test event on it and go looking for it:

az vm run-command invoke --resource-group rg-saat-vms --name win01 --command-id RunPowerShellScript --scripts 'eventcreate /T ERROR /ID 900 /L APPLICATION /SO SaatLab /D SaatvedhaTest' -o none
Start-Sleep -Seconds 300
az monitor log-analytics query --workspace $ws --analytics-query "Heartbeat | where Computer startswith 'win01' | count" -o table

You should see this:

Count    TableName
-------  -------------
0        PrimaryResult

No heartbeat and no events. The agent is healthy but it has no DCR, so it has nothing to do and nowhere to send anything. This is the AMA ticket you’ll see most: a policy or script put the extension on, but nobody did the DCR association.

Fix it: associate the DCR with win01, wait a bit, and check again:

Set-Content -Path C:\azure-lab\dcr-assoc.json -Value ('{"properties": {"dataCollectionRuleId": "' + $dcrId + '"}}')
$id = az vm show --resource-group rg-saat-vms --name win01 --query id -o tsv
az rest --method put --url "https://management.azure.com${id}/providers/Microsoft.Insights/dataCollectionRuleAssociations/dcra-saat-basic?api-version=2022-06-01" --body '@C:\azure-lab\dcr-assoc.json' -o none
Start-Sleep -Seconds 300
az vm run-command invoke --resource-group rg-saat-vms --name win01 --command-id RunPowerShellScript --scripts 'eventcreate /T ERROR /ID 901 /L APPLICATION /SO SaatLab /D SaatvedhaTest' -o none
Start-Sleep -Seconds 300
az monitor log-analytics query --workspace $ws --analytics-query "Event | where Source == 'SaatLab' | project TimeGenerated, Computer, EventLevelName, RenderedDescription" -o table

You should see something like this:

Computer    EventLevelName    RenderedDescription    TableName      TimeGenerated
----------  ----------------  ---------------------  -------------  ----------------------------
win01       Error             SaatvedhaTest          PrimaryResult  2026-10-20T19:03:12.000Z

Events only get collected from the moment the agent receives the rule, so write a fresh test event whenever you change a DCR.

2Break it: the heartbeat stops

Take the NAT Gateway off snet-web, wait, and then compare the two VMs:

az network vnet subnet update --ids $v.'snet-web' --remove natGateway -o none
Start-Sleep -Seconds 900
az monitor log-analytics query --workspace $ws --analytics-query "Heartbeat | summarize LastSeen=max(TimeGenerated) by Computer | extend MinutesAgo=datetime_diff('minute', now(), LastSeen)" -o table

You should see something like this:

Computer    LastSeen                      MinutesAgo    TableName
----------  ----------------------------  ------------  -------------
web01       2026-10-20T19:05:10.000Z      14            PrimaryResult
win01       2026-10-20T19:19:40.000Z      0             PrimaryResult

web01 went quiet 14 minutes ago while win01 is still reporting, because from a private subnet with no outbound path the agent can’t reach the ingestion endpoints. On Linux its local log, /var/opt/microsoft/azuremonitoragent/log/mdsd.err, is full of connection errors.

At work this shows up as “the server stopped logging”, usually during the very incident you need the logs for.

Fix it: give it an outbound path again (NAT Gateway, firewall rules for the Azure Monitor endpoints, or Azure Monitor Private Link Scope), and then check:

az network vnet subnet update --ids $v.'snet-web' --nat-gateway natgw-saat -o none
Start-Sleep -Seconds 300
az monitor log-analytics query --workspace $ws --analytics-query "Heartbeat | where Computer == 'web01' | summarize LastSeen=max(TimeGenerated)" -o table

You should see a time within the last few minutes.

To clean up, keep the workspace, the DCR and the agents, but remove the NAT Gateway and stop the VMs:

az network vnet subnet update --ids $v.'snet-web' --remove natGateway -o none
az network vnet subnet update --ids $v.'snet-mgmt' --remove natGateway -o none
az network nat gateway delete --resource-group rg-saat-core --name natgw-saat
az network public-ip delete --resource-group rg-saat-core --name pip-saat-natgw
az vm deallocate --resource-group rg-saat-vms --name web01
az vm deallocate --resource-group rg-saat-vms --name win01
Azure Monitor Agent problems: missing association and stopped heartbeat
An agent with no rule, and an agent with no way out.

✅ Checkpoint: Both VMs sent heartbeats once they had a DCR and an outbound path. law-saat and dcr-saat-basic stay for Lessons 33 and 34.

This happened at work

The audit logs that were never collected

A bank moved 400 Windows servers from the old Log Analytics agent to AMA ahead of the August 2024 retirement. They used an Azure Policy to install the agent everywhere, and the migration dashboard showed 400 green ticks.

Six months later an auditor asked for the sign-in failure events from a group of payment servers, and the Event table had nothing at all for 90 of them. When the team checked, the policy that installed AMA had run fine, but the policy that associated the security DCR was scoped to the wrong management group.

What they changed: agent install and DCR association now sit in a single policy initiative that’s assigned as one. Every day a KQL check compares the VM inventory from Resource Graph against the computers seen in Heartbeat in the last hour, and raises a ticket for anything missing.

Common mistakes and troubleshooting

MistakeWhat you seeWhat to do
Agent installed, no DCR associatedNo Heartbeat, no dataAssociate a DCR; check Heartbeat first.
No outbound path or blocked endpointsHeartbeat stops; mdsd errorsNAT, firewall rules, or Azure Monitor Private Link.
No managed identity on the VMAgent can’t authenticateEnable system-assigned identity.
Collecting everything at debug levelBig ingestion billCollect warnings and above; filter with XPath.
No daily cap in dev workspacesSurprise costs from a noisy VMSet a cap; alert on ingestion.
Still planning on the old MMA agentUnsupported since August 2024Migrate to AMA with DCRs.

Interview questions

Click any question to open it. They’re worded the way an interviewer would ask them, and under each one you’ll find why they ask it and one way you could answer in your own words.

Fresher level

1. What is the Azure Monitor Agent?

Why they ask this: To see if you know the basic idea.

How you might answer: It’s a VM extension that collects logs and performance data from inside Windows and Linux machines and sends it to Log Analytics or Azure Monitor metrics. It replaced the Log Analytics agent (MMA).

2. What is a data collection rule?

Why they ask this: It’s the central idea behind AMA.

How you might answer: It’s an Azure resource that says what data to collect, how to filter it and where to send it. An agent gets its work from whichever DCRs are associated with its machine.

3. Which table shows that an agent is alive?

Why they ask this: It’s the first thing you’d check.

How you might answer: Heartbeat. AMA writes a record roughly every minute, so if the heartbeat’s missing, the agent either isn’t running, has no DCR, or can’t get to Azure.

2–5 years experience

4. AMA is installed but no data arrives. How do you troubleshoot?

Why they ask this: You’ll get this ticket a lot.

How you might answer: I’d look for Heartbeat from that computer first. If it’s not there, I check the DCR association, the managed identity and network access to the handler and ingestion endpoints. If heartbeats are coming in but one table is empty, then it’s the DCR’s data sources and filters.

5. How do you collect only important Windows events?

Why they ask this: They want to see you know XPath.

How you might answer: You put XPath queries in the DCR, for example System!*[System[(Level=1 or Level=2 or Level=3)]] for critical, errors and warnings, which keeps ingestion and the bill down.

6. How would you control Log Analytics costs?

Why they ask this: They want the practical levers.

How you might answer: Only collect what someone uses and filter at the DCR. Put high-volume, low-value tables on Basic or Auxiliary logs, set retention per table, and in non-production workspaces set daily caps with alerts.

Senior level

7. How would you roll out AMA across thousands of servers, including Arc?

Why they ask this: They want to hear about scale and governance.

How you might answer: I’d use Azure Policy initiatives that install AMA, assign the managed identity and associate standard DCRs by OS and role, with remediation tasks for the machines that already exist. Arc brings the on-premises servers in the same way, and a daily check of Heartbeat against inventory catches the gaps.

8. How do you send VM logs from private networks without internet?

Why they ask this: They’re checking private connectivity.

How you might answer: Either Azure Monitor Private Link Scope, with private endpoints for the monitor endpoints and private DNS, or an outbound path through Azure Firewall that only allows the Azure Monitor FQDNs and service tags.

9. Workspace design: one central workspace or many?

Why they ask this: They want to hear the trade-offs.

How you might answer: Keep as few as you can, often one per region or per security boundary, because querying across workspaces gets awkward. I’d only split for data residency, separate billing or strict access rules, and use resource-context access to limit what each team sees.

Quick quiz

Q1. What tells the Azure Monitor Agent what to collect?

  1. The VM size
  2. A data collection rule
  3. An NSG
  4. The Activity log
Show answer

B — DCRs define sources, destinations and flows.

Q2. How does AMA authenticate by default?

  1. Account key
  2. System-assigned managed identity
  3. SAS token
  4. Password
Show answer

B — AMA uses the VM’s managed identity.

Q3. AMA shows Succeeded but no Heartbeat appears. First suspect?

  1. Disk size
  2. No DCR association or no outbound path
  3. Blob tier
  4. Region pair
Show answer

B — Healthy extension doesn’t mean data flows.

Q4. Which agent retired on 31 August 2024?

  1. Azure Monitor Agent
  2. Log Analytics agent (MMA)
  3. VM agent
  4. Dependency agent
Show answer

B — MMA is retired; use AMA.

Q5. What does a workspace daily cap do?

  1. Deletes old data
  2. Stops ingestion for the day once reached
  3. Speeds up queries
  4. Adds retention
Show answer

B — It limits daily ingestion to protect cost.

Quick recap

Your VMs now report from the inside, and you know where to look when they go quiet.

  • AMA collects inside the VM; DCRs say what and where.
  • No DCR association means no data, even with a healthy agent.
  • The agent needs outbound HTTPS or Private Link.
  • Heartbeat is the first check for missing data.
  • Filter at the DCR and cap dev workspaces to control cost.

Next lesson

Lesson 33: Log Analytics workspaces and KQL basics → Next, you write KQL queries to filter, summarize and chart the data your agents have been collecting.

Further reading: Azure Monitor Agent

Want to go deeper into Azure Monitor Agent? Microsoft’s Azure Monitor Agent overview and Data collection rules in Azure Monitor are good next reads, and the full plan for this course is on the Azure Cloud Administration course page.

Scroll to Top

This website uses cookies

We use a few cookies to keep this site working. If you allow it, we also use Google Analytics to count visits so we can improve our lessons. You can accept all, deny the optional ones, or choose what to allow.