This commit adds support for Info(), BootTime() and Uptime() in package
Host. It uses no cgo, preferring to parse the output of `kstat -p`
instead.
Thanks go to @gfrey for the parsing logic for `/etc/release` and `uname`.
When fetching stats on all processes at once there's a non-trivial amount of
time spent in the `BootTime` call. But since this value should never change
during a live process, we can use a cached version for all subsequent calls.
This enables using gopsutil in a codebase that gets built on other OSes
than the ones supported. Instead of a build failure as before, due to
the build tags, gopsutil will now throw an "not implemented" runtime
error.
Fixes#234.
This is mostly intended for Linux, where we are returning the OS version
in the PlatformVersion field, which seems reasonable. Often it is still
useful to know which Linux kernel is running.
For FreeBSD and Darwin the kernel version matches the platform version,
since they previously used the kernel version for the platform version.
For Windows the kernel version is empty, since there is no clear way
to determine it.
before falling back to kernel.random.boot_id.
`/sys/class/dmi/id/product_uuid` is still managed by permissions, so
for root-run processes where `/sys/class/dmi/id/product_uuid` is
available, the host's UUID will be used instead, otherwise the UUID
from kernel.random.boot_id will be used instead.
On supported hosts the value returned is a UUID (case preserving
from the value of the underlying OS).
For Linux this is generated once, randomly per boot. For FreeBSD and
Darwin this is a more durable value that should persist across reboots.
host_darwin does the same filtering. Not doing this gives us some rather strange
entries that likely aren't what we want.
Before:
{"user":"reboot","terminal":"~","host":"3.10.0-327.4.5.el7.x86_64","started":1454378260}
{"user":"LOGIN","terminal":"ttyS0","host":"","started":1454378270}
{"user":"LOGIN","terminal":"tty1","host":"","started":1454378270}
{"user":"runlevel","terminal":"~","host":"3.10.0-327.4.5.el7.x86_64","started":1454378276}
{"user":"root","terminal":"pts/0","host":"vpn","started":1454404513}
After:
{"user":"root","terminal":"pts/0","host":"vpn","started":1454404513}