[libvirt] Libvirt's DomainGetInfo Function Development

Andrea Bolognani abologna at redhat.com
Fri Aug 5 13:36:20 UTC 2016


On Fri, 2016-08-05 at 17:45 +0500, Aleem Akhtar wrote:
> Ok. So that's why I was getting 1 GB as a result.
> So is there any way I can get memory in used
programmatically? 
> I mean without going inside guest domain.

The only way I can come up with at the moment relies on
qemu-guest-agent:

  $ virsh qemu-agent-command guest \
          '{"execute": "guest-exec",
            "arguments": {"path": "/usr/bin/free",
                          "capture-output": true}}'
  {"return":{"pid":1425}}

  $ virsh qemu-agent-command guest \
          '{"execute": "guest-exec-status",
            "arguments": {"pid": 1425}}'
  {"return":{"exitcode":0,"out-data":"ICA...zIK","exited":true}}

  $ echo 'ICA...zIK' | base64 -d
                total        used        free
  Mem:        4020408       97244     3359560
  Swap:       1048572           0     1048572

Of course you'll need to have qemu-guest-agent running
inside the guest and process all the resulting information
yourself.

See the virDomainQemuAgentCommand() API.

-- 
Andrea Bolognani / Red Hat / Virtualization




More information about the libvir-list mailing list