PowerCLI

 View Only
  • 1.  get_stat memory counters

    Posted Aug 30, 2011 03:44 PM

    I have got the below script which reports on memory usage of VM's via using the get-stat command.   In our virtual centre out statistci levels are set to 1 for each interval duration, so we can only use basic counters.   The main counters for memory I have used are mem.usage.average and mem.consumed.average.  The script is below :

    $businessDays = "Monday","Tuesday","Wednesday","Thursday","Friday"
    $dayStart = New-Object DateTime(1,1,1,7,30,0)
    $dayEnd = New-Object DateTime(1,1,1,17,30,0)
    get-cluster "EO Cluster 0" |Get-VM | where {$_.PowerState -eq "PoweredOn" -and $_.MemoryMB -ge 4096} | `
    Select name,MemoryMB,
      @{N="Average Memory Usage Percentage";E={[math]::Round((get-stat -entity $_ -Start ((Get-Date).AddDays(-7)) -Finish (Get-Date) -stat mem.usage.average |Where-object {$businessDays -contains $_.Timestamp.DayOfWeek -and $_.timestamp.timeofday -gt $daystart.timeofday -and $_.timestamp.timeofday -lt $dayend.timeofday} | Measure-Object -Property Value -Average).Average)}},

    @{N="Average Memory Usage MB";E={[math]::Round((get-stat -entity $_ -Start ((Get-Date).AddDays(-7)) -Finish (Get-Date) -stat mem.consumed.average | Where-object {$businessDays -contains $_.Timestamp.DayOfWeek -and $_.timestamp.timeofday -gt $daystart.timeofday -and $_.timestamp.timeofday -lt $dayend.timeofday} | Measure-Object -Property Value -Average).Average / 1KB)}}

    This script gets values only from VM's which have more than 4GB of memory.

    The issue I have is understanding the counter values and in particular the counters.  For one of the VM's, i get the below values for the last 7 days :

    Name: VM Name

    MemoryMB: 4096

    Avg Memory Usage : 24      (mem.usage.average)

    Avg Memory Usage MB : 4096   (mem.consumed.average)

    or

    Name: VM Name

    MemoryMB: 6144

    Avg Memory Usage : 8   (mem.usage.average)

    Avg Memory Usage MB : 5879 (mem.consumed.average)

    I just wanted to find out what the mem.consumed.average value shows, as from the above value the average mem consumed is quite high same as the memory allocated but the percentage used is quite low.  So which value do we follow.  Does the consumed value shows that how much of the guest memory has been touched but not used.   Can anyone please advise, as I need to explain these reports to management.



  • 2.  RE: get_stat memory counters

    Posted Sep 04, 2011 01:42 PM

    In the PerformanceManager page for memory metrics you will find the definitions for both metrics.

    The mem.usage.average metric expresses a percentage showing the actively used memory over the configured memory. The mem.active.average metric shows the actual amount in MB. These are the pages, according to the VMkernel, that are recently touched by the OS in the guest.

    And the mem.consumed.average metric show the amount of memory that is reserved by the guest OS, but that might not be actually in use.

    In your first example, the guest OS has allocated 4 GB of memory.

    But the OS is only actively using (touching) 24% (or 983 MB) of that allocated memory, as seen in recent samples by the VMkernel.



  • 3.  RE: get_stat memory counters

    Posted Sep 15, 2011 08:32 AM

    Thanks Luc for your blog article about the performance metric in http://www.lucd.info/2011/07/08/powercli-vsphere-statistics-part-5-rollup-types/ and providing us the script, however I wonder why I could not add two more metrics in the following script:

    $metrics = "cpu.usage.average","cpu.ready.summation","cpu.swapwait.summation","mem.active.average"
    $entities = Get-VM
    $start = (Get-Date).AddMinutes(-5)
    $report = Get-Stat -Entity $entities -Stat $metrics -Realtime -Start $start | `
    Group-Object -Property EntityId,Timestamp | %{
      New-Object PSObject -Property @{
        Name = $_.Group[0].Entity.Name
        Time = $_.Group[0].Timestamp
        CpuAvg = ($_.Group | where {$_.MetricId -eq "cpu.usage.average"}).Value
    CpuRdy = ($_.Group | where {$_.MetricId -eq "cpu.ready.summation"}).Value
        CpuSwpWait = ($_.Group | where {$_.MetricId -eq "cpu.swapwait.summation"}).Value
        MemActAvg = ($_.Group | where {$_.MetricId -eq "mem.active.average"}).Value
       
      }
    }
    $report | Sort-Object Name,Time | Export-Csv "C:\VMstats.csv" -NoTypeInformation -UseCulture



  • 4.  RE: get_stat memory counters

    Posted Sep 15, 2011 08:45 AM

    These metrics return values for each instance and an aggregate (average over the instances).

    That means the Where-clause returns more than 1 object and hence the result is an array and the Value property is not there.

    The solution is to take the aggregate value for these 2 metrics.

    Something like this

    $metrics = "cpu.usage.average","cpu.ready.summation","cpu.swapwait.summation","mem.active.average" 
    $entities
    = Get-VM $start = (Get-Date).AddMinutes(-5) $report = Get-Stat -Entity $entities -Stat $metrics -Realtime -Start $start | Group-Object -Property EntityId,Timestamp | %{     New-Object PSObject -Property @{         Name = $_.Group[0].Entity.Name         Time = $_.Group[0].Timestamp         CpuAvg = ($_.Group | where {$_.MetricId -eq "cpu.usage.average"}).Value         CpuRdy = ($_.Group | where {$_.MetricId -eq "cpu.ready.summation" -and $_.Instance -eq ""}).Value         CpuSwpWait = ($_.Group | where {$_.MetricId -eq "cpu.swapwait.summation" -and $_.Instance -eq ""}).Value         MemActAvg = ($_.Group | where {$_.MetricId -eq "mem.active.average"}).Value     } } $report | Sort-Object Name,Time | Export-Csv "C:\VMstats.csv" -NoTypeInformation -UseCulture


  • 5.  RE: get_stat memory counters

    Posted Sep 15, 2011 02:47 PM

    Ah ok, now I understood, Thanks Luc for the reply.

    I appreciate your efforts in sharing and helping the community here.

    Cheers.



  • 6.  RE: get_stat memory counters

    Posted Sep 06, 2011 12:05 PM

    Memory Consumed is the actual amount of Machine Memory that has physical memory mapped to it.

    Memory Consumed = Memory Granted - Shared Pages.

    So it may happen that the sharing of pages between the VMs may be less thus Memory consumed value is very high.

    Memory size presented to the guest can categorised in two way.

    1) Allocated memory-Memory assigned to applications.

            Furthe it can be categorised in two ways:

                   a) Active Memory-Allocated memory recently accessed/used by application.

                   b) Idle Memory- Allocated memory recently not accessed/used by application

    2) Free memory-Memory not assigned.

    I thinks this will clarify your doubts.

    HTH

    shishir



  • 7.  RE: get_stat memory counters

    Posted Feb 22, 2012 12:05 AM

    Shishir, Thanks for the explanation.

    What is "Shared Pages" actually use for ? is this shared memory for use by the hypervisor (TPS) ?



  • 8.  RE: get_stat memory counters

    Posted Feb 24, 2012 03:47 PM

    Transparent page sharing is something that continuously keeps on running on the ESX host.TPS do not runs at VM level.So suppose you have powered on 4 windows VMs on the machine then what TPS will do is that it will start identifying the pages which are shared across VMs and will only keep one copy of it,that way we will save lot of memory.These are some of the way through which we achieve memory overcommitment.