How to get a list of VMs that have Azure Monitor enabled using the REST API

Gem Libby 5 Reputation points
2023-02-01T09:24:21.64+00:00

On the Overview tab on https://portal.azure.com/#view/Microsoft_Azure_Monitoring/AzureMonitoringBrowseBlade/~/virtualMachines, there is a list of Virtual Machines that have Azure Monitor enabled.

I have been trying to get a list of those VMs through the Azure REST API but without success. Is there a way to get the VMs?

I have tried the following methods:

Called the API endpoint "https://management.azure.com/{resourceId}/providers/Microsoft.Insights/vmInsightsOnboardingStatuses/default?api-version=2018-11-27-preview". It does return some VMs that have Azure Monitor enabled but not all.

Used a KQL query on the Log Analytics API to get the heartbeats of VMs. It returns the heartbeats of all VMs including those that don't have Azure Monitor enabled. There seems to be no way of filtering out VMs without Azure Monitor.

Azure Monitor
Azure Monitor
An Azure service that is used to collect, analyze, and act on telemetry data from Azure and on-premises environments.
2,783 questions
Azure Virtual Machines
Azure Virtual Machines
An Azure service that is used to provision Windows and Linux virtual machines.
7,080 questions
0 comments No comments
{count} vote

2 answers

Sort by: Most helpful
  1. George Moise 2,346 Reputation points Microsoft Employee
    2023-02-01T13:49:15.3566667+00:00

    Hello,

    If you are looking to see which of the connected VMs are having the Virtual Machines Insights enabled in Azure Monitor, you can run the following Kusto Query on the Workspace where the VMs are connected:

    Heartbeat
    | where Solutions contains "VMInsights"
    | distinct Computer, OSType
    

    When an agent is sending its heartbeat to the Workspace, beside other information, it will also provide a list of the solutions that are enabled on that agent.
    That's why when you see VMInsights present in that Solutions property of the Heartbeat, it means that the agent was also enabled with VM Insights from Azure Monitor.

    Hope it helps!

    BR,

    George

    0 comments No comments

  2. George Moise 2,346 Reputation points Microsoft Employee
    2023-02-01T13:50:35.4133333+00:00

    Running this Kusto Query on your Workspace will tell you which agents are reporting that they have the Virtual Machines Insights (Azure Monitor) enabled:

    Heartbeat
    | where Solutions contains "VMInsights"
    | distinct Computer, OSType
    
    0 comments No comments