Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.5k views
in Technique[技术] by (71.8m points)

how to get cpu usage of azure vm throught powershell

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"

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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:estdata> (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:

enter image description here

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

enter image description here

Hope it helps:)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
...