简体   繁体   English

如何通过Powershell获得Azure vm的cpu使用率

[英]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. 我们可以通过电源外壳查看CPU使用率的指标以及VM的其他详细信息吗? 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. 我试图编写一个Power Shell脚本来获取Azure虚拟机的所有详细信息,但它显示出一些错误,任何人都无法知道如何编写脚本来获取详细信息。


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" 我能够获取虚拟机详细信息Get-AzureRmVM -ResourceGroupName“ RG”-名称“ VM”-状态,但是我没有获得CPU使用率,因此尝试了一些表内容“ WADPerformanceCountersTable”规则:-“ \\ Processor(_Total)\\ %处理器时间“

Maybe we can use this Azure PowerShell command Get-AzureRmMetric to get CPU usage. 也许我们可以使用此Azure PowerShell命令Get-AzureRmMetric来获取CPU使用率。

We can use Get-AzureRmMetricDefinition to get the supported metrics, here are the metrics of Azure VM: 我们可以使用Get-AzureRmMetricDefinition获取支持的指标,以下是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 . 有关Azure VM的支持指标的更多信息,请参考此链接

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: 这是PowerShell的输出:

在此处输入图片说明

If your Azure PowerShell version is 3.4.0, we can use this command to get guest metrics: 如果您的Azure PowerShell版本是3.4.0,我们可以使用以下命令获取访客指标:

在此处输入图片说明

Hope it helps:) 希望能帮助到你:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM