zoukankan      html  css  js  c++  java
  • virDomainMemoryStatStruct 以及 virDomainMemoryStatStruct的使用

    #include <libvirt/libvirt.h>
    #include <libvirt/virterror.h>
    #include "include/proxy.h"
    #include "include/rpc.h"
    
    int main(int argc, char ** argv) {
        virConnectPtr conn = virConnectOpen("qemu:///system");
        if(conn == NULL) {
            printf("error connecting qemu driver\n");
            exit(1);
        }
        virDomainPtr vm_ptr = virDomainLookupByName(conn, "template");
        if(vm_ptr == NULL) {
            printf("error finding domain\n");
            virConnectClose(conn);
            exit(1);
        }
        virDomainMemoryStatStruct stats[3];
        int res = virDomainMemoryStats(vm_ptr, stats, 3, 0);
        if(res >= 0) {
            for(int i = 0 ; i < res; i++) {
                printf("%d %llu\n", stats[i].tag, stats[i].val);
            }
        }
        virDomainFree(vm_ptr);
        virConnectClose(conn);
        return 0;
    }
    struct virDomainMemoryStatStruct {
    int tag;
    unsigned long ling val;
    }
    其中 tag取值:
    4 The amount of memory left completely unused by the system. Memory that is available but used for reclai mable caches should NOT be reported as free. This value is expressed in kB.
    5 The total amount of usable memory as seen by the domain. This value may be less than the amount of memo ry assigned to the domain if a balloon driver is in use or if the guest OS does not initialize all assi gned pages. This value is expressed in kB.
    6 Current balloon value (in KB)
    7 Resident Set Size of the process running the domain. This value is in kB

    对于普通的kvm虚拟机中,没有使用balloon driver,只能获得6和7参数。其中参数6是memory指定的数值,7会一直长到比6稍微大一点(如果没有设置currentMemory)
  • 相关阅读:
    如何稳定地使用 Google 搜索https://encrypted.google.com/
    widows 2008 同步时间命令
    MySql 初始化权限脚本
    [转] windows下Svn服务器之必须提交修改注释篇
    给编译好的DLL增加签名
    Anychart 破解备注
    Javascript 日期时间格式正则
    微服务项目规范(二)
    微服务项目规范(一)
    mac系统安装、启动与关闭redis
  • 原文地址:https://www.cnblogs.com/zhangzhang/p/2937650.html
Copyright © 2011-2022 走看看