With a vSphere Client, you can easily check the memory information of a host, either ESX or ESXi. To get that, you click on a host from the inventory tree, and then configuration tab. From the left side Hardware section of the configuration page, you click Memory and see a pane displaying the memory info as follows:
Bothered by SLOW Web UI to manage vSphere? Want to manage ALL your VMware vCenters, AWS, Azure, Openstack, container behind a SINGLE pane of glass? Want to search, analyze, report, visualize VMs, hosts, networks, datastores, events as easily as Google the Web? Find out more about vSearch 3.0: the search engine for all your private and public clouds.
Note that if you have chosen a ESXi host, you won’t see the Service Console part because there is no console OS any more in ESXi. BTW, VMware wants you to migrate from ESX to ESXi and here is a link with helps.
This seemingly easy information is actually not easy to get. At first glance, it should be in the config property of HostSystem (managed object representing an ESX or ESXi). The config property has a sub property called systemResources, typed as HostSystemResourceInfo. But you will get null for the systemResources property most, if not all, of the time, as reported in VI Java API forum.
Interestingly enough, HostSystem has a systemResources property in peer to the config property as well. Luckily, it’s not null so you can dig down for something. Still, with 3 sub properties of complex types included, how to get the memory from the data object?
Here are the steps to collect and calculate the numbers:
Get the total memory
You will use the following property path for the number in bytes and then divide it by 1024*1024 for a number in MB.
If you use VI Java API, you can do like this:
double totalMemInMB = host.getSummary().getHardware().getMemorySize / (1024*1024);
Get virtual machines’ memory
This number is not dynamic reflecting the memory usage by virtual machines but rather the memory reserved for virtual machines. With this in mind, you can get it as follows:
Notice that it is not divided by 1024*1024. It turns out the number you get as reservation is in MB already.
Get Service Console memory
Again, it’s only for ESX as ESXi does not have console OS therefore not relevant. You can get it as follows:
Get the system memory
Naturally you would think of the systemResources property again. You can indeed find the recursive resource allocations for “host/system” along with others like “host/idle,” “host/vim,” and “host/user.” You can of course dig down these data object and may calculate a number with a sophisticated algorithm.
It turned out it’s not necessarily as complicated as we think if we notice the relationships of these numbers: Total = System + VM + ConsoleOS. With this in mind, the system memory could be as simple as deductions like this:
System = total – VM – ConsoleOS
With these steps you can get the same numbers as vSphere Client.