使用libvirt技术监控虚拟机(二) 博客分类: Libvirt 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里装的是网络信息