* [Qemu-devel] Getting VM state from outside QEMU?
@ 2015-04-07 13:31 Erik Rull
2015-04-07 13:42 ` Paulo Ricardo Paz Vital
2015-04-07 18:16 ` John Snow
0 siblings, 2 replies; 8+ messages in thread
From: Erik Rull @ 2015-04-07 13:31 UTC (permalink / raw)
To: qemu-devel@nongnu.org
Hi all,
I need a pretty simple way to get the current state of the VM running in QEMU -
I only need the VM state (e.g. running, paused,...). Since my environment does
not have any perl, python or other high level scripting capabilities, a simple
way e.g. via a shell script would be nice. QEMU is running daemonized, so
interacting with the qemu console is not possible.
Are there any usable entries in /proc, /dev or /sys that could be used?
Thanks.
Best regards,
Erik
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [Qemu-devel] Getting VM state from outside QEMU?
2015-04-07 13:31 [Qemu-devel] Getting VM state from outside QEMU? Erik Rull
@ 2015-04-07 13:42 ` Paulo Ricardo Paz Vital
2015-04-08 16:10 ` Erik Rull
2015-04-07 18:16 ` John Snow
1 sibling, 1 reply; 8+ messages in thread
From: Paulo Ricardo Paz Vital @ 2015-04-07 13:42 UTC (permalink / raw)
To: Erik Rull; +Cc: qemu-devel@nongnu.org
On Tue, 2015-04-07 at 15:31 +0200, Erik Rull wrote:
> Hi all,
>
> I need a pretty simple way to get the current state of the VM running in QEMU -
> I only need the VM state (e.g. running, paused,...). Since my environment does
> not have any perl, python or other high level scripting capabilities, a simple
> way e.g. via a shell script would be nice. QEMU is running daemonized, so
> interacting with the qemu console is not possible.
> Are there any usable entries in /proc, /dev or /sys that could be used?
>
Hello Erik,
My suggestion is to create a script that sends the QMP command
"query-status" an then parse the result. The syntax and output is:
-> { "execute": "query-status" }
<- { "return": { "running": true, "singlestep": false, "status":
"running" } }
> Thanks.
>
> Best regards,
>
> Erik
>
--
Paulo Ricardo Paz Vital <paulo.vital@profitbricks.com>
ProfitBricks GmbH
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [Qemu-devel] Getting VM state from outside QEMU?
2015-04-07 13:31 [Qemu-devel] Getting VM state from outside QEMU? Erik Rull
2015-04-07 13:42 ` Paulo Ricardo Paz Vital
@ 2015-04-07 18:16 ` John Snow
1 sibling, 0 replies; 8+ messages in thread
From: John Snow @ 2015-04-07 18:16 UTC (permalink / raw)
To: Erik Rull, qemu-devel@nongnu.org
On 04/07/2015 09:31 AM, Erik Rull wrote:
> Hi all,
>
> I need a pretty simple way to get the current state of the VM running in QEMU -
> I only need the VM state (e.g. running, paused,...). Since my environment does
> not have any perl, python or other high level scripting capabilities, a simple
> way e.g. via a shell script would be nice. QEMU is running daemonized, so
> interacting with the qemu console is not possible.
> Are there any usable entries in /proc, /dev or /sys that could be used?
>
> Thanks.
>
> Best regards,
>
> Erik
>
Assuming this is some sort of embedded system under which python is not
an option:
You'll need to use the monitor interface (-monitor), and set it to a
pipe. you can echo commands into the pipe ("info status") and read lines
out of it.
try:
mkfifo monitor.out
mkfifo monitor.in
./qemu-system-blah -monitor pipe:monitor &
echo "info status" > monitor.in
read $line < monitor.out # 'info status'
read $line < monitor.out # 'VM status: running'
And now you've got e.g. "VM status: running" in $line. Use whichever
shell tricks to distill this down as needed.
Warning: this is using the human monitor protocol, which as the name
implies, is not meant for you to be scraping it with tools. It could
change arbitrarily in the future and shouldn't be used in production.
Really recommend the QMP interface and something capable of
sending/reading JSON for programmatic scripting of QEMU. Check out
scripts/qmp.py for a nice library for sending/receiving these sorts of
things.
Alternatively you can use a similar fifo trick for -qmp and try to parse
the answers you get with sed/awk/bash regex etc.
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [Qemu-devel] Getting VM state from outside QEMU?
2015-04-07 13:42 ` Paulo Ricardo Paz Vital
@ 2015-04-08 16:10 ` Erik Rull
2015-04-08 16:16 ` Eric Blake
0 siblings, 1 reply; 8+ messages in thread
From: Erik Rull @ 2015-04-08 16:10 UTC (permalink / raw)
To: paulo.vital; +Cc: qemu-devel@nongnu.org
Hello Paulo,
> On April 7, 2015 at 3:42 PM Paulo Ricardo Paz Vital
> <paulo.vital@profitbricks.com> wrote:
>
>
> On Tue, 2015-04-07 at 15:31 +0200, Erik Rull wrote:
> > Hi all,
> >
> > I need a pretty simple way to get the current state of the VM running in
> > QEMU -
> > I only need the VM state (e.g. running, paused,...). Since my environment
> > does
> > not have any perl, python or other high level scripting capabilities, a
> > simple
> > way e.g. via a shell script would be nice. QEMU is running daemonized, so
> > interacting with the qemu console is not possible.
> > Are there any usable entries in /proc, /dev or /sys that could be used?
> >
>
> Hello Erik,
>
> My suggestion is to create a script that sends the QMP command
> "query-status" an then parse the result. The syntax and output is:
>
> -> { "execute": "query-status" }
> <- { "return": { "running": true, "singlestep": false, "status":
> "running" } }
>
Sounds good - I tried that - but all attempts return that the command has not
been found. I added the following command line snippet and the results are:
[...] -qmp tcp:localhost:4444,server,nowait [...]
172.17.48.45 ~ # telnet 127.0.0.1 4444
{"QMP": {"version": {"qemu": {"micro": 0, "minor": 1, "major": 2}, "package":
""}, "capabilities": []}}
{ "execute": "query-status" }
{"error": {"class": "CommandNotFound", "desc": "The command query-status has not
been found"}}
{ "execute": "info status" }
{"error": {"class": "CommandNotFound", "desc": "The command info status has not
been found"}}
{ "execute": "info", "arguments": { "status": "" } }
{"error": {"class": "CommandNotFound", "desc": "The command info has not been
found"}}
{ "execute": "query-kvm" }
{"error": {"class": "CommandNotFound", "desc": "The command query-kvm has not
been found"}}
Any ideas what's wrong here?
Thanks.
Best regards,
Erik
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [Qemu-devel] Getting VM state from outside QEMU?
2015-04-08 16:10 ` Erik Rull
@ 2015-04-08 16:16 ` Eric Blake
2015-04-08 16:21 ` Erik Rull
2015-04-09 7:33 ` Paulo Ricardo Paz Vital
0 siblings, 2 replies; 8+ messages in thread
From: Eric Blake @ 2015-04-08 16:16 UTC (permalink / raw)
To: Erik Rull, paulo.vital; +Cc: qemu-devel@nongnu.org
On 04/08/2015 10:10 AM, Erik Rull wrote:
>>
>> My suggestion is to create a script that sends the QMP command
>> "query-status" an then parse the result. The syntax and output is:
>>
>> -> { "execute": "query-status" }
>> <- { "return": { "running": true, "singlestep": false, "status":
>> "running" } }
>>
>
> Sounds good - I tried that - but all attempts return that the command has not
> been found. I added the following command line snippet and the results are:
> [...] -qmp tcp:localhost:4444,server,nowait [...]
>
> 172.17.48.45 ~ # telnet 127.0.0.1 4444
> {"QMP": {"version": {"qemu": {"micro": 0, "minor": 1, "major": 2}, "package":
> ""}, "capabilities": []}}
You HAVE to use {"execute":"qmp_capabilities"} (possibly with an
"id":...) as your first command on the monitor, before you can issue any
other command. I really wish we could improve the error message:
>
> { "execute": "query-status" }
> {"error": {"class": "CommandNotFound", "desc": "The command query-status has not
> been found"}}
it would be a LOT nicer if we reported 'still in negotiation phase;
"qmp_capabilities" expected' than a bland "CommandNotFound". Of course,
patches are welcome to improve the experience there!
Similarly, once you are NOT in capabilities negotiation, any subsequent
use of "qmp_capabilities" fails. That's also something where the error
message could be improved.
--
Eric Blake eblake redhat com +1-919-301-3266
Libvirt virtualization library http://libvirt.org
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [Qemu-devel] Getting VM state from outside QEMU?
2015-04-08 16:16 ` Eric Blake
@ 2015-04-08 16:21 ` Erik Rull
2015-04-08 16:34 ` Eric Blake
2015-04-09 7:33 ` Paulo Ricardo Paz Vital
1 sibling, 1 reply; 8+ messages in thread
From: Erik Rull @ 2015-04-08 16:21 UTC (permalink / raw)
To: paulo.vital, Eric Blake; +Cc: qemu-devel@nongnu.org
Hi Eric,
> On April 8, 2015 at 6:16 PM Eric Blake <eblake@redhat.com> wrote:
>
>
> On 04/08/2015 10:10 AM, Erik Rull wrote:
> >>
> >> My suggestion is to create a script that sends the QMP command
> >> "query-status" an then parse the result. The syntax and output is:
> >>
> >> -> { "execute": "query-status" }
> >> <- { "return": { "running": true, "singlestep": false, "status":
> >> "running" } }
> >>
> >
> > Sounds good - I tried that - but all attempts return that the command has
> > not
> > been found. I added the following command line snippet and the results are:
> > [...] -qmp tcp:localhost:4444,server,nowait [...]
> >
> > 172.17.48.45 ~ # telnet 127.0.0.1 4444
> > {"QMP": {"version": {"qemu": {"micro": 0, "minor": 1, "major": 2},
> > "package":
> > ""}, "capabilities": []}}
>
> You HAVE to use {"execute":"qmp_capabilities"} (possibly with an
> "id":...) as your first command on the monitor, before you can issue any
> other command. I really wish we could improve the error message:
>
> >
> > { "execute": "query-status" }
> > {"error": {"class": "CommandNotFound", "desc": "The command query-status has
> > not
> > been found"}}
>
> it would be a LOT nicer if we reported 'still in negotiation phase;
> "qmp_capabilities" expected' than a bland "CommandNotFound". Of course,
> patches are welcome to improve the experience there!
>
> Similarly, once you are NOT in capabilities negotiation, any subsequent
> use of "qmp_capabilities" fails. That's also something where the error
> message could be improved.
>
> --
> Eric Blake eblake redhat com +1-919-301-3266
> Libvirt virtualization library http://libvirt.org
Thanks! That fixed it - even if I don't know why this was actually necessary :-)
{"execute":"qmp_capabilities"}
{"return": {}}
{ "execute": "query-status" }
{"return": {"status": "running", "singlestep": false, "running": true}}
Best regards,
Erik
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [Qemu-devel] Getting VM state from outside QEMU?
2015-04-08 16:21 ` Erik Rull
@ 2015-04-08 16:34 ` Eric Blake
0 siblings, 0 replies; 8+ messages in thread
From: Eric Blake @ 2015-04-08 16:34 UTC (permalink / raw)
To: Erik Rull, paulo.vital; +Cc: qemu-devel@nongnu.org
[-- Attachment #1: Type: text/plain, Size: 896 bytes --]
On 04/08/2015 10:21 AM, Erik Rull wrote:
>>> 172.17.48.45 ~ # telnet 127.0.0.1 4444
>>> {"QMP": {"version": {"qemu": {"micro": 0, "minor": 1, "major": 2},
>>> "package":
>>> ""}, "capabilities": []}}
>>
>> You HAVE to use {"execute":"qmp_capabilities"} (possibly with an
>> "id":...) as your first command on the monitor, before you can issue any
>> other command. I really wish we could improve the error message:
> Thanks! That fixed it - even if I don't know why this was actually necessary :-)
docs/qmp/qmp-spec.txt
It's part of the protocol, to allow us to make non-backwards-compatible
changes to how QMP is parsed while still keeping sane interactions
between mismatches in server vs. client (to date, we have wisely not
needed to add any capabilities).
--
Eric Blake eblake redhat com +1-919-301-3266
Libvirt virtualization library http://libvirt.org
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 604 bytes --]
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [Qemu-devel] Getting VM state from outside QEMU?
2015-04-08 16:16 ` Eric Blake
2015-04-08 16:21 ` Erik Rull
@ 2015-04-09 7:33 ` Paulo Ricardo Paz Vital
1 sibling, 0 replies; 8+ messages in thread
From: Paulo Ricardo Paz Vital @ 2015-04-09 7:33 UTC (permalink / raw)
To: Eric Blake; +Cc: Erik Rull, qemu-devel@nongnu.org
Sorry guys only checked the emails this morning :-D
On Wed, 2015-04-08 at 10:16 -0600, Eric Blake wrote:
> On 04/08/2015 10:10 AM, Erik Rull wrote:
> >>
> >> My suggestion is to create a script that sends the QMP command
> >> "query-status" an then parse the result. The syntax and output is:
> >>
> >> -> { "execute": "query-status" }
> >> <- { "return": { "running": true, "singlestep": false, "status":
> >> "running" } }
> >>
> >
> > Sounds good - I tried that - but all attempts return that the command has not
> > been found. I added the following command line snippet and the results are:
> > [...] -qmp tcp:localhost:4444,server,nowait [...]
> >
> > 172.17.48.45 ~ # telnet 127.0.0.1 4444
> > {"QMP": {"version": {"qemu": {"micro": 0, "minor": 1, "major": 2}, "package":
> > ""}, "capabilities": []}}
>
> You HAVE to use {"execute":"qmp_capabilities"} (possibly with an
> "id":...) as your first command on the monitor, before you can issue any
> other command. I really wish we could improve the error message:
>
> >
> > { "execute": "query-status" }
> > {"error": {"class": "CommandNotFound", "desc": "The command query-status has not
> > been found"}}
>
> it would be a LOT nicer if we reported 'still in negotiation phase;
> "qmp_capabilities" expected' than a bland "CommandNotFound". Of course,
> patches are welcome to improve the experience there!
That's an interesting point to see. I'm going to take a look on this and
submit a patch until next week, probably good to 2.4 release.
>
> Similarly, once you are NOT in capabilities negotiation, any subsequent
> use of "qmp_capabilities" fails. That's also something where the error
> message could be improved.
>
--
Paulo Ricardo Paz Vital <paulo.vital@profitbricks.com>
ProfitBricks GmbH
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2015-04-09 7:33 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-04-07 13:31 [Qemu-devel] Getting VM state from outside QEMU? Erik Rull
2015-04-07 13:42 ` Paulo Ricardo Paz Vital
2015-04-08 16:10 ` Erik Rull
2015-04-08 16:16 ` Eric Blake
2015-04-08 16:21 ` Erik Rull
2015-04-08 16:34 ` Eric Blake
2015-04-09 7:33 ` Paulo Ricardo Paz Vital
2015-04-07 18:16 ` John Snow
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).