jtpio/jupyterlab-system-monitor

How to get cpu and memory information from docker container

kwon14 opened this issue · 1 comments

Hello. Thank you so much for providing a good extension.

I am using Jupyterlab with ubuntu docker running.
To use jupyterlab-system-monitor, you need to set the number of CPU cores and memory capacity allocated to the container,
but I can't figure out how to get that information.

Please share how to get cpu and memory information in the container.

thank you.

dleen commented

Hi,

For memory, depending on your distribution, you can find this information via cgroups in the file: /sys/fs/cgroup/memory/memory.limit_in_bytes. For my container I get the following (using a quick Python script to convert to MiB):

cat /sys/fs/cgroup/memory/memory.limit_in_bytes | python -c 'import sys; print(int(sys.stdin.readlines()[0].strip())/1024/1024)'
16384.0

which shows 16384MiB or 16GiB as the limit.

CPU is much more difficult. You might be able to do something similar via some file in /sys/fs/cgroup/cpu but unlike memory CPU usage is relative to other processes/containers. It would be better if you could pass the value you pass to Docker --cpus as an environment variable and read that from inside the container.