The QEMU Monitor Protocol (QMP) is a JSON-based protocol which allows applications to communicate with a QEMU instance.

Read more about QMP here :wiki.qemu.org/QMP

Its a client server architecture where the data can be exchanged. The
monitor protocol is really useful for debugging, experimenting and also
useful for collecting statistics and for fetching data about the qemu
instance or VM.

There are different ways to access and talk over “QMP”:


1) Virsh/libvirt way using ‘qemu-monitor-command’
2) Using ‘telnet’ over ‘qmp’ socket
3) Using utitilties ‘qmp-shell’, nc, socat/rlwrap over ‘qmp’ socket..

Previously I used different hacks to talk with the VM instances via
qemu monitor protocol, but things are changing fast and now libvirt has a
decent interface to talk with the qemu instance using “QMP” protocol.

When talking over QMP , we have to use “qmp” syntax which is JSON formatted data for the communication. How-ever QMP’s subset called ‘hmp’ is also available to make life easy.

libvirt has added an option with ‘virsh’ to talk over QMP. Its
“qemu-monitor-command”. It has the capability of exchanging information
in ‘hmp’ format as well. You just need to on ‘-hmp’ over command line
for this .

As soon as you are connected to “QMP” server you will receive a
“greetings” banner from the server : Then you have to execute
“qmp_capabilities” command to start the communication:

“QMP” greeting banner will look like this:

{“QMP”: {“version”: {“qemu”: {“micro”: 50, “minor”: 5,
“major”: 1}, “package”: “”}, “capabilities”: []}} ==> “greetings”
banner is provided by “QMP”


{ “execute”: “qmp_capabilities” } ======> “You are moving into data exchange”

Now, let me show you the examples of using different utilities for this purpose..

1) VIRSH / LIBVIRT WAY:

  qemu-monitor-command  [--hmp] {[--cmd] }...

Below example will show you ‘virsh’ way of using it via ‘HMP’ and ‘QMP':

I have a guest running with domain id :3 . You may have different id, get it using “virsh list”

To get information about 'VM' block devices, registers, uuid, spice..etc :

[root@humbles-lap QMP]# virsh qemu-monitor-command --hmp 3 info block
drive-virtio-disk0: removable=0 io-status=ok file=/export/vmimgs/L1-f18.qcow2 ro=0 drv=qcow2 encrypted=0 bps=0 bps_rd=0 bps_wr=0 iops=0 iops_rd=0 iops_wr=0 [root@humbles-lap QMP]# virsh qemu-monitor-command --hmp 3 info registers
RAX=0000000000000096 RBX=00000000000f4240 RCX=0000000000000008 RDX=000000000000acac
RSI=0000000000000096 RDI=ffffffff81edd950 RBP=ffff88007fc03e68 RSP=ffff88007fc03e68
R8 =0000000000000002 R9 =0000000000000000 R10=0000000000000000 R11=0000000000000001
R12=00000000000e7aa4 R13=00000000000e7aa4 R14=fffffffffff0bdc0 R15=0000000000000007
RIP=ffffffff816628e4 RFL=00000086 [--S--P-] CPL=0 II=0 A20=1 SMM=0 HLT=0 root@humbles-lap QMP]# virsh qemu-monitor-command --hmp 3 info uuid
0d0946d1-9b07-4480-6647-815237b910e2 [root@humbles-lap QMP]# virsh qemu-monitor-command --hmp 3 info spice
Server:
address: 0.0.0.0:5900
migrated: false
auth: spice
compiled: 0.12.2
mouse-mode: client
Channel:
address: 127.0.0.1:47690
session: 1804289383
channel: 1:0
Channel:
address: 127.0.0.1:47695
session: 1804289383
channel: 4:0
Channel:
address: 127.0.0.1:47694
session: 1804289383
channel: 2:0
Channel:
address: 127.0.0.1:47696
session: 1804289383
channel: 3:0

Above examples used ‘hmp’ format, how-ever if you would like to use ‘qmp’ format , you just need to exclude ‘-hmp’ option from virsh command as shown below:

