zcalusic / sysinfo

Sysinfo is a Go library providing Linux OS / kernel / hardware system information.
MIT License
527 stars 93 forks source link

RFE to allow for container usage #23

Open adkerr opened 4 years ago

adkerr commented 4 years ago

My use case is probably fairly unusual and I do have a work around, but I was wondering if you'd be willing to consider adding an optional value to systemInfo struct that would place a prefix on all the paths to files? What I'm attempting to do is use this package inside a docker container and mount the host filesystem into the container in order to detect the host's info. Typically when this is done you'll mount the host's FS into a directory like /host so it doesn't collide with the container's FS. So if it was possible to set something like si.PathPrefix or whatever name you like that gets prepended to each of the currently hardcoded file paths that would be very useful. For now I'm able to simply mount the host's /etc dir directly over the container's /etc and it works as expected (I personally am most interested in the OS info, so only need etc), but it would be best, and allow expanded use cases, to keep the host and container FS's separated properly.

zcalusic commented 4 years ago

Hello @adkerr, and thanks for your comment.

While I do run lots of containers, somehow I haven't yet attempted to run sysinfo in a container. ;)

But, I'm certain it would be useful in many cases, so yes, I'd actually be willing to check the details and do what needs to be done, so that it can be used in a container enviroment more easily.

Even if sysinfo is actually a per-host thing, I see the beauty of orchestrating it (say via k8s daemonset) and using it that way to access host info.

I can't promise when I'll have enough time to investigate all that properly, but I can promise I'll come back to this topic ASAP. Together with all other ideas that I've collected in the meantime and just didn't have time to execute them yet. :cry:

adkerr commented 4 years ago

Thanks for your response @zcalusic. No rush on this; as I said I've got a workaround.

You've got a wonderful tool here that has greatly simplified the task of figuring the host distro and version for me. Keep up the good work!