1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-03-20 10:50:08 +03:00

B #2824 fix LXD container monitoring (#2840)

* handle exceptions in get_memory()
* add option to set cgroup prefix to the container path via the environment variable `LXC_CGROUP_PREFIX`

In case of a more complex cgroup configuration the containers cgroup could be placed in separate slice instead of default root cgroup. In this case the defining LXC_CGROUP_PREFIX="system.slice/" (note the trailing slash) in the environment will help vmm/lxd/poll to construct correct path the needed *memory* and *cpu,cpuacct* cgroups

```bash
su - oneadmin -c 'echo "export LXC_CGROUP_PREFIX=system.slice" >>~/.bashrc'
```
This commit is contained in:
Anton Todorov 2019-01-24 12:02:39 +02:00 committed by Ruben S. Montero
parent fa4d1b3a89
commit 47bb4c0a4a

View File

@ -129,10 +129,19 @@ module LXD
state
end
def lxc_path(vm_name)
path = 'lxc/' + vm_name
path = "#{ENV['LXC_CGROUP_PREFIX']}#{path}" if ENV['LXC_CGROUP_PREFIX']
end
def get_memory(vm_name)
stat = File.read('/sys/fs/cgroup/memory/lxc/' + vm_name + '/memory.usage_in_bytes').to_i
stat / 1024
begin
stat = File.read('/sys/fs/cgroup/memory/' + lxc_path(vm_name) + '/memory.usage_in_bytes').to_i
stat / 1024
rescue StandardError
return 0
end
end
def get_net_statistics(vmd)
@ -196,7 +205,8 @@ module LXD
def get_process_jiffies(vm_name)
begin
jiffies = 0
stat = File.read('/sys/fs/cgroup/cpu,cpuacct/lxc/' + vm_name + '/cpuacct.stat')
stat = File.read('/sys/fs/cgroup/cpu,cpuacct/' + lxc_path(vm_name) + '/cpuacct.stat')
stat.lines.each {|line| jiffies += line.split(' ')[1] }
rescue StandardError
return 0