how to get cpu usage of azure vm throught powershell

杀马特。学长 韩版系。学妹 提交于 2019-12-04 06:57:52

问题


can we see the metrics of the CPU usage and other details of the VM through power shell. i am trying to write a power shell script to get all the details of the azure virtual machine it show some error can any one have idea about how to write a script to get the details.


i am able to get the vm details Get-AzureRmVM -ResourceGroupName "RG" -Name "VM" -Status but i am not getting cpu usage for that i tried some table contents "WADPerformanceCountersTable" rule:- "\Processor(_Total)\% Processor Time"


回答1:


Maybe we can use this Azure PowerShell command Get-AzureRmMetric to get CPU usage.

We can use Get-AzureRmMetricDefinition to get the supported metrics, here are the metrics of 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

More information about supported metrics of Azure VM, please refer to this link.

Then we can use the value to get metrics:

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

Here is the PowerShell output:

If your Azure PowerShell version is 3.4.0, we can use this command to get guest metrics:

Hope it helps:)



来源:https://stackoverflow.com/questions/46667074/how-to-get-cpu-usage-of-azure-vm-throught-powershell

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!