libvirt获取实际内存的实现

libvirt获取实际内存的实现

libvirt可以通过virDomainGetInfo()来得到虚机信息:
   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     nrVirtCpu     : the number of virtual CPUs for the domain
       unsigned long long     cpuTime     : the CPU time used in nanoseconds
   }

libvirt获取虚拟机实际内存的实现方法:

1. 通过libxl_domain_info():provides a way to get the struct libxl_dominfo 
for a single domain given its domid.
  
    代码里是读取struct libxl_dominfo -> current_memkb
来得到实际内存,但是从网上搜到的结构体为:
    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提供了这个接口

2. 通过xenapi: xen_vm_get_record() xen_vm_metrics_get_memory_actual()
 
3. QEMU: 通过BallonInfo来获取内存
 
   

你可能感兴趣的:(lib)