serverinfo
serverinfo copied to clipboard
Meminfo support for OpenBSD
Meminfo currently only supports Linux and FreeBSD [0]
The output of top contains this information, and OpenBSD (and perhaps others?) have a -d option, which only refreshes the requested number of times.
$ top -d1
load averages: 4.87, 4.72, 4.83 host.example.net 02:43:39
59 processes: 4 running, 54 idle, 1 on processor up 13:59
CPU states: 39.0% user, 5.6% nice, 17.0% system, 0.5% interrupt, 37.9% idle
Memory: Real: 701M/1254M act/tot Free: 681M Cache: 387M Swap: 72M/11G
PID USERNAME PRI NICE SIZE RES STATE WAIT TIME CPU COMMAND
35645 root 58 0 25M 34M run - 8:21 20.07% perl
...
So we could exec this and parse the information out.
[0] https://github.com/nextcloud/serverinfo/blob/203e90df095ed70a0a9cbbe498e8e601f893d4b5/lib/SystemStatistics.php#L79
I added the FreeBSD support, did you try if the solution for FreeBSD also works in OpenBSD?
it would be these shell commands:
/sbin/sysctl -n hw.physmem hw.pagesize vm.stats.vm.v_inactive_count vm.stats.vm.v_cache_count vm.stats.vm.v_free_count
/usr/sbin/swapinfo
If that doesn't work, you could add a case for OpenBSD where you parse the information.
Yup, I tried it out before opening this ticket:
$ /sbin/sysctl -n hw.physmem hw.pagesize vm.stats.vm.v_inactive_count vm.stats.vm.v_cache_count vm.stats.vm.v_free_count
2090799104
4096
sysctl: second level name stats in vm.stats.vm.v_inactive_count is invalid
sysctl: second level name stats in vm.stats.vm.v_cache_count is invalid
sysctl: second level name stats in vm.stats.vm.v_free_count is invalid
$ /usr/sbin/swapinfo
-bash: /usr/sbin/swapinfo: No such file or directory
The converse, though, is that I think my suggestion of parsing the output of top should also work on FreeBSD (and hopefully a number of other Unices). Could you try it out and confirm?
For OpenBSD, I found this: https://www.cyberciti.biz/faq/openbsd-checking-for-ram-memory-size/
so it seems there is a chance if we parse the sysctl output a bit differently. I also found this project which does the job for a number of different systems: https://github.com/jrgp/linfo