A CFFI wrapper for the Linux sysinfo(2)
syscall, giving access to uptime, load averages, and memory/swap usage.
Platform: Linux only. The binding groves
sys/sysinfo.h, which is provided by glibc on Linux; it will not build on macOS or the BSDs.
The system depends on cffi (with
cffi-grovel) and local-time-duration,
and needs a C compiler available for the grovel step.
(asdf:load-system "cl-sysinfo")Returns the current system statistics as a plist:
(sysinfo:sysinfo)
;; =>
;; (:UPTIME 472031 :LOADS (1.8579102 1.9272461 1.4038086) :TOTALRAM 20764299264
;; :FREERAM 1156550656 :SHAREDRAM 1182826496 :BUFFERRAM 699760640 :TOTALSWAP
;; 2147479552 :FREESWAP 2147479552 :PROCS 2372 :TOTALHIGH 0 :FREEHIGH 0 :MEM-UNIT
;; 1)| Key | Meaning |
|---|---|
:uptime |
Seconds since boot |
:loads |
1-, 5- and 15-minute load averages (single-floats) |
:totalram |
Total usable main memory |
:freeram |
Available memory |
:sharedram |
Amount of shared memory |
:bufferram |
Memory used by buffers |
:totalswap |
Total swap space |
:freeswap |
Free swap space |
:procs |
Number of current processes |
:totalhigh |
Total high memory |
:freehigh |
Available high memory |
:mem-unit |
Size, in bytes, of the memory unit used by the fields above |
Note: All memory and swap sizes are expressed in units of
:mem-unitbytes, not bytes. Multiply by:mem-unitto get a value in bytes (it is usually1).
The same data as sysinfo, but as an association list of (KEY . VALUE).
The values, in the same order as sysinfo. Note that the :loads value is
itself a list, so the result is not fully flat.
The system uptime as a local-time-duration duration, ready for formatting
or arithmetic.
Each of the three accessors above takes an optional
infoplist (as returned bysysinfo). Pass one you already have to avoid an extra syscall and to get a consistent snapshot across calls; otherwise a fresh one is fetched.
sysinfo:sysinfo-error is signalled (a subclass of cl:error) if the
syscall fails. The syscall return code is available via
sysinfo:sysinfo-error-code, and the C errno (when the implementation
exposes it) via sysinfo:sysinfo-error-errno.
(asdf:test-system "cl-sysinfo")The test suite uses FiveAM. From a shell
you can also run ./scripts/run-tests.sh (requires
Roswell).
See CHANGELOG.md.
LLGPL — see LICENSE.