Summary
When installing Azure Monitor Agent (AMA) on Azure Batch pool nodes via Azure Policy, the agent fails to authenticate with a 401 InvalidResourceId error. The resource ID presented in the access token (the underlying VMSS resource ID) does not match the resource ID expected by the Azure Monitor control plane (the Batch pool resource ID).
Goal
I'm trying to collect OS-level metrics (CPU, memory, disk I/O) from Azure Batch pool nodes and ship them to a Log Analytics workspace using Azure Monitor Agent, without modifying application code.
Since I'd like to capture metrics for hundreds of nodes, I'm looking for a scalable solution that does not require manual configuration on each node, hence why I wanted to test a proof-of-concept using Azure Policies and AMAs.
Environment
- Azure Batch pool using Virtual Machine Configuration (not Cloud Services)
- Pool nodes provisioned as a VM Scale Set (
Microsoft.Compute/virtualMachineScaleSets) in an auto-generated resource group separate from the Batch account
- Node OS: Ubuntu 24.04
- Pool type: spot instances
- AMA version installed:
1.40.0
Setup
For completeness I'm listing here all the resources I created (all of them in the same Azure subscription and region).
Infrastructure
- A test Batch account with a single pool of 2 spot VMs running Ubuntu 24.04
- Note: The Batch account places pool VMs in an auto-generated resource group separate from the Batch account resource group — this is a key detail for policy scoping
- A test Log Analytics workspace
- A user-assigned managed identity having the following roles:
-
Monitoring Metrics Publisher role on the Log Analytics workspace
-
Virtual Machine Contributor role on the whole subscription (for simplicity, so I don't have to guess the auto-generated RG name and scope the role assignment at that level)
- A Data Collection Rule (DCR) configured to collect Performance Counters, associated to the pool VMSS
Azure Policies
I created 2 new policies assignments (starting from the two built-in policies below) and scoped them to the auto-generated resource group containing the pool VMSS:
-
Configure Linux virtual machine scale sets to run Azure Monitor Agent with user-assigned managed identity-based authentication
-
Configure Linux virtual machine scale sets to be associated with a Data Collection Rule
After creating a task remediation both policies show 100% compliant status.
Verified State
- AMA extension (
AzureMonitorLinuxAgent 1.40.0) installed on the VMSS — confirmed via:
az vmss extension list --output table
# AzureMonitorLinuxAgent Microsoft.Azure.Monitor 1.40.0 ProvisioningState/succeeded
- Both VMSS instances have
latestModelApplied: True — confirmed via:
az vmss list-instances --query "[].{instanceId:instanceId, latestModel:latestModelApplied}"
# 0 True
# 1 True
- AMA service running on both instances — confirmed via:
az vmss run-command invoke --scripts "sudo systemctl status azuremonitoragent"
# Active: active (running)
# Enable succeeded
Problem
Despite all steps completing successfully, no data appears in the Log Analytics workspace — neither Heartbeat nor Perf tables contain any records.
Inspecting the AMA error log on the instances via az vmss run-command invoke reveals the following error repeating every 60 seconds:
Response Code: 401
{
"error": {
"code": "InvalidResourceId",
"message": "Resource ID in the access token
('/subscriptions/<sub-id>/resourceGroups/<auto-generated-rg>/providers/Microsoft.Compute/virtualMachineScaleSets/<vmss-name>')
does not match the expected one
('/subscriptions/<sub-id>/resourceGroups/<batch-account-rg>/providers/Microsoft.Batch/batchAccounts/<batch-account>/pools/<pool-name>')"
}
}
Question
Is there an officially supported way to install and run Azure Monitor Agent on Azure Batch pool nodes to collect OS-level VM metrics?
Specifically:
- Is there a supported configuration that resolves the
InvalidResourceId mismatch between the VMSS resource ID and the Batch pool resource ID?
- Is there a recommended alternative approach to collect OS-level metrics (CPU, memory, disk) from Batch pool nodes into a Log Analytics workspace?