Portable way to gather process statistics?

Some time ago, I ported the SLURM HPC cluster resource manager to FreeBSD. Almost all the features now work, but complete job accounting depends on linprocfs to gather process memory use, cpu time, etc. The SLURM code only offers complete accounting for a couple of platforms, using non-portable code. The Linux code simply parses files under /proc. This works on FreeBSD if linprocfs is mounted and the path is changed to /compat/linux/proc.

I'm curious about possible ways to gather stats directly on FreeBSD, without a linuxulator dependency.

From what I've found so far, libprocstat appears to be the high-level interface for doing this sort of thing under FreeBSD, but it also appears to be endemic to FreeBSD.

I'm losing hope of finding a truly portable interface, but I'd prefer to find a method that's at least somewhat portable, so we don't squander precious man-hours writing redundant code. It looks like kvm_getprocs() might at least provide a somewhat uniform interface across BSD systems.

Anyone have other suggestions?

Thanks,

Jason
 
A lot of what you can find on Linux on procfs is found as a sysctl. This includes memory, as well as temperature and battery information. That's where tools, such as conky, which can easily be configured to output whatever you want. I use it for the i3 status bar. This is an interface for all sorts of status information. In the recent release deciding how the output should be became much easier.

Even if the default is to provide you with a GUI, that's by far not the only way you can use it. Like I wrote, I use the JSON interface of i3, simply by having a conky.text template that creates the output. So depending on what exactly you want I'd go for sysctl or conky. Even though I am not sure about conky necessarily being the best option. It's really made for various kinds of displays, so it has the system information part, but also other things, like Eve Online account status or so.

For actual process information you have two tools. ps and proctstat. I don't know how compatible flags of ps are (there certainly aren't jails in Linux) and there is procstat, which can shows you pretty much everything about a process you want to know.

I hope that helps. :)
 
Back
Top