Best way to get total number of running/stopped VMs for dashboard?

victorhooi

Well-Known Member
Apr 3, 2018
250
20
58
38
I'm trying to create a realtime dashboard of the number of running/stopped VMs on a Proxmox cluster.

What is the easiest way of doing this?

qm list seems to be one option:

Code:
root@foo-vm01:~# qm list --full true
      VMID NAME                 STATUS     MEM(MB)    BOOTDISK(GB) PID
       100 aruba-mobility-master-8.5-september-2019 stopped    8192               4.00 0
       101 accessing-aruba      stopped    4000              30.00 0
       102 aruba-mobility-master-8.6-january-2020 stopped    12000              6.00 0
       500 win7-base            running    4000              30.00 237352
       502 win8.1-base          running    4000               0.00 237418
       503 win10-base           running    4000               0.00 242001
       504 win10-fasttrack-base running    4000               0.00 237194
       700 win7-with-software   stopped    4000              30.00 0
       701 win8.1-with-software stopped    4000               0.00 0

Or I can use the REST api:
Code:
root@foo-vm01:~# pvesh get /nodes/angussyd-vm01/qemu
┌─────────┬──────┬──────┬──────┬───────────┬───────────┬──────────────────────────────────────────┬────────┬───────────┬──────┬────────────┐
│ status  │ vmid │ cpus │ lock │   maxdisk │    maxmem │ name                                     │    pid │ qmpstatus │ tags │     uptime │
╞═════════╪══════╪══════╪══════╪═══════════╪═══════════╪══════════════════════════════════════════╪════════╪═══════════╪══════╪════════════╡
│ running │  503 │    2 │      │    0.00 B │  3.91 GiB │ win10-base                               │ 242001 │           │      │  6h 23m 7s │
├─────────┼──────┼──────┼──────┼───────────┼───────────┼──────────────────────────────────────────┼────────┼───────────┼──────┼────────────┤
│ running │  502 │    2 │      │    0.00 B │  3.91 GiB │ win8.1-base                              │ 237418 │           │      │ 6h 23m 11s │
├─────────┼──────┼──────┼──────┼───────────┼───────────┼──────────────────────────────────────────┼────────┼───────────┼──────┼────────────┤
│ running │  500 │    2 │      │ 30.00 GiB │  3.91 GiB │ win7-base                                │ 237352 │           │      │ 6h 23m 13s │
├─────────┼──────┼──────┼──────┼───────────┼───────────┼──────────────────────────────────────────┼────────┼───────────┼──────┼────────────┤
│ running │  504 │    2 │      │    0.00 B │  3.91 GiB │ win10-fasttrack-base                     │ 237194 │           │      │ 6h 23m 18s │
├─────────┼──────┼──────┼──────┼───────────┼───────────┼──────────────────────────────────────────┼────────┼───────────┼──────┼────────────┤
│ stopped │  101 │    2 │      │ 30.00 GiB │  3.91 GiB │ accessing-aruba                          │        │           │      │            │
├─────────┼──────┼──────┼──────┼───────────┼───────────┼──────────────────────────────────────────┼────────┼───────────┼──────┼────────────┤
│ stopped │  700 │    2 │      │ 30.00 GiB │  3.91 GiB │ win7-with-software                       │        │           │      │            │
├─────────┼──────┼──────┼──────┼───────────┼───────────┼──────────────────────────────────────────┼────────┼───────────┼──────┼────────────┤
│ stopped │  102 │    3 │      │  6.00 GiB │ 11.72 GiB │ aruba-mobility-master-8.6-january-2020   │        │           │      │            │
├─────────┼──────┼──────┼──────┼───────────┼───────────┼──────────────────────────────────────────┼────────┼───────────┼──────┼────────────┤
│ stopped │  701 │    2 │      │    0.00 B │  3.91 GiB │ win8.1-with-software                     │        │           │      │            │
├─────────┼──────┼──────┼──────┼───────────┼───────────┼──────────────────────────────────────────┼────────┼───────────┼──────┼────────────┤
│ stopped │  100 │    6 │      │  4.00 GiB │  8.00 GiB │ aruba-mobility-master-8.5-september-2019 │        │           │      │            │
└─────────┴──────┴──────┴──────┴───────────┴───────────┴──────────────────────────────────────────┴────────┴───────────┴──────┴────────────┘

Firstly - is there an alternative way to get this data? (Just wondering if easier way - or if the above approaches I found are the best).

Second, is there a way, using the API, to target *all* nodes in the cluster, or do you have to specify them all, individually?

Thirdly, And is there any way to get the username who started the VM as well, somehow?

Thanks,
Victor
 
qm often simply calls the API (see code). The whole API is documented. This API viewer is automatically generated from the code, so if something is not there it does not exist (yet). If you're missing something, you can open a feature request in our Bugzilla :)


1) If you plan to process the output of the API, you might want to take a look at curl and jq. There is a wiki article about this.
2) Depends on the command. For certain ones you have to specify a node. Writing a small shell script with a loop might help.
3) You can see this information in the task log at the bottom of the GUI. If you double click it and go to Status you will find the Unique task ID You can grep for (parts of) it in /var/log.
 

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!