Search code examples
azureazure-virtual-machineazure-sdk

How to monitor Azure Classic VM using REST API or via Java SDK?


HI i want to monitor Azure Classic VM using REST API/Java SDK , when i tried it with REST API with the following URL(The below url worked for Azure VM)

https://management.azure.com/subscriptions/<subscription_id>/resourceGroups/Preprod2-Resource-Group/providers/Microsoft.ClassicCompute/virtualMachines/cloudops-testvm1/providers/microsoft.insights/metrics?api-version=2016-09-01

I'm getting the following error

{ "code": "NotFound", "message": "Resource provider not found: [Microsoft.ClassicCompute]" }

Please suggest me if it can be done via REST API or if there is an SDK please suggest me the same.

My requirement is i want to monitor Classic VM and collect Network In,Network Out,Percentage CPU,Disk Read Operations/Sec,Disk Write Operations/Sec,Disk Write Bytes and Disk Read Bytes for every 5mins


Solution

  • This isn't a supported resource type through metrics API. The supported types and metrics are here:Supported metrics with Azure Monitor. You could check this link, for now, classic VM is not supported.

    According to your description, you could use the Metric Definitions API. It works for classic VM.

    https://management.azure.com/subscriptions/<subscription_id>/resourceGroups/<resourceGroups/>/providers/Microsoft.ClassicCompute/virtualMachines/<Virutal name>/providers/microsoft.insights/metricdefinitions?api-version=2015-07-01
    

    Metric information stores in Azure storage account, you also could call Storage API to get VM metrics. More information please refer to this link:Storage Analytics.