Azure api to get CPU Utilization % for multiple VMs in Single request

Ashish Sharma 6 Reputation points


I am looking for the azure rest api to get VM wise CPU Utilization % data for a subscription in a single request.

e.g. A subscription has multiple VMs and we need the metrics value for each VM for that subscription in a single request.

I went through the documentation and found that the Get request for only one VM per request-{SubscriptionID}/resourceGroups/{ResourceGroupName}/providers/Microsoft.Compute/virtualMachines/{VM Name}/providers/microsoft.insights/metrics?api-version=2019-07-01&metricnames=Percentage CPU

Please suggest.


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,785 questions
{count} votes

2 answers

Sort by: Most helpful
  1. tbgangav-MSFT 10,381 Reputation points

    Hi @Ashish Sharma and @CyrilAzoulay,

    Short answer to accomplish the requirement is install log analytics agents on the VMs and get the CPU Utilization % for VMs in single request through API by leveraging this and this API reference.

    Sample kusto query to use in this or this API:

    | where CounterName == @"% Processor Time"  
    | where ( InstanceName == "_Total" )    
    | summarize AggregatedValue= avg(CounterValue) by Computer, bin(TimeGenerated, 30s)  

    Here is the related detailed explanation w.r.t it.

    1 person found this answer helpful.

  2. CyrAz 5,176 Reputation points

    As far as I know you can't get metrics from multiple resources in a single query to the API but I'll gladly take any info that would prove me wrong, as I would absolutely benefit from that as well!

    0 comments No comments