无法使用Get-AzureRmMetric访问[来宾]指标 [英] Unable to Access [Guest] metrics using Get-AzureRmMetric
问题描述
我为Azure虚拟机启用了访客级指标,并正在尝试使用Get-AzureRMMetric
获取 [来宾] \ Memory \ Committed Bytes 属性的历史记录.
I have guest-level metrics enable for an Azure Virtual Machine and am trying to get the history for the [Guest]\Memory\Committed Bytes property using Get-AzureRMMetric
.
$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
我收到以下错误:
如果我将$metricname
更改为任何主机指标(例如,"CPU百分比"),此代码都可以正常工作,但是我需要获取内存信息.
This code works fine if I change the $metricname
to any of the host metrics ("Percentage CPU" for example), but I need to get the memory information.
注意:这是在PowerShell 5.1中,我发现我可以在PowerShell v3中使用几乎相同的代码($history.metricvalues
而不是$history.data
),并且可以进入 [来宾] 指标,但没有任何主机指标.
Note: This is in PowerShell 5.1, I've found that I can use almost the same code ($history.metricvalues
rather than $history.data
) in PowerShell v3 and I can get to the [Guest] metrics there, but not any of the host metrics.
推荐答案
目前,Azure PowerShell不支持不使用Get-AzureRmMetric
获取memory usage
指标.
For now, Azure PowerShell does not support to use Get-AzureRmMetric
to get memory usage
metrics.
我们可以使用Get-AzureRmMetricDefinition
获取受支持的指标:
We can use Get-AzureRmMetricDefinition
to get the supported metrics:
以下是Azure VM的指标:
Here are the metrics for 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的支持指标,请参考此官方文章.
About supported metrics of Azure VM, please refer to this official article.
然后我们可以使用该值获取其他指标:
Then we can use the value to get other metrics:
Get-AzureRmMetric -ResourceId $id -TimeGrain 00:01:00 -DetailedOutput -MetricNames "Network in"
这是我的PowerShell输出:
Here is my PowerShell output:
作为一种解决方法,我们可以使用OMS获取内存使用情况,有关在OMS上配置性能计数器的更多信息,请参考此
As a workaround, we can use OMS to get the Memory usage, more information about configuring performance counters on OMS, please refer to this link.
更新:
您是对的,我们可以在Azure PowerShell版本3.4.0上运行此命令,效果很好.
You are right, we can run this command on Azure PowerShell version 3.4.0, it works fine.
在版本3.4.0上运行此命令时,将收到以下警告:
When we run this command on Version 3.4.0, we will get this warning:
警告:不赞成使用API:将使用传统指标API 在下一个版本中不再提供.这意味着通话发生了变化 以及此cmdlet的输出. 这是PowerShell的输出:
WARNING: API deprecation: The use of the legacy metrics API will be discontinued in the next release. This implies a change in the call and the output of this cmdlet. Here is the PowerShell output:
作为一种解决方法,我们可以通过REST API导出指标,有关它的更多信息,请参考此
As a workaround, we can via the REST API to export metrics, more information about it, please refer to this link.
这篇关于无法使用Get-AzureRmMetric访问[来宾]指标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!