Virtualization Technology News and Information
SCRIPT: Using WMI to determine memory usage by Virtual Server

Ben Armstrong reaches into his bag of tricks yet again to help out the Virtual Server community.  This time, Ben writes about using WMI to determine memory usage by Virtual Server.  In his latest article, he writes:

When you create a virtual machine under Virtual Server, you configure the amount of memory that you want that virtual machine to believe that it has (say 512mb of RAM).  However, Virtual Server needs to use more than that amount of memory to actually run the virtual machine.  Virtual Server also needs memory for itself to run emulated devices and store various information about the virtual machine in.  Unfortunately, because Virtual Server uses a driver (VMM.SYS) to allocate the memory this information is not easily to determine (i.e. it does not show up in task manager).  In the past I posted about how to use PerfMon to see how much memory Virtual Server was actually using, but today I have a nice little VB Script that talks to the Virtual Server WMI interfaces to determine this information.

Now - the fact that Virtual Server has WMI interfaces is very poorly documented - but they do exist and a primarily for gathering statistical information from Virtual Server.  Virtual Server uses a WMI namespace of \\root\vm\virtualserver, and this script connects to that namespace on the local computer, gets a collection of all of the virtual machine objects and then lists out the 'PhysicalMemoryAllocated' property of each virtual machine:

Option Explicit

Dim strComputer, objWMIService, colVMs, vm, totalMem

totalMem = 0
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\vm\virtualserver")
Set colVMs = objWMIService.ExecQuery( _
    "SELECT * FROM VirtualMachine",,48)
For Each vm in colVMs
    Wscript.Echo "-----------------------------------"
    Wscript.Echo & ":: Physical Memory Allocated: " & _
                        vm.PhysicalMemoryAllocated / 1048576 & _
   " MB (" & vm.PhysicalMemoryAllocated & " bytes)"
    totalMem = totalMem + vm.PhysicalMemoryAllocated

    Wscript.Echo "-----------------------------------"
    Wscript.Echo "All virtual machines"
    Wscript.Echo "-----------------------------------"
    Wscript.Echo "Physical Memory Allocated: " & totalMem / 1048576 _
   & " MB (" & totalMem & " bytes)"


Read, comment and thank Ben for the original article and scripting help, here.
Published Thursday, September 14, 2006 1:42 PM by David Marshall
Filed under:
There are no comments for this post.
To post a comment, you must be a registered user. Registration is free and easy! Sign up now!
<September 2006>