feisky

云计算、虚拟化与Linux技术笔记
  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

libvirt获取实际内存的实现

Posted on 2011-11-26 14:57  feisky  阅读(1095)  评论(2编辑  收藏  举报
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来获取内存
 
   
无觅相关文章插件,快速提升流量