VMware {code} Community
Pratik123
Contributor
Contributor

How to get Swap size of ESX host by VI SDK?

Hi,

Is there any API by which we can get the total swap space of a ESX host?

When we collect the performance data of ESX host, we get SwapUsed, SwapIn, SwapOut performance counters.

Can we also get the total swap?

It wont come while collecting performance data but can this value be available using any data objects of Host like Config or summary objects.

Thanks,

Pratik

0 Kudos
7 Replies
njain
Expert
Expert

To get the swap space on the ESX, you need to get the capacity of swap partition. This can be done using RetrieveDiskPartitionInfo method.

http://www.vmware.com/support/developer/vc-sdk/visdk25pubs/ReferenceGuide/vim.host.StorageSystem.htm...

This method will give you the partition details of an ESX disk and returns "HostDiskPartitionInfo" object. Now, you need to check the spec.partition.type property to identify the swap partition (linuxSwap) and then calculate the swap size as follows:

Capacity (in bytes) = 512 * (endSector – startSector)

Here,

startSector = spec.partition.startSector

endSector = spec.partition.endSector

Note, this would give you the size in bytes. You might want to convert this to MB unit.

Hope the above helps.

Pratik123
Contributor
Contributor

Hi,

Thanks for your response.

I think you are referring COS swap here.

Is there way to get the VMkernel swap?

Thanks,

Pratik

0 Kudos
RahulBhagat
Contributor
Contributor

...............

0 Kudos
m_daneri
VMware Employee
VMware Employee

Hi

Since ESX 3.x there isn't vmkernel swap, if you want you can get the VM swap

Max

0 Kudos
fordian
Hot Shot
Hot Shot

Hello,

Could you give an example of how you code this ?

Thank you

Dominic

0 Kudos
lamw
Community Manager
Community Manager

Take a look here:

=========================================================================

William Lam

VMware vExpert 2009

VMware ESX/ESXi scripts and resources at:

VMware Code Central - Scripts/Sample code for Developers and Administrators

If you find this information useful, please award points for "correct" or "helpful".

0 Kudos
Pratik123
Contributor
Contributor

Hi,

As told by max, we can calculate the Vm swap space for every powered on Vm.

That has answered my query.

Thanks to evryone for their comments. They were very helpful.

Pratik

0 Kudos