fix(pacakging): fix cpu/memory metrics when running inside LXC container as systemd service#14255
Merged
Merged
Conversation
ilyam8
commented
Jan 13, 2023
Comment on lines
+74
to
+77
| # LXCFS directories (https://github.com/lxc/lxcfs#lxcfs) | ||
| # If we don't set them explicitly, systemd mounts procfs from the host. See https://github.com/netdata/netdata/issues/14238. | ||
| BindReadOnlyPaths=-/proc/cpuinfo -/proc/diskstats -/proc/loadavg -/proc/meminfo | ||
| BindReadOnlyPaths=-/proc/stat -/proc/swaps -/proc/uptime -/proc/slabinfo |
Member
Author
There was a problem hiding this comment.
An alternative is the BindReadOnlyPaths=/proc:/proc:rbind one-liner (suggested in #14238). It works, but I decided to not use it because it makes /proc/mounts kinda messy.
proc rbind
rpool/data/subvol-111-disk-0 / zfs rw,noatime,xattr,posixacl 0 0
none /dev tmpfs rw,relatime,size=492k,mode=755,uid=100000,gid=100000,inode64 0 0
mqueue /dev/mqueue mqueue rw,relatime 0 0
proc /dev/.lxc/proc proc rw,relatime 0 0
sys /dev/.lxc/sys sysfs rw,relatime 0 0
udev /dev/full devtmpfs rw,nosuid,relatime,size=264070148k,nr_inodes=66017537,mode=755,inode64 0 0
udev /dev/null devtmpfs rw,nosuid,relatime,size=264070148k,nr_inodes=66017537,mode=755,inode64 0 0
udev /dev/random devtmpfs rw,nosuid,relatime,size=264070148k,nr_inodes=66017537,mode=755,inode64 0 0
udev /dev/tty devtmpfs rw,nosuid,relatime,size=264070148k,nr_inodes=66017537,mode=755,inode64 0 0
udev /dev/urandom devtmpfs rw,nosuid,relatime,size=264070148k,nr_inodes=66017537,mode=755,inode64 0 0
udev /dev/zero devtmpfs rw,nosuid,relatime,size=264070148k,nr_inodes=66017537,mode=755,inode64 0 0
devpts /dev/pts devpts rw,nosuid,noexec,relatime,gid=100005,mode=620,ptmxmode=666,max=1026 0 0
devpts /dev/ptmx devpts rw,nosuid,noexec,relatime,gid=100005,mode=620,ptmxmode=666,max=1026 0 0
devpts /dev/console devpts rw,nosuid,noexec,relatime,gid=100005,mode=620,ptmxmode=666,max=1026 0 0
devpts /dev/tty1 devpts rw,nosuid,noexec,relatime,gid=100005,mode=620,ptmxmode=666,max=1026 0 0
devpts /dev/tty2 devpts rw,nosuid,noexec,relatime,gid=100005,mode=620,ptmxmode=666,max=1026 0 0
tmpfs /dev/shm tmpfs rw,nosuid,nodev,uid=100000,gid=100000,inode64 0 0
proc /proc proc rw,nosuid,nodev,noexec,relatime 0 0
proc /proc/sys proc ro,relatime 0 0
proc /proc/sys/net proc rw,nosuid,nodev,noexec,relatime 0 0
binfmt_misc /proc/sys/fs/binfmt_misc binfmt_misc rw,nosuid,nodev,noexec,relatime 0 0
none /proc/sys/kernel/random/boot_id tmpfs ro,nosuid,nodev,noexec,relatime,size=492k,mode=755,uid=100000,gid=100000,inode64 0 0
proc /proc/sysrq-trigger proc ro,relatime 0 0
lxcfs /proc/cpuinfo fuse.lxcfs rw,nosuid,nodev,relatime,user_id=0,group_id=0,allow_other 0 0
lxcfs /proc/diskstats fuse.lxcfs rw,nosuid,nodev,relatime,user_id=0,group_id=0,allow_other 0 0
lxcfs /proc/loadavg fuse.lxcfs rw,nosuid,nodev,relatime,user_id=0,group_id=0,allow_other 0 0
lxcfs /proc/meminfo fuse.lxcfs rw,nosuid,nodev,relatime,user_id=0,group_id=0,allow_other 0 0
lxcfs /proc/stat fuse.lxcfs rw,nosuid,nodev,relatime,user_id=0,group_id=0,allow_other 0 0
lxcfs /proc/swaps fuse.lxcfs rw,nosuid,nodev,relatime,user_id=0,group_id=0,allow_other 0 0
lxcfs /proc/uptime fuse.lxcfs rw,nosuid,nodev,relatime,user_id=0,group_id=0,allow_other 0 0
sysfs /sys sysfs ro,nosuid,nodev,noexec,relatime 0 0
sysfs /sys/devices/virtual/net sysfs rw,nosuid,nodev,noexec,relatime 0 0
fusectl /sys/fs/fuse/connections fusectl rw,nosuid,nodev,noexec,relatime 0 0
debugfs /sys/kernel/debug debugfs rw,nosuid,nodev,noexec,relatime 0 0
securityfs /sys/kernel/security securityfs rw,nosuid,nodev,noexec,relatime 0 0
pstore /sys/fs/pstore pstore rw,nosuid,nodev,noexec,relatime 0 0
efivarfs /sys/firmware/efi/efivars efivarfs rw,nosuid,nodev,noexec,relatime 0 0
none /sys/fs/cgroup cgroup2 ro,nosuid,nodev,noexec,relatime 0 0
lxcfs /sys/devices/system/cpu/online fuse.lxcfs rw,nosuid,nodev,noexec,relatime,user_id=0,group_id=0,allow_other 0 0
tmpfs /run tmpfs rw,nosuid,nodev,size=105641444k,nr_inodes=819200,mode=755,uid=100000,gid=100000,inode64 0 0
tmpfs /run/lock tmpfs rw,nosuid,nodev,noexec,relatime,size=5120k,uid=100000,gid=100000,inode64 0 0
proc /proc proc ro,nosuid,nodev,noexec,relatime 0 0
proc /proc/sys proc ro,noexec,relatime 0 0
proc /proc/sys/net proc ro,nosuid,nodev,noexec,relatime 0 0
binfmt_misc /proc/sys/fs/binfmt_misc binfmt_misc ro,nosuid,nodev,noexec,relatime 0 0
none /proc/sys/kernel/random/boot_id tmpfs ro,nosuid,nodev,noexec,relatime,size=492k,mode=755,uid=100000,gid=100000,inode64 0 0
proc /proc/sysrq-trigger proc ro,noexec,relatime 0 0
lxcfs /proc/cpuinfo fuse.lxcfs ro,nosuid,nodev,noexec,relatime,user_id=0,group_id=0,allow_other 0 0
lxcfs /proc/diskstats fuse.lxcfs ro,nosuid,nodev,noexec,relatime,user_id=0,group_id=0,allow_other 0 0
lxcfs /proc/loadavg fuse.lxcfs ro,nosuid,nodev,noexec,relatime,user_id=0,group_id=0,allow_other 0 0
lxcfs /proc/meminfo fuse.lxcfs ro,nosuid,nodev,noexec,relatime,user_id=0,group_id=0,allow_other 0 0
lxcfs /proc/stat fuse.lxcfs ro,nosuid,nodev,noexec,relatime,user_id=0,group_id=0,allow_other 0 0
lxcfs /proc/swaps fuse.lxcfs ro,nosuid,nodev,noexec,relatime,user_id=0,group_id=0,allow_other 0 0
lxcfs /proc/uptime fuse.lxcfs ro,nosuid,nodev,noexec,relatime,user_id=0,group_id=0,allow_other 0 0
tmpfs /run/credentials tmpfs ro,nosuid,nodev,noexec,size=105641444k,nr_inodes=819200,mode=755,uid=100000,gid=100000,inode64 0 0
tmpfs /run/systemd/incoming tmpfs ro,nosuid,nodev,size=105641444k,nr_inodes=819200,mode=755,uid=100000,gid=100000,inode64 0 0current approach
rpool/data/subvol-111-disk-0 / zfs rw,noatime,xattr,posixacl 0 0
none /dev tmpfs rw,relatime,size=492k,mode=755,uid=100000,gid=100000,inode64 0 0
mqueue /dev/mqueue mqueue rw,relatime 0 0
proc /dev/.lxc/proc proc rw,relatime 0 0
sys /dev/.lxc/sys sysfs rw,relatime 0 0
udev /dev/full devtmpfs rw,nosuid,relatime,size=264070148k,nr_inodes=66017537,mode=755,inode64 0 0
udev /dev/null devtmpfs rw,nosuid,relatime,size=264070148k,nr_inodes=66017537,mode=755,inode64 0 0
udev /dev/random devtmpfs rw,nosuid,relatime,size=264070148k,nr_inodes=66017537,mode=755,inode64 0 0
udev /dev/tty devtmpfs rw,nosuid,relatime,size=264070148k,nr_inodes=66017537,mode=755,inode64 0 0
udev /dev/urandom devtmpfs rw,nosuid,relatime,size=264070148k,nr_inodes=66017537,mode=755,inode64 0 0
udev /dev/zero devtmpfs rw,nosuid,relatime,size=264070148k,nr_inodes=66017537,mode=755,inode64 0 0
devpts /dev/pts devpts rw,nosuid,noexec,relatime,gid=100005,mode=620,ptmxmode=666,max=1026 0 0
devpts /dev/ptmx devpts rw,nosuid,noexec,relatime,gid=100005,mode=620,ptmxmode=666,max=1026 0 0
devpts /dev/console devpts rw,nosuid,noexec,relatime,gid=100005,mode=620,ptmxmode=666,max=1026 0 0
devpts /dev/tty1 devpts rw,nosuid,noexec,relatime,gid=100005,mode=620,ptmxmode=666,max=1026 0 0
devpts /dev/tty2 devpts rw,nosuid,noexec,relatime,gid=100005,mode=620,ptmxmode=666,max=1026 0 0
tmpfs /dev/shm tmpfs rw,nosuid,nodev,uid=100000,gid=100000,inode64 0 0
sysfs /sys sysfs ro,nosuid,nodev,noexec,relatime 0 0
sysfs /sys/devices/virtual/net sysfs rw,nosuid,nodev,noexec,relatime 0 0
fusectl /sys/fs/fuse/connections fusectl rw,nosuid,nodev,noexec,relatime 0 0
debugfs /sys/kernel/debug debugfs rw,nosuid,nodev,noexec,relatime 0 0
securityfs /sys/kernel/security securityfs rw,nosuid,nodev,noexec,relatime 0 0
pstore /sys/fs/pstore pstore rw,nosuid,nodev,noexec,relatime 0 0
efivarfs /sys/firmware/efi/efivars efivarfs rw,nosuid,nodev,noexec,relatime 0 0
none /sys/fs/cgroup cgroup2 ro,nosuid,nodev,noexec,relatime 0 0
lxcfs /sys/devices/system/cpu/online fuse.lxcfs rw,nosuid,nodev,noexec,relatime,user_id=0,group_id=0,allow_other 0 0
tmpfs /run tmpfs rw,nosuid,nodev,size=105641444k,nr_inodes=819200,mode=755,uid=100000,gid=100000,inode64 0 0
tmpfs /run/lock tmpfs rw,nosuid,nodev,noexec,relatime,size=5120k,uid=100000,gid=100000,inode64 0 0
tmpfs /run/user/1000 tmpfs rw,nosuid,nodev,relatime,size=52820720k,nr_inodes=13205180,mode=700,uid=101000,gid=101000,inode64 0 0
proc /proc proc rw,nosuid,nodev,noexec,relatime 0 0
lxcfs /proc/cpuinfo fuse.lxcfs ro,nosuid,nodev,relatime,user_id=0,group_id=0,allow_other 0 0
lxcfs /proc/diskstats fuse.lxcfs ro,nosuid,nodev,relatime,user_id=0,group_id=0,allow_other 0 0
lxcfs /proc/loadavg fuse.lxcfs ro,nosuid,nodev,relatime,user_id=0,group_id=0,allow_other 0 0
lxcfs /proc/meminfo fuse.lxcfs ro,nosuid,nodev,relatime,user_id=0,group_id=0,allow_other 0 0
proc /proc/slabinfo proc ro,nosuid,nodev,noexec,relatime 0 0
lxcfs /proc/stat fuse.lxcfs ro,nosuid,nodev,relatime,user_id=0,group_id=0,allow_other 0 0
lxcfs /proc/swaps fuse.lxcfs ro,nosuid,nodev,relatime,user_id=0,group_id=0,allow_other 0 0
lxcfs /proc/uptime fuse.lxcfs ro,nosuid,nodev,relatime,user_id=0,group_id=0,allow_other 0 0
tmpfs /run/credentials tmpfs ro,nosuid,nodev,noexec,size=105641444k,nr_inodes=819200,mode=755,uid=100000,gid=100000,inode64 0 0
tmpfs /run/systemd/incoming tmpfs ro,nosuid,nodev,size=105641444k,nr_inodes=819200,mode=755,uid=100000,gid=100000,inode64 0 032efe11 to
35f9dc5
Compare
|
This pull request has been mentioned on Netdata Community Forums. There might be relevant details there: https://community.netdata.cloud/t/incorrect-available-memory-values-with-lxd-containers/3604/14 |
35f9dc5 to
0169dc3
Compare
0169dc3 to
15981f7
Compare
thiagoftsm
reviewed
Jan 15, 2023
Ferroin
approved these changes
Jan 16, 2023
Member
Ferroin
left a comment
There was a problem hiding this comment.
Approving the service file changes and system-info script changes.
thiagoftsm
approved these changes
Jan 16, 2023
Contributor
thiagoftsm
left a comment
There was a problem hiding this comment.
PR is working as expected, LGTM!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes: #14238
The issue is that the LXCFS proc is not mounted because of ProtectControlGroups=on which causes Netdata to track the host system and not the LXC container it's running in.
That is impossible to "fix" completely because an LXC container is not a VM, so we are limited to LXCFC procfs.
A further improvement in this direction will be to disable plugins that collect host system metrics, which do not make sense to collect inside the LXC container (e.g. ZFS, KSM, etc). I am not going to do it in this PR.
This PR:
Test Plan
Additional Information
For users: How does this change affect me?