Re: how to get vm uptime through libvirt api

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


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?


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

  Powered by Linux