[libvirt-users] getCPUStats of a domain by a non-root user - libvirtError: Requested operation is not valid: cgroup CPUACCT controller is not mounted

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

Hi,
libvir: QEMU Driver error : Requested operation is not valid: cgroup CPUACCT controller is not mounted
You need to install/configure Cgroups on your system : http://en.wikipedia.org/wiki/Cgroups https://access.redhat.com/knowledge/docs/en-US/Red_Hat_Enterprise_Linux/6/ht... Olivier

Hi Olivier, Thanks for the suggestion, but Cgroups is installed and started. As I mentioned, everything works for the root user. Should I do some special configuration for a non-root user? Currently, my /etc/cgconfig.conf contains the following: mount { cpuacct = /mnt/cgroups/cpuacct; } Thanks, Anton On Fri, Aug 17, 2012 at 11:24 PM, Olivier Doucet <webmaster@ajeux.com>wrote:
Hi,
libvir: QEMU Driver error : Requested operation is not valid: cgroup CPUACCT controller is not mounted
You need to install/configure Cgroups on your system : http://en.wikipedia.org/wiki/Cgroups
https://access.redhat.com/knowledge/docs/en-US/Red_Hat_Enterprise_Linux/6/ht...
Olivier

Hi Olivier, Thanks for the links. I see now that there is an option to assign permissions to access control groups for non-root users. I'll try to configure it and post back the results. Best regards, Anton On Fri, Aug 17, 2012 at 11:31 PM, Anton Beloglazov < anton.beloglazov@gmail.com> wrote:
Hi Olivier,
Thanks for the suggestion, but Cgroups is installed and started. As I mentioned, everything works for the root user. Should I do some special configuration for a non-root user? Currently, my /etc/cgconfig.conf contains the following:
mount { cpuacct = /mnt/cgroups/cpuacct; }
Thanks, Anton
On Fri, Aug 17, 2012 at 11:24 PM, Olivier Doucet <webmaster@ajeux.com>wrote:
Hi,
libvir: QEMU Driver error : Requested operation is not valid: cgroup CPUACCT controller is not mounted
You need to install/configure Cgroups on your system : http://en.wikipedia.org/wiki/Cgroups
https://access.redhat.com/knowledge/docs/en-US/Red_Hat_Enterprise_Linux/6/ht...
Olivier

Hi All, Unfortunately, I couldn't manage to solve my problem. I've tried various way to configure Cgroups to enable VM monitoring by a non-root user with no luck. My current /etc/cgconfig.conf is the following: group sysdefault { perm { task { uid = anton; gid = root; } admin { uid = anton; gid = root; } } } mount { cpuacct = /mnt/cgroups/cpuacct; } Where "anton" is a non-root user. However, this doesn't work. Here is a simple test: $ virsh start cirros $ virsh cpu-stats cirros error: Failed to virDomainGetCPUStats() error: Requested operation is not valid: cgroup CPUACCT controller is not mounted Where cirros is a VM image. Everything is fine for the root user: $ sudo virsh start cirros $ sudo virsh cpu-stats cirros CPU0: cpu_time 0.025812184 seconds vcpu_time 0.025812184 seconds CPU1: cpu_time 4.893484927 seconds vcpu_time 4.893484927 seconds Total: cpu_time 4.924620941 seconds user_time 1.060000000 seconds system_time 3.050000000 seconds I would be very grateful to get any suggestions from anyone. Thanks, Anton On Sat, Aug 18, 2012 at 4:07 PM, Anton Beloglazov < anton.beloglazov@gmail.com> wrote:
Hi Olivier,
Thanks for the links. I see now that there is an option to assign permissions to access control groups for non-root users. I'll try to configure it and post back the results.
Best regards, Anton
On Fri, Aug 17, 2012 at 11:31 PM, Anton Beloglazov < anton.beloglazov@gmail.com> wrote:
Hi Olivier,
Thanks for the suggestion, but Cgroups is installed and started. As I mentioned, everything works for the root user. Should I do some special configuration for a non-root user? Currently, my /etc/cgconfig.conf contains the following:
mount { cpuacct = /mnt/cgroups/cpuacct; }
Thanks, Anton
On Fri, Aug 17, 2012 at 11:24 PM, Olivier Doucet <webmaster@ajeux.com>wrote:
Hi,
libvir: QEMU Driver error : Requested operation is not valid: cgroup CPUACCT controller is not mounted
You need to install/configure Cgroups on your system : http://en.wikipedia.org/wiki/Cgroups
https://access.redhat.com/knowledge/docs/en-US/Red_Hat_Enterprise_Linux/6/ht...
Olivier
participants (2)
-
Anton Beloglazov
-
Olivier Doucet