Using qemu agent to run code inside VM?

Dunuin

Distinguished Member
Jun 30, 2020
14,181
4,143
243
Germany
Hi,

I want to monitor a VMs RAM usage from the host so I can dynamically adjust the "minimum RAM" by script so ballooning won't remove more RAM than the guest got free or available and caching isn't wasting that much RAM. My idea was to run free -b inside the guest and monitor total RAM and available RAM because the "qm monitor" command is only reporting "free" and "used" RAM but not "avaialbe" or "cache/buffer" (so you can't see how much is used for caching).
Is there a way to do that using the qemu guest agent? I've seen its possible to read/write from/to files inside the guest using the agent. Or do I need to use SSH for that?
Would be a bit annoying to add a monitor user with RSA key for that to each of the VMs.
 
Thanks! :)

Needed to change the "-b" but now it works:
Code:
root@Hypervisor:/# qm guest exec 107 -- "/bin/bash" "-c" "/usr/bin/free -b"
{
   "exitcode" : 0,
   "exited" : 1,
   "out-data" : "               total        used        free      shared  buff/cache   available\nMem:      1550704640   875958272    79859712    24952832   594886656   500973568\nSwap:     2145382400      262144  2145120256\n"
}
 
Hello,

just for curiosity and possibly for saving innocent resources: has the invocation of an initial bash plus forking "free" any advantages?

Without bash I can get the exact same result :)
Code:
root@pved:/etc/pve# qm guest exec 1901 -- "/bin/bash" "-c" "/usr/bin/free -b"
{
   "exitcode" : 0,
   "exited" : 1,
   "out-data" : "              total        used        free      shared  buff/cache   available\nMem:     2091909120   861155328   182390784    27033600  1048363008  1013248000\nSwap:    1070592000   107479040   963112960\n"
}
root@pved:/etc/pve# qm guest exec 1901 -- "/usr/bin/free" "-b"
{
   "exitcode" : 0,
   "exited" : 1,
   "out-data" : "              total        used        free      shared  buff/cache   available\nMem:     2091909120   860831744   182714368    27033600  1048363008  1013579776\nSwap:    1070592000   107479040   963112960\n"
}

Best regards
 
AFAIU this should not make much of a difference in this use case. Depending on what you want to run, it can help to do it in the context of a shell. For example, if you need any of the shell features, like globbing.
 

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!