The /System/Library/CoreServices/ServerVersion.plist exists on macOS servers , but not on a workstation such as my laptop. The actual terminoly is mostly borrowed from the windows equivalent as @Lomanic suggested. In theory, this should make interpreting the results from the two platforms a bit more consistent.
Note: The macOS server application can be installed on almost any macOS workstation to make it a server that can manage other apple devices.
gopsutil is a transitive dependency of another project that I am integrating
into an internal build system. We target multiple platforms and as a part
of the build system for the large internal repo, we calculate the build
graph used to determine what targets have changed and need to be build /
tested as a single DAG for all platforms.
gopsutil currently does not form a DAG if linux and any other platform are
considered at the same time. linux is the only platform where the process
package imports the host package.
To remove this cycle, the relevant methods have been moved to internal/common
with the linux build tag and are consumed the host and process packages.
Remains backward compatible.
When encountering non-fatal errors SensorsTemperatures() returns the
temperatures for all the sensor we could read successfully. In that
case the custom error contains a list of all the non-fatal errors
encountered.
Example usage:
_, err := SensorsTemperatures()
if err != nil {
warns, ok := err.(*Warnings)
if ok {
fmt.Printf("%v\n", err)
for i, w := range warns.List {
fmt.Printf("Warning %v: %v\n", i+1, w)
}
} else {
t.Errorf("%v", err)
}
}
On Linux, most golang programs do not run as root (or at least, they should not),
by default, the kernels uses strict permissions, so most userland programs cannot
read `/sys/class/dmi/id/product_uuid`. However, programs such as Consul are relying
on it to get fixed IDs, instead they have a different ID on each boot.
We propose to use `/etc/machine-id` as fallback https://www.freedesktop.org/software/systemd/man/machine-id.html
In order to fix this, this patch does the following:
- if `/sys/class/dmi/id/product_uuid` can be read, use it for HostID
- else if `/etc/machine-id` exists and has 32 chars, use it and add '-' to have the same format as product_uuid
- finally, if notthing works, use the `kernel.random.boot_id`
This will greatly increase the number of programs having correct behaviour when
those rely on having a fixed HostID.
This will fix the following issues:
- https://github.com/shirou/gopsutil/issues/350
- https://github.com/hashicorp/consul/issues/4741
Same as commit fc04d2d, but for mips64le from mipsle definition.
It would be nice if anyone can check with the correctness, since the
qemu environment for mips64/mips64le can't run Go properly due to this
issue: https://github.com/golang/go/issues/15416
The order of init function execution is dependant on the order that the
source files are passed to the compiler. This causes issues when
building under other build systems, such as bazel or buck, as they are
not guarenteed to maintain the same file order as the default go tool.
Improve performance by eliminating the fork out to uname on FreeBSD which also helps prevent crashes / hangs due to the outstanding fork crash bug:
golang/go#15658
Also added a test for PlatformInformation.
In order to improve performance and help prevent crashes due to the outstanding fork crash bug:
https://github.com/golang/go/issues/15658
Replace string parsed values from the sysctl command with native reads of sysctl values using unix.SysctlRaw and unix.SysctlUint32.
This also merges OpenBSD and FreeBSD load implementations which are identical.
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}
Package common wasn't used for public functions. Place it in an
internal directory to prevent other packages from using.
Remove the distributed references to "HOST_PROC" and "HOST_SYS"
consts and combine into a common function. This also helps so that
if a env var is defined with a trailing slash all will continue to
work as expected.
Fixes #100
Added the ability to fetch an alternative location for /proc via an
environment variable. If the env var is not set it will return /proc as
the default value.