无法使用Get-AzureRmMetric访问[Guest]指标

问题描述 投票:0回答:1

我为Azure虚拟机启用了客户级指标,并尝试使用Get-AzureRMMetric获取[Guest] \ Memory \ Committed Bytes属性的历史记录。

$endTime = Get-Date
$startTime = $endTime.AddMinutes(-540)
$timeGrain = '00:05:00'
$metricName = '\Memory\Committed Bytes'


$history=(Get-AzureRmMetric -ResourceId $resourceId `
-TimeGrain $timeGrain -StartTime $startTime `
-EndTime $endTime `
-MetricNames $metricName)

$history.data | Format-table -wrap Average,Timestamp,Maxiumim,Minimum,Total

我收到以下错误:enter image description here

如果我将$metricname更改为任何主机指标(例如“Percentage CPU”),此代码可以正常工作,但我需要获取内存信息。

注意:这是在PowerShell 5.1中,我发现我可以在PowerShell v3中使用几乎相同的代码($history.metricvalues而不是$history.data),我可以在那里找到[Guest]指标,但不是任何主机指标。

Powershell v3 example

powershell azure metrics azure-powershell
1个回答
1
投票

目前,Azure PowerShell不支持使用Get-AzureRmMetric来获取memory usage指标。

我们可以使用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

关于Azure VM的受支持指标,请参阅此官方article

然后我们可以使用该值来获取其他指标:

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

这是我的PowerShell输出:

enter image description here

作为一种解决方法,我们可以使用OMS来获取内存使用情况,有关在OMS上配置性能计数器的更多信息,请参阅此link


更新:

你是对的,我们可以在Azure PowerShell版本3.4.0上运行此命令,它工作正常。

当我们在版本3.4.0上运行此命令时,我们将收到此警告:

警告:API弃用:旧版指标API的使用将在下一版本中停止使用。这意味着此cmdlet的调用和输出发生了更改。这是PowerShell输出:enter image description here

作为一种解决方法,我们可以通过REST API导出指标,有关它的更多信息,请参阅此link

© www.soinside.com 2019 - 2024. All rights reserved.