Re: [libvirt] How to get VM memory usage

[moderator note: I'm forwarding a stripped down version of the original mail which was rejected in the moderator queue. I stripped the .jpg attachments, which are inappropriate for a technical list. Either paste the text contents (rather than a screenshot) of the window you are describing, or host your images elsewhere and have your list email merely give a URL of the externally-hosted images]
ForwardedMessage.eml
Subject: Re: Re: [libvirt] How to get VM memory usage From: "wangyufeng@cloudguarding.com" <wangyufeng@cloudguarding.com> Date: 04/26/2017 01:21 AM
To: "Daniel P. Berrange" <berrange@redhat.com> CC: libvir-list <libvir-list@redhat.com>
Hi Daniel,
I found method MemoryStats in domain.go: func (d *Domain) MemoryStats(nrStats uint32, flags uint32) ([]DomainMemoryStat, error) { ptr := make([]C.virDomainMemoryStatStruct, nrStats)
result := C.virDomainMemoryStats( d.ptr, (C.virDomainMemoryStatPtr)(unsafe.Pointer(&ptr[0])), C.uint(nrStats), C.uint(flags))
if result == -1 { return []DomainMemoryStat{}, GetLastError() }
out := make([]DomainMemoryStat, result) for i := 0; i < int(result); i++ { out = append(out, DomainMemoryStat{ Tag: int32(ptr[i].tag), Val: uint64(ptr[i].val), }) } return out, nil }
Do you mean this method can get used memory info? While I invoke the method, which can only get values of tag 0 and tag 6:
And the balloon driver have been activated on the monitored vm:
Below is my code, could you tell me what's wrong with my code?
Thank you very much.
---------------------------------------------------------------------------------------------------------- On Fri, Apr 21, 2017 at 09:58:12AM +0800, wangyufeng@cloudguarding.com wrote:
Hi Daniel,
In method 'GetInfo', we can only get memory and max memory. However I need to get used memory for calculating memory usage. The virsh command 'dommemstat' can obtain used memory, is there a method in libvirt-go to obtain used memory?
That command uses the virDomainMemoryStats() API call
Regards, Daniel -- |: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
-- Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3266 Virtualization: qemu.org | libvirt.org
participants (1)
-
Eric Blake