Implementation of libvirt to obtain the actual memory
Libvirt can use virdomaingetinfo () to obtain VM information:
Struct virdomaininfo {
Unsigned char state: the running state, one of virdomainstate
Unsigned long maxmem: The maximum memory in Kbytes allowed
Unsigned long memory: the memory in Kbytes used by the domain
Unsigned short nr1_cpu: the number of virtual CPUs for the domain
Unsigned long cputime: the CPU time used in nanoseconds
}
Libvirt:
1. Use libxl_domain_info (): provides a way to get the struct libxl_dominfo
For a single domain given its domid.
CodeRead struct libxl_dominfo-> current_memkb
To obtain the actual memory, but the structure found on the internet is:
Struct libxl_dominfo {
Uint8_t UUID [16];
Uint32_t domid;
Uint8_t dying: 1;
Uint8_t paused: 1;
Uint8_t running: 1;
Uint64_t max_memkb;
Uint64_t cpu_time;
Uint32_t vcpu_max_id;
Uint32_t vcpu_online;
};
Xen-unstable provides this interface
2. Use xenapi: xen_vm_get_record () xen_vm_metrics_get_memory_actual ()
3. qemu: Obtain memory through balloninfo