How does a tool like Net-SNMP captures CPU usage?
And what would be the least intrusive way to do it under Linux?
Less intrusive in the way that doing so would consume the least amount of machine resources (both cpu and ram) in order to do it. Eventually the data will be saved into a file.
There is no other way to calculate the current CPU utilization than reading
/procexcept for the kernel itself. All common tools like ps, top etc. are also just reading/proc, either/proc/statfor an overall CPU usage or/proc/<pid>/statfor a per-process CPU usage. However as/procis a virtual file system directly provided by the kernel the overhead for reading files in it is way smaller than for regular files.If you don’t want to read
/procyourself try to use a tool that does only little extra computations, likepsas mentioned by @deep.