问题
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