[libvirt-users] How to find memory utilization percent of kvm guest?

suyog jadhav suyogjadhav at yahoo.com
Wed Oct 28 08:43:09 UTC 2015

I currently use following approach but its failing

Find Max memory using following API

        vdgiRet = virDomainGetInfo(domPtr, infoPtr);
        memTotal = infoPtr->memory;

Find current utilization using following API
        rVal = virDomainMemoryStats (domPtr, memStats, VIR_DOMAIN_MEMORY_STAT_NR, 0) ;
        for (i = 0; i < rVal; i++) 
            if (memStats[i].tag == 7)
                memUsed = memStats[i].val;

Which is the value of "VIR_DOMAIN_MEMORY_STAT_RSS    =    7"

Then I calculate util as (memUsed/memTotal)

But the value of memUsed exceeds value of memTotal by small amount resulting in memUtil to be around 101 %.

I understand that VIR_DOMAIN_MEMORY_STAT_RSS is Resident Set Size of the process running the domain.

How do I Calculate the current memory utilization using alternate way?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://listman.redhat.com/archives/libvirt-users/attachments/20151028/c8a512ab/attachment.htm>

More information about the libvirt-users mailing list