When we login to azure portal and have a look at any resource like VM, we will see some monitoring data in Overview section of each resource which shows us charts for 30 days. (CPU average, network in/out etc)

My requirement is to not make any changes to azure resources via portal or cli. But i am rather looking for a powershell / azure cli command which will pull all this data from azure to my local machine for some analysis.

I am looking for VM, Web apps and Azure SQL to start with.


  • What kind of analysis? Why aren’t you using something like OMS Inisights & Analytics to capture, chart, and alert on this data? – MDMarra Nov 11 '17 at 0:32
  • I am trying to do some other analysis on this data and would like it to code it out myself. I have around 200 VMs plus other resources and i am trying to code a personalized dashboard around few analysis myself. Have seen all the azure and other 3rd party tools and none meet my criteria. IF i get just get this data via cli or powershell, i can do rest myself in no time. – Rajan Bhayana Nov 11 '17 at 0:36
  • 1
    i think i got what i needed. az monitor metrics list --resource /subscriptions/xxxxxxx/resourceGroups/xxxxx/providers/Microsoft.Compute/virtualMachines/xxxx --metric-names "Percentage CPU" --time-grain "PT1M" >> PercentageCpuData.txt – Rajan Bhayana Nov 11 '17 at 23:16

You are right, we can use CLI 2.0 to get the metric data:

az monitor metrics list --resource /subscriptions/xxxxxxx/resourceGroups/xxxxx/providers/Micros‌​oft.Compute/virtualM‌​achines/xxxx --metric-names "Percentage CPU" --time-grain "PT1M" >> PercentageCpuData.txt

Also we can use Azure PowerShell command Get-AzureRmMetricDefinition to get metrics.

Here are the metrics for Azure VM:

PS D:\testdata> (Get-AzureRmMetricDefinition -ResourceId $id).name

Value                     LocalizedValue
-----                     --------------
Percentage CPU            Percentage CPU
Network In                Network In
Network Out               Network Out
Disk Read Bytes           Disk Read Bytes
Disk Write Bytes          Disk Write Bytes
Disk Read Operations/Sec  Disk Read Operations/Sec
Disk Write Operations/Sec Disk Write Operations/Sec
CPU Credits Remaining     CPU Credits Remaining
CPU Credits Consumed      CPU Credits Consumed

Then we can use the value to get other metrics:

Get-AzureRmMetric -ResourceId $id -TimeGrain 00:01:00 -DetailedOutput -MetricNames "Network in"

Here a similar case about you, please refer to it.

By the way, difference about Azure Host metrics and Guest metrics, please refer to this link.

  • not able to +1 it but can confirm that the above approached worked for me. – Rajan Bhayana Nov 20 '17 at 2:56
  • We can follow this link to accept it, thank you:) – Jason Ye Nov 20 '17 at 2:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.