[root@humbles-lap QMP]# virsh qemu-monitor-command 3 '{"execute":"query-kvm"}'
{"return":{"enabled":true,"present":true},"id":"libvirt-34"} [root@humbles-lap QMP]#

Now lets look at other possibilities of talking to qemu instance via “qmp” protocol:

1) Start a qemu instance with a socket option and telnet to that:

[root@humbles-lap QMP]./x86_64-softmmu/qemu-system-x86_64 --enable-kvm -smp 2 -m 1024 /export/vmimgs/L1-f18.qcow2 -nographic -qmp tcp:localhost:4444,server

[root@humbles-lap qemu]$ telnet localhost 4444
Trying ::1...
Connected to localhost.
Escape character is '^]'.
{"QMP": {"version": {"qemu": {"micro": 50, "minor": 5, "major": 1}, "package": ""}, "capabilities": []}}

2) Try starting a qemu instance via ‘qmp’ UNIX socket and access it via ‘qmp-shell’, “nc”, “socat &rwrap” ..etc

[root@humbles-lap qemu]# ./x86_64-softmmu/qemu-system-x86_64 --enable-kvm -smp 2 -m 1024 /export/vmimgs/L1-f18.qcow2 -nographic -qmp unix:./qmp-sock-exp,server

There is a program called ‘qmp-shell” shipped or available from upstream qemu:

Inside “QMP” directory you have the mentioned programm:

[root@humbles-lap qemu]# ./QMP/qmp-shell ./qmp-sock-exp
Welcome to the QMP low-level shell!
Connected to QEMU 1.5.50 (QEMU)
(QEMU) q
qmp_capabilities query-block-jobs query-events query-migrate-capabilities query-tpm
qom-get query-blockstats query-fdsets query-name query-tpm-models
qom-list query-chardev query-kvm query-pci query-tpm-types
qom-list-types query-command-line-options query-machines query-rx-filter query-uuid
qom-set query-commands query-mice query-spice query-version
query-balloon query-cpu-definitions query-migrate query-status query-vnc
query-block query-cpus query-migrate-cache-size query-target quit
(QEMU) (QEMU) query-chardev
{u'return': [{u'label': u'parallel0', u'filename': u'null'}, {u'label': u'serial0', u'filename': u'stdio'}, {u'label': u'compat_monitor0', u'filename': u'unix:./qmp-sock-exp,server'}]}
(QEMU) (QEMU) query-block
{u'return': [{u'locked': False, u'type': u'unknown', u'io-status': u'ok', u'removable': False, u'device': u'ide0-hd0', u'inserted': {u'bps_rd': 0, u'backing_file_depth': 0, u'encrypted': False, u'image': {u'cluster-size': 65536, u'format': u'qcow2', u'filename': u'/export/vmimgs/L1-f18.qcow2', u'virtual-size': 15032385536, u'dirty-flag': False, u'actual-size': 8293609472}, u'bps_wr': 0, u'drv': u'qcow2', u'bps': 0, u'iops': 0, u'file': u'/export/vmimgs/L1-f18.qcow2', u'iops_rd': 0, u'encryption_key_missing': False, u'ro': False, u'iops_wr': 0}}, {u'locked': False, u'tray_open': False, u'io-status': u'ok', u'removable': True, u'device': u'ide1-cd0', u'type': u'unknown'}, {u'device': u'floppy0', u'type': u'unknown', u'tray_open': False, u'locked': False, u'removable': True}, {u'device': u'sd0', u'type': u'unknown', u'tray_open': False, u'locked': False, u'removable': True}]}
(QEMU) (QEMU) query-kvm
{u'return': {u'enabled': True, u'present': True}}
(QEMU) (QEMU) query-vnc
{u'return': {u'enabled': False}}
(QEMU) (QEMU) quit
{u'return': {}}
(QEMU) quit
Disconnected

Now , lets move to the example of using ‘nc’ :

[root@humbles-lap qemu]# nc -U ./qmp-sock-exp
{"QMP": {"version": {"qemu": {"micro": 50, "minor": 5, "major": 1}, "package": ""}, "capabilities": []}} ==> "greetings" banner is provided by "QMP" { "execute": "qmp_capabilities" } ======> "You are moving into data exchange"
{"return": {}} { "execute": "query-vnc" }
{"return": {"enabled": false}} Ctrl+D

