简介:libvirt 使用QEMU agent,就是运行在Guest OS里面的一个小服务。这个服务负责hypervisor和Guest之间进行通信的。Hypervisor使用这个通道去获取guest OS的信息或执行命令。这个通道的协议叫做Qemu Machine Protocol. 比如,libvirt使用agent去获取网络和文件系统的详细信息。它们是通过virtio-serial或者通过isa-serial通道,又叫做org.qemu.guest_agent.0。 在hypervisior服务器这边也会创建一个文件,在/var/lib/libvirt/qemu/channel/target/.
(1)我们在Guest OS中安装客户端
$ sudo yum install qemu-guest-agent
(2)然后我们重新启动我们的Guest-OS,查看信息,是否为运行状态 。
systemctl status qemu-geust-agent
(3)第二步如果为运行状态,我们在hypervisor上执行查询信息,进行检验。
$ sudo virsh qemu-agent-command centos7.0 '{"execute": "guest-info"}' --pretty
{
"return": {
"version": "2.8.0",
"supported_commands": [
{
"enabled": true,
"name": "guest-sync-delimited",
"success-response": true
},
{
"enabled": true,
"name": "guest-sync",
"success-response": true
},
{
"enabled": true,
"name": "guest-suspend-ram",
"success-response": false
},
{
"enabled": true,
"name": "guest-suspend-hybrid",
"success-response": false
},
windows客户端这里不再详述。详见链接地址:https://fedoraproject.org/wiki/Windows_Virtio_Drivers.
二. 资源收集
(1)获取hypervisor CPU的利用率
root@kvm:~# virsh nodecpustats --percent
usage: 0.0%
user: 0.0%
system: 0.0%
idle: 100.0%
iowait: 0.0%
(2)获取 hypervisor 内存的利用率
root@kvm:~# virsh nodememstats
total : 131918328 KiB
free : 103633700 KiB
buffers: 195532 KiB
cached : 25874840 KiB
(3)检查KVM的实例状态
root@kvm:~# virsh domstate kvm1
running
(4)获取分配给KVM实例的CPU数量
root@kvm:~# virsh vcpucount --current kvm1 --live
1
(5)收集Guest虚拟CPU的详细信息
root@kvm:~# virsh vcpuinfo kvm1
VCPU: 0
CPU: 29
State: running
CPU time: 118.8s
CPU Affinity: yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy
(6)获取关于虚拟VM CPU的timer信息
root@kvm:~# virsh cpu-stats --total kvm1
Total:
cpu_time 175.003045493 seconds
user_time 2.610000000 seconds
system_time 7.510000000 seconds
(7)获取关于vm的常规信息。
root@kvm:~# virsh dominfo kvm1
Id: 30
Name: kvm1
UUID: bd167199-c1c4-de7e-4996-43a7f197e565
OS Type: hvm
State: running
CPU(s): 1
CPU time: 175.6s
Max memory: 1048576 KiB
Used memory: 1048576 KiB
Persistent: yes
Autostart: disable
Managed save: no
Security model: none
Security DOI: 0
(8)获取MV的内存利用率
root@kvm:~# virsh dommemstat --live kvm1
actual 1048576
swap_in 0
rss 252684
(9)获取KVM实例关联的块设备信息
root@kvm:~# virsh domblklist kvm1
Target Source
------------------------------------------------
hda /var/lib/libvirt/images/kvm1.img
(10)获取块设备信息的大小
root@kvm:~# virsh domblkinfo --device hda kvm1
Capacity: 8589934592
Allocation: 2012381184
Physical: 2012381184
(11)获取KVM实例关联的块设备错误 信息
root@kvm:~# virsh domblkerror kvm1
No errors found
(12)查看KVM实例的块设备统计信息
root@kvm:~# virsh domblkstat --device hda --human kvm1
Device: hda
number of read operations: 42053
number of bytes read: 106145280
number of write operations: 10648
number of bytes written: 96768000
number of flush operations: 4044
total duration of reads (ns): 833974071
total duration of writes (ns): 1180545967
total duration of flushes (ns): 3458623200
(13)获取虚拟机的进程信息
root@kvm:~# pgrep -lfa kvm1
32332 /usr/bin/qemu-system-x86_64 -name kvm1 -S -machine pc- i440fx-trusty,accel=kvm,usb=off -m 1024 -realtime mlock=off -smp 1,sockets=1,cores=1,threads=1 -uuid bd167199-c1c4-de7e-4996-43a7f197e565 -no-user-config -nodefaults -chardev socket,id=charmonitor,path=/var/lib/libvirt/qemu/kvm1.monitor,server,nowait -mon chardev=charmonitor,id=monitor,mode=control -rtc base=utc -no-shutdown -boot strict=on -device piix3-usb-uhci,id=usb,bus=pci.0,addr=0x1.0x2 -drive file=/var/lib/libvirt/images/kvm1.img,if=none,id=drive-ide0-0-0,format=raw -device ide-hd,bus=ide.0,unit=0,drive=drive-ide0-0-0,id=ide0-0-0,bootindex=1 -netdev tap,fd=24,id=hostnet0 -device rtl8139,netdev=hostnet0,id=net0,mac=52:54:00:55:9b:d6,bus=pci.0,addr=0x3 -chardev pty,id=charserial0 -device isa-serial,chardev=charserial0,id=serial0 -vnc 146.20.141.158:0 -device cirrus-vga,id=video0,bus=pci.0,addr=0x2 -device virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x4