CLI command 'qm status' and 'qm list' reports an incorrect status if VM paused

Gordon Kaltofen

New Member
Jul 28, 2014
8
0
1
Berlin
www.dresearch-fe.de
In my opinion, the CLI command 'qm' has a bug. It reports incorrect VM status 'running' if VM paused.

1) I am logged in as root.

2) Suspends the VM 114
~# qm suspend 114

Proxmox VE Web-GUI reports the correct status 'paused'

3) Query the current status at CLI
~# qm status 114
or
~# qm list
reports the incorrect status 'running'.

but @monitor is it correct:
~# qm monitor 114
Entering Qemu Monitor for VM 114 - type 'help' for help
qm> info status
VM status: paused
qm> quit

The same effect I had when the power mode of the host system changed this in the sleep mode.






I want to script the VM status query via CLI. That should be fixed.




Or is there another explanation?

Greetings,
Gordon
 
qm> info status
VM status: paused
qm> quit

The 'qm' command only return if the KVM process is running.
You need to use the API if you want the monitor status (that also solves your permission problems).

(GET nodes/<nodename>/qemu/<vmid>, attribute qmpstatus).
 
Last edited:
Bump: curious if anyone got this to work? I'm also trying to do something of the sort. I'm trying to script this: use qm monitor to use screen dump to capture the console to a PNG.

I've tried:

qm monitor 100 << screendump /root/100p.png
qm monitor 100 >> screendump /root/100p.png
qm monitor 100 | screendump /root/100p.png

And variations with scripting:

#!/bin/bash
qm monitor 100 <<MONITOR
echo "screendump /root/100t.png"
MONITOR

BUT, nothing working. Is there another way to simply grab the console image via SSH? I know qm monitor drops to a monitor shell, but how can I pass commands to it?

Thanks!
 
This is how you can determine if the VM is stopped or suspended:

Suspended:
Code:
root@pve:~# qm status 107 --verbose
    ...
    lock: suspended       <-------
    ...
    qmpstatus: stopped
    status: stopped
    ...

Stopped:
Code:
root@pve:~# qm status 101 --verbose
    ...
    qmpstatus: stopped
    ...
    status: stopped
    ...

Alternatively, you can also see lock status with this command:
Code:
pvesh get /cluster/resources --type vm --output-format json-pretty

I'm adding a one-liner that will provide formatted output similar to 'qm list':
Bash:
pvesh get /cluster/resources --type vm --output-format json-pretty | jq -r '.[] | "\(.vmid),\(.name),\(.status),\(.lock // "")"' | tr ',' ' ' |  awk '{printf "%-15s %-30s %-15s %s\n", $1, $2, $3, ($4 == "unlocked") ? "" : $4}'

Example output:
Code:
100             ubuntu-22.04-ktx-1             stopped         suspended
101             win11                          stopped         
102             ubuntu-22.04-desktop           stopped         
103             win10-template                 stopped         
104             mint-21.3-desktop              stopped         
105             win10-cloned                   stopped         
106             ubuntu-22.04-ktx-2             running         
107             mikrotik-routeros-chr          stopped         suspended
108             openwrt                        stopped
 
Last edited:
  • Like
Reactions: UdoB

About

The Proxmox community has been around for many years and offers help and support for Proxmox VE, Proxmox Backup Server, and Proxmox Mail Gateway.
We think our community is one of the best thanks to people like you!

Get your subscription!

The Proxmox team works very hard to make sure you are running the best software and getting stable updates and security enhancements, as well as quick enterprise support. Tens of thousands of happy customers have a Proxmox subscription. Get yours easily in our online shop.

Buy now!