Last one to access “QMP” is via ‘socat’ and ‘rlwrap':

You need to install ‘socat & rlwrap’ for experimenting this.

[root@humbles-lap qemu]# rlwrap  socat UNIX-CONNECT:./qmp-sock-exp STDIO
{"QMP": {"version": {"qemu": {"micro": 50, "minor": 5, "major": 1}, "package": ""}, "capabilities": []}} { "execute": "query-pci" }
{"return": [{"bus": 0, "devices": [{"bus": 0, "qdev_id": "", "slot": 0, "class_info": {"class": 1536, "desc": "Host bridge"}, "id": {"device": 4663, "vendor": 32902}, "function": 0, "regions": []}, {"bus": 0, "qdev_id": "", "slot": 1, "class_info": {"class": 1537, "desc": "ISA bridge"}, "id": {"device": 28672, "vendor": 32902}, "function": 0, "regions": []}, {"bus": 0, "qdev_id": "", "slot": 1, "class_info": {"class": 257, "desc": "IDE controller"}, "id": {"device": 28688, "vendor": 32902}, "function": 1, "regions": [{"bar": 4, "size": 16, "address": 49216, "type": "io"}]}, {"bus": 0, "qdev_id": "", "irq": 9, "slot": 1, "class_info": {"class": 1664, "desc": "Bridge"}, "id": {"device": 28947, "vendor": 32902}, "function": 3, "regions": []}, {"bus": 0, "qdev_id": "", "slot": 2, "class_info": {"class": 768, "desc": "VGA controller"}, "id": {"device": 184, "vendor": 4115}, "function": 0, "regions": [{"prefetch": true, "mem_type_64": false, "bar": 0, "size": 33554432, "address": 4227858432, "type": "memory"}, {"prefetch": false, "mem_type_64": false, "bar": 1, "size": 4096, "address": 4273930240, "type": "memory"}, {"prefetch": false, "mem_type_64": false, "bar": 6, "size": 65536, "address": -1, "type": "memory"}]}, {"bus": 0, "qdev_id": "", "irq": 11, "slot": 3, "class_info": {"class": 512, "desc": "Ethernet controller"}, "id": {"device": 4110, "vendor": 32902}, "function": 0, "regions": [{"prefetch": false, "mem_type_64": false, "bar": 0, "size": 131072, "address": 4273733632, "type": "memory"}, {"bar": 1, "size": 64, "address": 49152, "type": "io"}, {"prefetch": false, "mem_type_64": false, "bar": 6, "size": 262144, "address": -1, "type": "memory"}]}]}]} Ctrl+ D

Hope this was helpful!!!

http://www.humblec.com/qmp-qemu-monitor-protocol-and-different-ways-of-accessing-it/

