Closed stevenh closed 2 years ago
I have changed to use SysctlRaw
to LoadAvg
at 1ba77cdb3d0f8a2b7016b3b0c462e4e2b5ad503b. But SysctlRaw returns binary and should parse result by myself. It is hard to parse, I can not change all of function to use SysctlRaw
Thanks @shirou we're looking at open sourcing our library which handles the parsing.
I'll do a PR for this shortly.
I've put in a PR which eliminates the use of the sysctl command on FreeBSD: https://github.com/shirou/gopsutil/pull/432 obviously there's other uses of external commands too, so leaving this issue open for reference, but this should at least help.
For reference our little package which helps decoding structs when there's padding involved, which is can be the case in sysctl structs, can be found here: https://github.com/multiplay/go-utils
Thank you for your awesome contribution about #432. As you said, I leave this issue. I will also try to eliminate other commands. Thank you so much.
golang/go#15658 was marked as fixed (either by FreeBSD or the language runtime), shall we keep this one opened (say, to remove the remaining external commands) or not?
Still worth while eliminating the requirement for external commands
common.DoSysctrl
is not called anymore in gopsutil as seen from a grep -IrF common.DoSysctrl
.
Due to the issue with golang forking the use of external commands eventually causes any users of gopsutil/load.Avg to crash the binary. See for more information: https://github.com/golang/go/issues/15658
The main culprit of this is common.DoSysctrl which forks out to /usr/bin/sysctl which should never be needed as the values can be read without forking using the in built unix.SysctlRaw function.
We have had this happen several times now with telegraf which uses gopsutil to determine load in the system plugin.