Re: how to get vm uptime through libvirt api

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]


Thank you very much for reply. Initially my thought of uptime is equal to executing to `uptime` inside a virtual machine. 
as for the second case, where virtual machine is paused for a period, does libvirt expose an api to get how long qemu process
has existed?

thank you.


On Tue, Jul 26, 2022 at 3:16 PM Michal Prívozník <mprivozn@xxxxxxxxxx> wrote:
On 7/26/22 08:49, Jiatong Shen wrote:
> Hello community,
>    I would like to know if there is an api to get a virtual machine's
> uptime. Thank you in advance for the help.

There's no such API because not even qemu guest agent has an explicit
API for that. However, it has an API to execute binaries:

# virsh qemu-agent-command --pretty $dom '{"execute":"guest-exec",
"arguments":{"path":"uptime", "capture-output":true}}'
  "return": {
    "pid": 1174

# virsh qemu-agent-command --pretty $dom
'{"execute":"guest-exec-status", "arguments":{"pid":1174}}'
  "return": {
    "exitcode": 0,
    "exited": true

$ echo
| base64 -d
 09:10:58 up 8 min,  1 user,  load average: 0.00, 0.09, 0.08

But it also depends what exactly do you mean by 'uptime'. Because if I
start a guest, then pause it for 5 minutes and then let it run again,
what should 'uptime' refer to?



Best Regards,

Jiatong Shen

[Index of Archives]     [Virt Tools]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Yosemite News]     [KDE Users]

  Powered by Linux