VMware Cloud Community
robmatrovemobil
Contributor
Contributor

How to get the same host memory usage stats using powershell that I see in the vi client vm summary screen?

When I use the vi powershell get-stat -memory -realtime -maxsamples 1 for a vm I get stats mem.vmmemctl.average, mem.usage.average, mem.active.average and mem.granted.average. How do these numbers relate to what I see in the Infrastructure Client Summary tab for a VM? I believe the mem.active.average is what the VI client reports as Guest memory usage but even with converting the KB to MB by dividing by 1024 the numbers are not really close enough for me to be confident. None of those reported stats come close to the Host memory usage number in the VI client.

Thanks... Rob.

0 Kudos
3 Replies
LucD
Leadership
Leadership

I tested this on several guests (Windows & Linux) and the numbers Get-Stat returns are always within an acceptable range (+/- 5%) of what the Summary tab shows.

The following script was used for getting the values

$vm = Get-VM <Guest-name>

$memgrant = (Get-Stat -Stat mem.granted.average -Realtime -MaxSamples 1 -Entity $vm).value/1Kb
$memusage = (Get-Stat -Stat mem.usage.average -Realtime -MaxSamples 1 -Entity $vm).value

Write-Host "Host memory usage " $memgrant
Write-Host "Guest memory usage " ("{0:N2}" -f ($memgrant * $memusage / 100))

As a tip, for a better understanding have a look at session "TA21 Understand “Host”and “Guest”Memory Usage And Related Memory Management Concepts" that was presented at VMworld 2007 (provided you have a VMworld account of course).


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

robmatrovemobil
Contributor
Contributor

Thanks for the tip.

Usually what I get for mem.granted.average is +/- 5% of what I see in the summary tab for host memory usage, but for some vms it's WAY off, more that twice what is reported in the summary tab.

I find what I get for mem.active.average is close enough to the guest memory usage for my purposes, but I will try out your calculation below on machines where mem.granted.average is close to summary tab value.

Very strange... and discomforting...

0 Kudos
LucD
Leadership
Leadership

Some reflections:

1) mem.active.average is in fact the same as mem.usage.average. The first is in Kb, the 2nd as a percent of total available memory.

2) you probably know that the Windows OS accesses all memory after boot. This you can witness in the Perfomance tab, Memory-Realtime of a Windows guest.

"Guest memory usage" is not a good indicator immediately after a boot. You better wait a few minutes.

3) the author of the VMworld 2007 session TA21 (which I mentioned earlier) has contributed a paper on VirtualCenter Memory Statistic Definitions. Definitely worth a read.

4) the memory usage that is shown in the VC is never as accurate as what you can see in the guest itself. What amount of memory usage do you see inside the guest ?

Update:

While TA21 states "Guest has better visibility while estimating 'active' memory", there just appeared an entry in Mike D's Virtualization Blog on Using Perfmon in a Windows VM where he mentions a draft KB that states "Do not use guest OS performance tools to monitor virtual machine performance".

I'm curious to see the KB once it is published and if that claim is also true for memory usage statistics.


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

0 Kudos