pixelb / ps_mem

A utility to accurately report the in core memory usage for a program
GNU Lesser General Public License v2.1
1.55k stars 282 forks source link

Accurate reporting for host machine - when inside a docker container #49

Open gotjoshua opened 5 years ago

gotjoshua commented 5 years ago

I was trying to use ps_mem inside a glances container to write logs in response to alerts. The glances docker container that I ran ps_mem inside of has full access to the host and shows processes correctly. Unfortunately, ps_mem did not list the actual processes from the host.

Is there a trick to make this work as is? or would it be a feature request?

pixelb commented 5 years ago

If there was a way to get the pids associated with the container, one could pass them to ps_mem -p pid1,pid2. If glances operates in a separate pid namespace, one might be able to remount /proc within that container to get the PID subset?

gotjoshua commented 5 years ago

Hi, thanks for the reply!

I did try that strategy (getting the pids from ps and then passing them to ps_mem via ps_mem -p pid1,pid2 but the output was empty... most likely, due the missing /proc

is that safe to just mount the host's proc folder into a container?

You can't mount to /proc.

Or can you suggest precisely where to mount it to?

pixelb commented 5 years ago

You should be able to mount /proc and need it available

gotjoshua commented 5 years ago

i tried

volumes:
 - /proc/:/proc/

and got an error

do you have another suggestion where to mount it and how to tell ps_mem where to look for it?

NHellFire commented 4 years ago

You'll need to run the glances container with --pid host for it to not have a separate PID namespace (as mentioned in their docs).