使用libvirt技术监控虚拟机(二)

关于XML:

在libvirt中,虚拟机的信息是以XML的形式存储的,我们可以用方法来获取一个虚拟机(也就是一个Domain)的XML文件

char *caps;  

caps = malloc(sizeof(char)*1024);
caps = virDomainGetXMLDesc(allDomains[numOfDom],4);
free(caps);

  

使用

fprintf(stdout, "Capabilities:\n%s\n",caps);

把caps输出如下:

 

<domain type='xen' id='1'>                                    //虚拟机类型于虚拟机id
  <name>test1</name>
  <uuid>3eae3e71-a7c2-2bb0-035b-a6e1011ddc24</uuid>
  <memory>556032</memory>
  <currentMemory>524288</currentMemory>
  <vcpu>1</vcpu>
  <os>
    <type>hvm</type>
    <loader>/usr/lib/xen/boot/hvmloader</loader>
    <boot dev='hd'/>
  </os>
  <features>
    <acpi/>
    <apic/>
    <pae/>
  </features>
  <clock offset='utc'/>
  <on_poweroff>destroy</on_poweroff>
  <on_reboot>restart</on_reboot>
  <on_crash>restart</on_crash>
  <devices>                                                 
    <emulator>/usr/lib/xen/bin/qemu-dm</emulator>
    <disk type='file' device='disk'>
      <driver name='file'/>
      <source file='/var/lib/xen/images/test1.img'/>
      <target dev='hda' bus='ide'/>
    </disk>
    <interface type='bridge'>                        
      <mac address='00:16:3e:74:03:53'/>
      <source bridge='xenbr0'/>
      <script path='vif-bridge'/>
      <target dev='vif1.0'/>
    </interface>
    <serial type='pty'>
      <source path='/dev/pts/2'/>
      <target port='0'/>
    </serial>
    <console type='pty' tty='/dev/pts/2'>
      <source path='/dev/pts/2'/>
      <target port='0'/>
    </console>
    <input type='mouse' bus='ps2'/>
    <graphics type='vnc' port='5901' autoport='yes' keymap='en-us'/>
  </devices>
</domain>

 

device件值对里装的是I/O信息,Interface里装的是网络信息

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值