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
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.
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.
For now, Azure PowerShell does not support to use
Get-AzureRmMetric
to getmemory usage
metrics.We can use
Get-AzureRmMetricDefinition
to get the supported metrics:Here are the metrics for Azure VM:
About supported metrics of Azure VM, please refer to this official article.
Then we can use the value to get other metrics:
Here is my PowerShell output:
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.
Update:
You are right, we can run this command on Azure PowerShell version 3.4.0, it works fine.
When we run this command on Version 3.4.0, we will get this warning:
As a workaround, we can via the REST API to export metrics, more information about it, please refer to this link.