PowerCLI: Find Resourcepool or VMs with Memory Ballooning/Swap Usage


 image image

In this post I will show you how to report Resource Pools and VMs with active Memory Ballooning. But what is Memory Ballooning. I short quote from the ESX3 memory whitepaper http://www.vmware.com/pdf/esx3_memory.pdf:

The balloon driver, also known as the vmmemctl driver, collaborates with the server to reclaim pages that are considered least valuable by the guest operating system. It essentially acts like a native program in the operating system that requires more and more memory. The driver uses a proprietary ballooning technique that provides predictable performance that closely matches the behavior of a native system under similar memory constraints. This technique effectively increases or decreases memory pressure on the guest operating system, causing the guest to invoke its own native memory management algorithms. When memory is tight, the guest operating system decides which particular pages to reclaim and, if necessary, swaps them to its own virtual disk.

You need to be sure your guest operating systems have sufficient swap space. This swap space must be greater than or equal to the difference between the virtual machine’s configured memory size and its reservation.

More information about Memory ballooning can also be found in this post by Arnim van Lieshout.

So let’s continue with the PowerCLI scripts.

The following script will report all the resource pools with active Memory Ballooning:

$myCol = @()
foreach($clus in (Get-Cluster)){
 foreach($rp in (Get-ResourcePool -Location $clus | Get-View | Where-Object `
  {$_.Name -ne "Resources" -and `
   $_.Summary.QuickStats.BalloonedMemory -ne "0"})){
   $Details = "" | Select-Object Cluster, ResourcePool, `
   SwappedMemory ,BalloonedMemory

    $Details.Cluster = $clus.Name
    $Details.ResourcePool = $rp.Name
    $Details.SwappedMemory = $rp.Summary.QuickStats.SwappedMemory
    $Details.BalloonedMemory = $rp.Summary.QuickStats.BalloonedMemory

    $myCol += $Details
  }
}
$myCol

#$myCol | Export-Csv -NoTypeInformation C:\RPs-Ballooning.csv

This will be the output:

image

If you add the script to a powerpack within the Virtualization EcoShell, It will look like this:

image

If you want to report the VMs with active memory ballooning, you can run the following script:

$myCol = @()
foreach($vm in (Get-View -ViewType VirtualMachine | Where-Object `
  {$_.Summary.QuickStats.BalloonedMemory -ne "0"})){
   $Details = "" | Select-Object VM, `
   SwappedMemory ,BalloonedMemory

    $Details.VM = $vm.Name
    $Details.SwappedMemory = $vm.Summary.QuickStats.SwappedMemory
    $Details.BalloonedMemory = $vm.Summary.QuickStats.BalloonedMemory

    $myCol += $Details
  }
$myCol

And within a couple of seconds, you’ll get a list with all the VMs with active ballooning:

image

If you add the script to a powerpack within the Virtualization EcoShell, It will look like this:

image

About these ads

3 Responses to PowerCLI: Find Resourcepool or VMs with Memory Ballooning/Swap Usage

  1. René says:

    Nog even en we kunnen het ICT-Freak powerpack voor de EcoShell downloaden. Ik kijk er naar uit.

  2. Andrew says:

    Nice script. I’d add a check for swapped memory as often we see VMs with no ballooning but with memory swapped.

    $_.Summary.QuickStats.BalloonedMemory -ne "0" -or $_.Summary.QuickStats.SwappedMemory -ne "0"

  3. Kyle says:

    Great Script! Is there a way to report on VMs that had memory ballooning issues within the last 24hours instead of just at this exact moment in time? I would like to include this as part of a nightly health check script.Thanks!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

Join 1,173 other followers

%d bloggers like this: