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

Ashish Sharma 6 Reputation points
2020-09-24T13:30:28.977+00:00

Hi,

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-

https://management.azure.com/subscriptions/{SubscriptionID}/resourceGroups/{ResourceGroupName}/providers/Microsoft.Compute/virtualMachines/{VM Name}/providers/microsoft.insights/metrics?api-version=2019-07-01&metricnames=Percentage CPU

Please suggest.

Thanks,
Ashish

Azure Monitor
Azure Monitor
An Azure service that is used to collect, analyze, and act on telemetry data from Azure and on-premises environments.
3,320 questions
{count} votes

2 answers

Sort by: Most helpful
  1. tbgangav-MSFT 10,416 Reputation points
    2020-09-25T04:30:36.487+00:00

    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:

    Perf  
    | 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,181 Reputation points
    2020-09-24T18:12:44.68+00:00

    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

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.