skip to Main Content

In the Azure portal, I can check/enable VM Monitoring Insights:

enter image description here

In the portal, we can get a list of VMs that are monitored here: https://portal.azure.com/#view/Microsoft_Azure_Monitoring/AzureMonitoringBrowseBlade/~/virtualMachines

How can I, using the Python SDK (preferably) or the Azure CLI:

  • Get a list of all VMs in a subscription that do not have this feature enabled?
  • Enable Monitoring Insights?

2

Answers


  1. Chosen as BEST ANSWER

    I haven't been able to find an API call that gives me what I need in an obvious (to me) fashion.

    However, calling az vm extension list/ComputeManagementClient.virtual_machine_extensions and checking if the AzureMonitorLinuxAgent or AzureMonitorWindowsAgent exists seems to correlate with the information we get in the Portal about whether the Monitoring Insights is active in a specific VM.


  2. Get a list of all VMs in a subscription that do not have this feature enabled?
    Enable Monitoring Insights?

    There are only below options to install VM Insights, refer the MS DOC for more details.

    enter image description here

    Here is a PowerShell script to enable VM Insights features on all VMs that are not already enabled in the subscription.

        Install-Script -Name Install-VMInsights
        
        $DcrResourceId =  "DCR_Resource-ID"
        $uamrgname = "User assigned managed identity rg name"
        $uamname ="User assigned managed identity name"
        $subid= "<SUB-ID>"
        $vmnames = Get-AzVM
        Foreach($vms in $vmnames){
        Write-Host : "Enabling VM Insight feature on VM name: $($vms.Name)"
        Install-VMInsights.ps1 -SubscriptionId $subid -ResourceGroup $vms.ResourceGroupName -Name $vms.Name -DcrResourceId $DcrResourceId -UserAssignedManagedIdentityName $uamrgname  -UserAssignedManagedIdentityResourceGroup $uamname
        }
    

    Output:

    enter image description here

    After running the script, the VM Insights feature has been enabled on the VMs

    enter image description here

    Reference: Enable VM insights by using PowerShell

    Check VMInsights on VMs

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search