eminence/procfs

Add an optionnal prefix to /proc for gathering data ?

Closed this issue · 5 comments

Hi,

First thanks a lot for this library that we use actively in https://github.com/hubblo-org/scaphandre/. This is really great work and allows us to save a lot of time.

I'd like to propose a feature that would be definitely useful for us but I'm not sure if it would fit in the direction you want to take with procfs. So this is more a question about whether you'd accept considering this feature or not. If so, I'd gladly propose a PR accordingly.

To allow our project to run with Docker while being as secure as possible, we'd like to enable mounting /proc (and /sys/class/powercap, but this is specific to scaphandre) as RO volumes. However this causes apparmor in the container to crash as it need to touch /proc/self at some point (didn't test yet with selinux for example). This behavior is discussed here if you are interested in the details.

To fix that we would like to pass an optionnal prefix (/myprefix for example) for scaphandre to gather data from /myprefix/proc and /myprefix/sys/class/powercap instead of /proc and /sys/class/powercap.
So the question is: would you consider adding an optionnal prefix, using procfs, so that it could get data from a prefixed path in such a context ?

Thanks a lot for your time.

Hello! Sorry to taking so long to reply.

In general, yes this is something I'd like to support. But I'm not exactly sure on the best API. Since /proc is almost always where procfs lives, I want to optimize for this case.

In #116, a change was made to make the from_reader constructor public, allowing someone to open a procfs file from an arbitrary location and parse the data with this procfs crate. I think this is a good idea, and is something I want to do for all the construtors.

This would at least partially work in your use-case, but is probably not ideal for you. There may be missing (non-public) constructors still, and it puts more work on you (the client code) to find and open the file.

Do you have a particular API in mind for allowing procfs to read from arbitrary prefixes?

Hi ! Thanks for that answer (and sorry for the late reply on our side !). In our case we use process::all_processes() most of the time and then use the data we have for each Process.

I see that #122 is open and seems to deal with process::all_processes so I guess we may have a solution once it's merged ?

Hi !

Updating this thread after a few months :)

Would you confirm that #122 fixes this feature request ? Or did I understand something wrong ?

thanks a lot !

Hi 👋

Yes, I think #122 would have been a good solution for you, since you were only caring about processes. Unfortunately that function was accidentally removed, but was just re-introduced in #184 (which has been published as v0.13.2).

Can you give v0.13.2 a try and let me know if it's working for your use-case?

Thanks!

I think this is solved for processes, plus some one-off use-cases (like #191), so I'm going to close this. But please let me know if you have a use-case that's not handled.