如何通过Powershell获得Azure vm的cpu使用率 [英] how to get cpu usage of azure vm throught powershell

查看:125
本文介绍了如何通过Powershell获得Azure vm的cpu使用率的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们能否通过电源外壳查看CPU使用率的指标以及VM的其他详细信息. 我试图编写一个Power Shell脚本来获取Azure虚拟机的所有详细信息,但它显示出一些错误,任何人都无法知道如何编写脚本来获取详细信息.

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.

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

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"

推荐答案

也许我们可以使用此Azure PowerShell命令Get-AzureRmMetric来获取CPU使用率.

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

我们可以使用Get-AzureRmMetricDefinition获取受支持的指标,这是Azure VM的指标:

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

有关Azure VM的支持指标的更多信息,请参考此

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"

这是PowerShell的输出:

Here is the PowerShell output:

如果您的Azure PowerShell版本是3.4.0,我们可以使用此命令获取访客指标:

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

希望它会有所帮助:)

这篇关于如何通过Powershell获得Azure vm的cpu使用率的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