QMP ( qemu monitor protocol ) and Different ways of accessing it的更多相关文章

  1. 基于QMP实现对qemu虚拟机进行交互

    本文详解QMP,包含qmp.hmp.qemu-guest-agent的介绍.工作原理.配置方法.范例 小慢哥的原创文章,欢迎转载 目录 ▪ QMP介绍 ▪ QMP语法 ▪ 单独使用qemu,启用QMP ...

  2. 利用Qemu Guest Agent (Qemu-ga) 实现 Openstack 监控平台

    经常使用vmWare的同学都知道有vmware-tools这个工具,这个安装在vm内部的工具,可以实现宿主机与虚拟机的通讯,大大增强了虚拟机的性能与功能, 如vmware现在的Unity mode下可 ...

  3. 干货分享: 长达250页的Libvirt Qemu KVM的ppt,不实验无真相

    下载地址:Libvirt Qemu KVM 教程大全 http://files.cnblogs.com/popsuper1982/LibvirtQemuKVM.pptx 1. 概论 1.1 虚拟化的基 ...

  4. 基于KVM的qemu中宿主机和虚拟机间的通信

    qga是一个运行在虚拟机内部的普通应用程序(可执行文件名称默认为qemu-ga,服务名称默认为qemu-guest-agent),其目的是实现一种宿主机和虚拟机进行交互的方式,这种方式不依赖于网络,而 ...

  5. Libvmi实现分析

    LibVMI是一个专注于读写虚拟机内存的自省库,它能够监视虚拟机底层的运行细节并将其还原.LibVMI支持对Xen及KVM虚拟化平台上的运行虚拟机进行自省操作,针对KVM虚拟化平台,LibVMI对QE ...

  6. qemu-guest-agent简介

    经常使用vmWare的同学都知道有vmware-tools这个工具,这个安装在vm内部的工具,可以实现宿主机与虚拟机的通讯,大大增强了虚拟机的性能与功能, 如vmware现在的Unity mode下可 ...

  7. QEMU KVM libvirt手册(2): monitor

    Administrating Virtual Machines with QEMU Monitor When QEMU is running, a monitor console is provide ...

  8. 关于qemu的二三事(1)————qemu的特殊参数之monitor

    qemu作为一个十分重要的虚拟化工具,提供了丰富的功能/参数来支持虚拟化的各种操作. 下面仅就monitor这个参数或者说是功能来结合自己的实际体验来做个简要介绍. 如何进入qemu的monitor模 ...

  9. KVM 介绍(5):libvirt 介绍 [ Libvrit for KVM/QEMU ]

    学习 KVM 的系列文章: (1)介绍和安装 (2)CPU 和 内存虚拟化 (3)I/O QEMU 全虚拟化和准虚拟化(Para-virtulizaiton) (4)I/O PCI/PCIe设备直接分 ...

随机推荐

  1. dll和ocx比较

    ActiveX,OLE是基于COM的一种应用,其文件后缀一般以dll和ocx结尾:ocx作为一种特殊的dll文件,具有一定的用户界面和事件响应,而dll文件只是方法和属性的集合. 一.关于DLL的介绍 ...

  2. Octopus系列之更新历史记录

    更新笔记历史 2015.2.3 更新了产品价格的计算方法     --采用了通用化的一个处理[支持各个国家货币]更新产品价格,增加两组价格:一组用来进行前台的展示:一组用来进行后台的计算更新了产品分类 ...

  3. Oozie简介

    在Hadoop中执行的任务有时候需要把多个Map/Reduce作业连接到一起,这样才能够达到目的.[1]在Hadoop生态圈中,有一种相对比较新的组件叫做Oozie[2],它让我们可以把多个Map/R ...

  4. centos 运用ssh的rsa算法实现无密码登录

    ssh 公钥和私钥原理 1.客户端机子生成私钥和公钥,将公钥放到服务器证书中,然后就可以实现免密码登录.(服务器认证文件要有该登录用户的读执行权限) 2.a登录b: a机子:test01账号(b也要建 ...

  5. Ubuntu里面的安装命令总结

    本人是新手中的新手,才开始用ubuntu.下面,总结一下安装软件的方法...... 0. 利用apt-get 其实,在ubuntu下安装软件的方法其实灰常简单.就是在终端里面输入: sudo apt- ...

  6. javascript——拖拽(完整兼容代码)

    拖拽,是JS经常会用到的效果,在网上有很多的这样那样的拖拽效果,但其中往往大多有各种各养的问题,功能不全,无法兼容,而且修改的时候 也是十分麻烦. 其实拖拽的原理很简单,无非是鼠标的三个动作的解析,以 ...

  7. C# Lodop实现打印

    项目的Debug文件夹下有个template文件夹,里面有用到的js.自己建的要打印的网页和用到的背景图 1.打印方法: class print { public void printzb(strin ...

  8. C#Winform从页面获取数据,传入数据库

    环境: 1.SQLite数据库新建数据表,设置相应的字段.(其他数据库形式都相似,using相应数据库的包即可) 2.页面有两个textBox:textBox1.textBox2, 3.一个保存按钮: ...

  9. jquery表单提交和重置

    $('#myform').submit() 表单提交 $('#myform')[0].reset() 表单重置

  10. async = require('async')

    var mongoose = require('mongoose'), async = require('async'); mongoose.connect('localhost', 'learn-m ...