Product SiteDocumentation Site

3.4.4. getCellsFreeMemory

The getCellsFreeMemory method can be used to obtain the amount of free memory (in kilobytes) in some or all of the NUMA nodes in the system. It takes as input the starting cell and the maximum number of cells to retrieve data from. If successful, Python list is returned with the amount of free memory in each node. On failure None is returned. The following code demonstrates the use of getCellsFreeMemory:

Example 3.14. Using getCellsFreeMemory

#!/usr/bin/env python3
import sys
import libvirt

conn = None
    conn ="qemu:///system")
except libvirt.libvirtError as e:
    print(repr(e), file=sys.stderr)

nodeinfo = conn.getInfo()
numnodes = nodeinfo[4]

memlist = conn.getCellsFreeMemory(0, numnodes)
cell = 0
for cellfreemem in memlist:
    print('Node '+str(cell)+': '+str(cellfreemem)+' bytes free memory')
    cell += 1