VMware Cloud Community
TheVMinator
Expert
Expert
Jump to solution

Average Memory Usage with Get-Stat

I am running this report and want to add average memory Usage in GB.  I'd like to account for all the memory that a VM has been demanding from ESXi, including overhead.

get-vm | select name, memoryGB

How can I add average memory demand to this report?

Thanks!

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

You can do

Get-StatType -Interval "Past Week" -Entity AnyVM | where {$_ -match "mem"} 

Just replace the AnyVM with a name of a VM in your environment


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

View solution in original post

0 Kudos
6 Replies
LucD
Leadership
Leadership
Jump to solution

Try something like this

Get-VM | 
Select Name, MemoryGB,@{N="MemoryConsumedGB";E={
    [
math]::Round(((Get-Stat -Entity $_ -Realtime -MaxSamples 1 -Stat "mem.consumed.average","mem.overhead.average" |
   
Measure-Object -Property Value -Sum | Select -ExpandProperty Sum)/1MB),1)
}}

It adds the currently consumed and overhead memory together.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

TheVMinator
Expert
Expert
Jump to solution

OK great thanks. 

  • Can I format this to get last 7 days rather than real-time?
  • Also, the value this is returning seems to be my provisioned RAM in GB instead of RAM used.  (I'm getting a flat 4GB for the Memory Usage calculation above on a VM that sits idle and reports 400 MB of memory usage in vSphere Client so I'm thinking something isn't right)
  • Can this be switched to MB instead of GB?

Thanks again for all the help!

0 Kudos
LucD
Leadership
Leadership
Jump to solution

It looks as if you are looking for the active memory in that case.

The following gets the average over 7 days.

Get-VM | 
Select Name, MemoryGB,@{N="MemoryConsumedGB";E={
    [
math]::Round((
    (
Get-Stat -Entity $_ -Start (Get-Date).AddDays(-7)-Stat "mem.active.average" |
   
Measure-Object -Property Value -Average | Select -ExpandProperty Average)/1MB),1)}}
   


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

TheVMinator
Expert
Expert
Jump to solution

OK thanks.  That gives me a blank.  I suspect it is my statistics logging level.  How can I check which statistics I do have available for memory for the last week so I know what I have to work with?

0 Kudos
LucD
Leadership
Leadership
Jump to solution

You can do

Get-StatType -Interval "Past Week" -Entity AnyVM | where {$_ -match "mem"} 

Just replace the AnyVM with a name of a VM in your environment


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
TheVMinator
Expert
Expert
Jump to solution

OK thanks again.

0 Kudos