Product SiteDocumentation Site

4.6.3. Memory Statistics

To obtain the amount of memory currently used by the domain you can use the memoryStats method.
from __future__ import print_function
import sys
import libvirt

domName = 'Fedora22-x86_64-1'

conn ='qemu:///system')
if conn == None:
    print('Failed to open connection to qemu:///system', file=sys.stderr)

dom = conn.lookupByID(5)
if dom == None:
    print('Failed to find the domain '+domName, file=sys.stderr)

stats  = dom.memoryStats()
print('memory used:')
for name in stats:
    print('  '+str(stats[name])+' ('+name+')')

Example 4.41. Get the memory statistics

Note that the memoryStats returns a dictionary object. This object will contain a variable number of entries depending on the hypervisor and guest domain capabilities.