PowerCLI

 View Only
  • 1.  Average Memory Usage with Get-Stat

    Posted Oct 21, 2013 06:41 PM

    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!



  • 2.  RE: Average Memory Usage with Get-Stat

    Posted Oct 21, 2013 06:51 PM

    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.



  • 3.  RE: Average Memory Usage with Get-Stat

    Posted Oct 22, 2013 12:05 AM

    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!



  • 4.  RE: Average Memory Usage with Get-Stat

    Posted Oct 22, 2013 08:28 AM

    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)}}
       


  • 5.  RE: Average Memory Usage with Get-Stat

    Posted Oct 23, 2013 12:22 AM

    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?



  • 6.  RE: Average Memory Usage with Get-Stat
    Best Answer

    Posted Oct 23, 2013 05:21 AM

    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



  • 7.  RE: Average Memory Usage with Get-Stat

    Posted Jan 17, 2014 07:36 PM

    OK thanks again.