VMware Cloud Community
TheVMinator
Expert
Expert
Jump to solution

Average Memory Utilization

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!

Reply
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

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

View solution in original post

Reply
0 Kudos
2 Replies
LucD
Leadership
Leadership
Jump to solution

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

Reply
0 Kudos
TheVMinator
Expert
Expert
Jump to solution

ok thanks!

Reply
0 Kudos