How can I get the average memory utilization of a group of VMs? I have a current report that uses get-vm to create a group of vm objects. I'd like to integrate a custom property that goes and gets the average memory utilization of this group of VMs and adds it as a custom property. I'd like to use Get-stat but I'm only at statistics level 1 so I can only use what is available through that.
get-vm -location somecluster1,anothercluster2 | select name, memorygb, numcpu, aMillionOtherProperties,
@{N="AverageRAMUsage";E={ABrilliantget-statSnippet}}
Ideas?
Thanks!
Over which period of time do you want to get this utilisation ?
In any case, you could do something like this, just remember to adapt the content of the $start variable
$clusterName = 'MyCluster'
$start = (Get-Date).AddHours(-1)
$stat = 'mem.usage.average'
$vms = Get-VM -Location (Get-Cluster -Name $clusterName)
Get-Stat -Entity $vms -Stat $stat -Start $start -ErrorAction SilentlyContinue |
Group-Object -Property {$_.Enity.Name} |
Select Name,
@{N='MemoryGB';E={$_.Group[0].Entity.MemoryGB}},
@{N='NumCpu';E={$_.Group[0].Entity.NumCpu}},
@{N='AverageRAMUsage';E={
[math]::Round(($_.Group[0] | Measure-Object -Property Value -Average | Select -ExpandProperty Average),2)
}}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Over which period of time do you want to get this utilisation ?
In any case, you could do something like this, just remember to adapt the content of the $start variable
$clusterName = 'MyCluster'
$start = (Get-Date).AddHours(-1)
$stat = 'mem.usage.average'
$vms = Get-VM -Location (Get-Cluster -Name $clusterName)
Get-Stat -Entity $vms -Stat $stat -Start $start -ErrorAction SilentlyContinue |
Group-Object -Property {$_.Enity.Name} |
Select Name,
@{N='MemoryGB';E={$_.Group[0].Entity.MemoryGB}},
@{N='NumCpu';E={$_.Group[0].Entity.NumCpu}},
@{N='AverageRAMUsage';E={
[math]::Round(($_.Group[0] | Measure-Object -Property Value -Average | Select -ExpandProperty Average),2)
}}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
ok thanks!