QMP ( qemu monitor protocol ) and Different ways of accessing it

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:

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”

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:

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:

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

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

Inside “QMP” directory you have the mentioned programm:

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

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

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

Hope this was helpful!!!

Leave a Reply

Your email address will not be published. Required fields are marked *