Hello,

I'm trying to use libvirt as a non-root user to obtain statistics on the CPU usage by VMs using the Python API. I'm performing basically the following steps:

import libvirt
conn = libvirt.openReadOnly(None)
dom = conn.lookupByUUIDString('268e38ea-1bc7-41e4-c19e-8eff682e58e4')
dom.getCPUStats(True, 0)


However, they result in the following error:


libvir: QEMU Driver error : Requested operation is not valid: cgroup CPUACCT controller is not mounted
---------------------------------------------------------------------------
libvirtError                              Traceback (most recent call last)
<ipython-input-23-9317cf967f6d> in <module>()
----> 1 dom.getCPUStats(True, 0)

/usr/lib/python2.7/site-packages/libvirt.pyc in getCPUStats(self, total, flags)
   1733            [{cpu_time:xxx, user_time:xxx, system_time:xxx}] """
   1734         ret = libvirtmod.virDomainGetCPUStats(self._o, total, flags)
-> 1735         if ret is None: raise libvirtError ('virDomainGetCPUStats() failed', dom=self)
   1736         return ret
   1737 

libvirtError: Requested operation is not valid: cgroup CPUACCT controller is not mounted


However, CPUACCT is actually started and mounted to /mnt/cgroups/cpuacct, and the following steps actually work for the root user:


import libvirt
conn = libvirt.open(None)
dom = conn.lookupByUUIDString('e06c6b11-d655-5a98-fd90-724d106066f9')
dom.getCPUStats(True, 0)

Output:

[{'cpu_time': 10245430984L,
  'system_time': 5350000000L,
  'user_time': 1870000000L}]


The domains referenced above are started for the non-root and root users respectively.

I would be very grateful for any pointers to possible solutions of my problem.

Thanks,
Anton Beloglazov