Skip to main content

Identifying Monitoring Agents via KQL for transition AMA Migration - Part 2

· 6 min read
Hasan Gural

Hello Folks, Welcome back to the second part of our journey to transition from the Log Analytics agents to the Azure Monitor Agent (AMA). In the first part, we learned how to find and check the monitoring agents using KQL. In this part, we'll continue our journey by identifying the agents that have reported to the Log Analytics Workspace and then extend our query to include all virtual machines within your subscription or tenant.

Last time, we discovered which virtual machines were running the old MMA or OMS agents. This time, we're refining our search to quickly determine whether a machine uses MMA or the updated AMA.

📊 Extending the query to include extensions for AMA

If you recollect from our previous post, we explored the microsoft.compute/virtualmachines/extensions table in the Azure Resource Graph to look up the virtual machines and their extensions. We picked out just the extensions we needed. Now, we're taking it a step further. We want to see the extensions on the virtual machines, especially the ones for the AMA agent.

In order to do this, we are going to use the filter publisher =~ "Microsoft.Azure.Monitor for the AMA agent. Here's how we can extend our query to include the extensions for the AMA agent:


resources
| where type == "microsoft.compute/virtualmachines"
| extend PowerStatus = properties.extended.instanceView.powerState.displayStatus,
OSType = properties.storageProfile.osDisk.osType,
IdentityType = identity.type,
ComputerName = tolower(name)
| project ComputerName, id, location, resourceGroup, PowerStatus, OSType, IdentityType
| join kind=leftouter (
resources
| where type contains "microsoft.compute/virtualmachines/extensions"
| extend publisher = properties.publisher
| where publisher =~ "Microsoft.Azure.Monitor"
| parse id with * "/virtualMachines/" ComputerName "/" *
| extend extensionType = properties.type,
status = properties.provisioningState,
version = properties.typeHandlerVersion,
ComputerName = tolower(ComputerName)
| project ComputerName, AMA = name, AMAStatus = status, AMAVersion = version
)
on ComputerName
| where isnotempty(AMA)
| project ComputerName, ResourceID = tolower(id), location, resourceGroup, OSType, PowerStatus, AMA, AMAStatus, AMAVersion

Resulting in example output:

COMPUTERNAMELOCATIONRESOURCEGROUPOSTYPEPOWERSTATUSAMAAMASTATUSAMAVERSION
vm-name-01location-01rg-name-01LinuxVM deallocatedAzureMonitorLinuxAgentSucceeded1
vm-name-02location-02rg-name-02LinuxVM runningAzureMonitorLinuxAgentSucceeded1.22
vm-name-03location-03rg-name-03LinuxVM runningAzureMonitorLinuxAgentSucceeded1.6
vm-name-04location-01rg-name-01LinuxVM runningAzureMonitorLinuxAgentSucceeded1.6

image

▶️ Combine results for MMA and AMA

With the results for both MMA and AMA on the hand, we're in a strong position to bring them together for a holistic view of all our virtual machines and the respective agents reporting in. This comprehensive overview is crucial for grasping the current layout of our environment, which agents we need to transition.

The process of generating these results into a single glass pane is straightforward. Merging these data sets isn't complex; we'll employ the same join keyword within our query to unify the information. By doing this, we'll gain a comprehensive overview of all the virtual machines and their respective reporting agents.


resources
| where type == "microsoft.compute/virtualmachines"
| extend PowerStatus = properties.extended.instanceView.powerState.displayStatus,
OSType = properties.storageProfile.osDisk.osType,
IdentityType = identity.type,
ComputerName = tolower(name)
| project ComputerName, id, location, resourceGroup, PowerStatus, OSType, IdentityType
| join kind=leftouter (
resources
| where type contains "microsoft.compute/virtualmachines/extensions"
| extend publisher = properties.publisher
| where publisher =~ "Microsoft.EnterpriseCloud.Monitoring"
| parse id with * "/virtualMachines/" ComputerName "/" *
| extend extensionType = properties.type,
status = properties.provisioningState,
version = properties.typeHandlerVersion,
ComputerName = tolower(ComputerName)
| project ComputerName, MMA = name, MMAStatus = status, version
)
on ComputerName
| join kind=leftouter (
resources
| where type contains "microsoft.compute/virtualmachines/extensions"
| extend publisher = properties.publisher
| where publisher =~ "Microsoft.Azure.Monitor"
| parse id with * "/virtualMachines/" ComputerName "/" *
| extend extensionType = properties.type,
status = properties.provisioningState,
version = properties.typeHandlerVersion,
ComputerName = tolower(ComputerName)
| project ComputerName, AMA = name, AMAStatus = status, AMAVersion = version
)
on ComputerName
| project ComputerName, location, resourceGroup, OSType, PowerStatus, MMA, MMAStatus, AMA, AMAStatus, AMAVersion

Below you'll find the results to help understand what we're looking at. Notice that in some cases, organizations are still running MMA, while others have already made the jump to AMA. This means we're seeing both agents in our environment, which could result in double logging from the same virtual machines.

COMPUTERNAMELOCATIONRESOURCEGROUPOSTYPEPOWERSTATUSMMAMMASTATUSAMAAMASTATUSAMAVERSION
comp-01uksouthrg-app-01WindowsVM deallocatedMicrosoftMonitoringAgentSucceededAzureMonitorWindowsAgentSucceeded1
comp-02uksouthrg-app-01WindowsVM runningMicrosoftMonitoringAgentSucceededAzureMonitorWindowsAgentSucceeded1
comp-03uksouthrg-app-01WindowsVM runningMicrosoftMonitoringAgentSucceededAzureMonitorWindowsAgentSucceeded1
comp-04ukwestrg-app-01WindowsVM runningMicrosoftMonitoringAgentSucceededAzureMonitorWindowsAgentSucceeded1
comp-05uksouthrg-app-01WindowsVM runningMicrosoftMonitoringAgentSucceededAzureMonitorWindowsAgentSucceeded1
comp-06ukwestrg-app-01WindowsVM runningMicrosoftMonitoringAgentSucceededAzureMonitorWindowsAgentSucceeded1
comp-07uksouthrg-app-01WindowsVM runningMicrosoftMonitoringAgentSucceededAzureMonitorWindowsAgentSucceeded1
comp-08uksouthrg-app-01WindowsVM runningMicrosoftMonitoringAgentSucceededAzureMonitorWindowsAgentSucceeded1

image

✔️ Conclusion

In this post, we've extended our Resource Graph query to include the extensions for the AMA agent. We've also combined the results for both MMA and AMA to gain a comprehensive overview of all the virtual machines and their respective reporting agents. Hopefully, this will help you to understand the current layout of your environment and which agents you need to transition from MMA to AMA. Please feel free to reach out to me if you have any questions or brainstorming ideas. I'm always happy to help!