Skip to content

fix(pacakging): fix cpu/memory metrics when running inside LXC container as systemd service#14255

Merged
ilyam8 merged 5 commits into
netdata:masterfrom
ilyam8:fix_mem_calc_inside_lxc_container
Jan 16, 2023
Merged

fix(pacakging): fix cpu/memory metrics when running inside LXC container as systemd service#14255
ilyam8 merged 5 commits into
netdata:masterfrom
ilyam8:fix_mem_calc_inside_lxc_container

Conversation

@ilyam8
Copy link
Copy Markdown
Member

@ilyam8 ilyam8 commented Jan 12, 2023

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.

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:

  • Updates Netdata systemd unit file: configures LXCFS proc mounts.
  • Fixes RAM calculation when using ZFS (we should ignore ZFS ARC cache shrinkable size).
  • Fixes calculation of the number of processors in system-info.sh.
Test Plan
  • install this branch in LXC container
  • check CPU cores (number) and memory (ram, mem available) charts.
Additional Information
For users: How does this change affect me?

@github-actions github-actions Bot added area/collectors Everything related to data collection collectors/proc area/packaging Packaging and operating systems support labels Jan 12, 2023
@ilyam8 ilyam8 changed the title fix(proc.plugin): ignore zfs arc cache when lxcfc proc is mounted fix(pacakging): fix incorrect cpu/memory metrics when running inside LXC container Jan 13, 2023
Comment thread system/netdata.service.in
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
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 0
current 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 0

@ilyam8 ilyam8 changed the title fix(pacakging): fix incorrect cpu/memory metrics when running inside LXC container fix(pacakging): fix incorrect cpu/memory metrics when running inside LXC container as systemd service Jan 13, 2023
@ilyam8 ilyam8 marked this pull request as ready for review January 13, 2023 10:12
@ilyam8 ilyam8 changed the title fix(pacakging): fix incorrect cpu/memory metrics when running inside LXC container as systemd service fix(pacakging): fix cpu/memory metrics when running inside LXC container as systemd service Jan 13, 2023
@ilyam8 ilyam8 requested a review from MrZammler January 13, 2023 10:14
@ilyam8 ilyam8 requested a review from vkalintiris as a code owner January 13, 2023 10:38
@ilyam8 ilyam8 force-pushed the fix_mem_calc_inside_lxc_container branch from 32efe11 to 35f9dc5 Compare January 13, 2023 10:43
@netdata-community-bot
Copy link
Copy Markdown

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

@ilyam8 ilyam8 force-pushed the fix_mem_calc_inside_lxc_container branch from 0169dc3 to 15981f7 Compare January 14, 2023 16:24
Comment thread collectors/proc.plugin/plugin_proc.c
@thiagoftsm thiagoftsm self-requested a review January 16, 2023 12:03
Copy link
Copy Markdown
Member

@Ferroin Ferroin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving the service file changes and system-info script changes.

Copy link
Copy Markdown
Contributor

@thiagoftsm thiagoftsm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR is working as expected, LGTM!

@ilyam8 ilyam8 merged commit a14a21f into netdata:master Jan 16, 2023
@ilyam8 ilyam8 deleted the fix_mem_calc_inside_lxc_container branch January 16, 2023 13:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/collectors Everything related to data collection area/daemon area/packaging Packaging and operating systems support collectors/proc

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Incorrect memory reporting while running in lxc container

4 participants