Using htop or free inside a container gives the information for host machine resources. However I want the utilization status specific to the container. lxc info on a container id gives me the following result:-
But this information is not consistent with htop on the host machine. htop tells me that each container is using 98M of memory. Even if I account for slight difference in measurement 98 MB and 1.44GB are two very different results. What is the best way to find the memory usage of a container?
htop is unlikely to get the whole picture when it comes to container memory consumption. You need to look at all the processes that are running inside the container AND also account for any tmpfs filesystems or similar kernel resource usage.
You probably should consider installing “lxcfs” on your system which would then have “free” and other commands report the right values inside the container.
Thank you @stgraber I already have lxcfs installed. Do I need to do anything else to make it work? I did take a look at the reference but I’m not sure how to use it…
Is the output of lxc info (like the one I posted in the description above) reliable? Can I accept the memory stats it gives me back?
guest# free -h
total used free shared buff/cache available
Mem: 62G 54G 8.5G 330M 6.7M 8.5G
Swap: 17G 139M 17G
guest# ps -e -o pmem= | paste -sd+ | bc -l
14.0
Why does lxc-info on the host say 54.21GB, but free5.7G? Is there a way to get accurate values inside a container even if I have to write a script, or access /proc directly? Is there anything I can check?
I have an assumption that 54GB includes buff/cache, but how do I then separate those values inside a container?