Retrieving all values from each VM on cluster via pvesh

Sudodude

New Member
May 24, 2022
12
1
3
Hello,

I am occasionally interested in retrieving some values from each VM on my cluster. For example, I would like to check and see if the protection status of each VM is enabled or disabled.

I have been dabbling with pvesh and have learned how to pull the vmid of each VM by using pvesh get /cluster/resources --type vm but I'm not sure what to do with it after that. To find out the value of protection on each VM, it appears that the only way is to check it with pvesh get /nodes/<nodename>/qemu/config . Do I have to run a for loop on each of my nodes to get the value or is there a better way?

This is just a current example. I might want to check if a snapshot exists, or if ballooning is enabled, or which VLAN tag is being used. What is the best way to pull all the values of each VM on the cluster so I can parse for what I'm looking for?

Thank you!
 
It really depends on how you want/comfortable data. The most versatile way is by working on json.
"man pvesh":
Code:
       --output-format <json | json-pretty | text | yaml> (default = text)
           Output format.

a very basic example:
Code:
pvesh get /cluster/resources --output-format json|jq '.[].id'
"node/pve7test2"
"node/pve7test1"
"storage/pve7test1/local-lvm"

Code:
pvesh get /cluster/resources --output-format json|jq '.[]|select(.type == "storage" )'
{
  "content": "backup",
  "disk": 1335492608,
  "id": "storage/pve7test2/pbstore",
  "maxdisk": 33501757440,
  "node": "pve7test2",
  "plugintype": "pbs",
  "shared": 1,
  "status": "available",
  "storage": "pbstore",
  "type": "storage"
}
{


Blockbridge : Ultra low latency all-NVME shared storage for Proxmox - https://www.blockbridge.com/proxmox
 
Thanks for your reply and for some good jq examples. I have been using jq and and am continuing to get a handle on retrieving the values that I want from the output.

In your opinion, what would be the best way to check the protection status of each VM on the cluster? It seems that the only way to retrieve this value is pvesh get /nodes/<nodename>/qemu/config . Will I have to loop through all the nodes, get the vmid from each VM on the node and then check it that way, or is there a better method?

I guess what I'm wondering is how to pull EVERY value from EVERY vm on the cluster. With this I can direct the output to a file where I can jq until my heart's content :).
 
I agree, @bbgeek17 that this is the ideal way. However, I am not seeing a way to query the cluster/resources and get the protection info of the VMs. I believe that this can only be done by querying via the nodes (e.g. pvesh get nodes/<nodename>/qemu/config . There are only a handful of values available when querying the cluster. I wish that in querying the cluster I could receive a FULL output of all the values of the VM.
 
doesnt this work for your original goal?
Code:
root@proxmox7-nvme1:~#  pvesh get /cluster/resources --output-format json |jq '.[]|select(.type=="qemu")'
{
  "cpu": 0,
  "disk": 0,
  "diskread": 0,
  "diskwrite": 0,
  "hastate": "ignored",
  "id": "qemu/1000",
  "maxcpu": 1,
  "maxdisk": 0,
  "maxmem": 2147483648,
  "mem": 0,
  "name": "VM 1000",
  "netin": 0,
  "netout": 0,
  "node": "proxmox7-nvme1",
  "status": "stopped",
  "template": 0,
  "type": "qemu",
  "uptime": 0,
  "vmid": 1000
}
{
  "cpu": 0,
  "disk": 0,
  "diskread": 0,
  "diskwrite": 0,
  "id": "qemu/1001",
  "maxcpu": 1,
  "maxdisk": 0,
  "maxmem": 2147483648,
  "mem": 0,
  "name": "VM 1001",
  "netin": 0,
  "netout": 0,
  "node": "proxmox7-nvme1",
  "status": "stopped",
  "template": 0,
  "type": "qemu",
  "uptime": 0,
  "vmid": 1001
}
root@proxmox7-nvme1:~#  pvesh get /cluster/resources --output-format json |jq '.[]|select(.type=="qemu")|select(.hastate != null)'
{
  "cpu": 0,
  "disk": 0,
  "diskread": 0,
  "diskwrite": 0,
  "hastate": "ignored",
  "id": "qemu/1000",
  "maxcpu": 1,
  "maxdisk": 0,
  "maxmem": 2147483648,
  "mem": 0,
  "name": "VM 1000",
  "netin": 0,
  "netout": 0,
  "node": "proxmox7-nvme1",
  "status": "stopped",
  "template": 0,
  "type": "qemu",
  "uptime": 0,
  "vmid": 1000
}

Besides that - very rarely there exists an API that returns everything and kitchen sink. In most cases you need to chain a few requests, which is completely normal.


Blockbridge : Ultra low latency all-NVME shared storage for Proxmox - https://www.blockbridge.com/proxmox
 
This is great, thank you for the sample commands and parsing of the jq data. I am learning jq and how to retrieve the desired values from the output, so this is quite helpful!

Again, I do wish that there were more values that can be found in pvesh get cluster/resources . Can this be a feature request perhaps? The protection value is one example where I wish I could query the cluster to find out which VMs have protection enabled or not. Another example is onboot. In my opinion it makes sense to have more available data when querying the cluster instead of each node directly. It would certainly make it easier when checking a value on each VM.

Thanks for your help!
 

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!