Commit Graph

109 Commits (6636b0fd7a4a8fd54ce7a814047d89a05d655910)

Author SHA1 Message Date
mingrammer 017c9f9cbc Fix typos
Lomanic 27ec6a0789 [host][linux] Remove call to sysctl binary in host/host_linux.go #639
Pierre Souchay 890eb80501 Better comments for fallback on /etc/machine-id
Pierre Souchay be2b25a7c6 Have a real fixed HostID on Linux
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
Ozair Jr 0bab9611d2 Adding Slackware platform information
Lomanic 1b47825dcb [host] Fix docker uptime parsing (fix #507)
linuxhe ee5d6a3d8f fix docker uptime
shirou 28f7cb0d63 [host] linux: use uptime even if docker guest.
CHEVY S. HUNGERFORD 29f8dfa1ad fixing SensorKey output
CHEVY S. HUNGERFORD 1c4fa5628c giving temperature more verbose output
shirou cd61c36c4f
Merge branch 'master' into feature/add_context_support
shirou 8b2468f1e7 Merge branch 'master' of github.com:shirou/gopsutil into feature/lxd_boot_time
shirou 4c73494c78 Add WithContext functions.
Lomanic e3ae39aa5b Fix #442, trim sensor names and properly handle CentOS in host.SensorsTemperatures()
shirou dc3a09c1d0 [host] linux: change file if in a lxc container.
Daniel Nelson df2f1a8dd1
Add HOST_VAR envvar and use to locate utmp on Linux.
Frank Schroeder a9e803ef6a
Fix data race in host.BootTime
Shirou WAKAYAMA cdcb9bb2ed [linux] host: fix typo
WAKAYAMA Shirou 25d50d5bc3 [linux]host: change to use filepath.Join
Shirou WAKAYAMA fee973abda [linux]host: fix HostTempreture func
shirou 8e36fe6d8f Merge pull request #334 from dotpy3/macos-linux-temperatures
Added temperatures sensors for macOS and Linux
itnihao 490dbd4ea4 Add hostinfo Virtualization vmware
Eric Gourlaouen 22aefb460a Replaced sys by HostSys
Added TemperatureStat string test
Eric Gourlaouen 8b08ca5fdc added temperatures
tycho garen 22c56d292e close open files
Sean Chittenden 36f5033d97
Unconditionally lowercase the `HostID` from all supported platforms.
Conor Branagan 5afd6f21c9 Cache the boot time after first query.
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.
Lukas Fittl 13aedadcde Add separate kernelVersion field to host information.
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.
Sean Chittenden d490d634ca
On Linux, attempt to read from /sys/class/dmi/id/product_uuid first
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.
Sean Chittenden 59094cd5b7
Add HostID to the Host InfoStat struct returned from host.Info().
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.
Sean Chittenden 4f79984afe
Remove redefined import name for common.
Sean Chittenden a3f57b1314
Resolve cyclic import and create a common helper func, NumProcs()
Sean Chittenden fcd296ea11
Merge branch 'master' of github.com:shirou/gopsutil
Sean Chittenden 69f7f8eaeb
Update host.Info() to return the number of processes on all platforms.
Fixes: #227
Shirou WAKAYAMA dd9b50926c [host]linux: add coreos to Info() and Virtualization().
Shirou WAKAYAMA e9afb36ccf [host] linux: detect docker and rkt correctly
Shirou WAKAYAMA c0d1185809 [host]linux: add alpine linux to detect host.Info().
Shirou WAKAYAMA 57f6aebc7e add Timeout to invoke command and use common.Invoke refs: #201
Shirou WAKAYAMA b1df5a912c [host]linux: type file changed.
Shirou WAKAYAMA 0787e8ba3e [host]linux-arm: update type_liux.go. Test will fail.
Shirou WAKAYAMA bce9212def fix build bugs.
Shirou WAKAYAMA d21ed2b40d search path via exec.LookPath before actual invoke.
Shirou WAKAYAMA ea152ea901 [BREAKING CHANGE] rename functions to pass golint. ex) net.NetIOCounters -> net.IOCounters
Shirou WAKAYAMA fa3e1cc196 [common]linux: add HostEtc to switch '/etc' See #175.
Robin Burchell 3fc7bc1ef7 host_linux: Skip everything that isn't a normal process.
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}
Paul Querna 008f2b4e18 Get Arch Linux Version from LSB
Cameron Sparr 444ee723c3 Fix HostInfo.Uptime, which has been returning boot time
Also adding a HostInfo.BootTime field for holding the boot time
Daniel Theophanes 0af895258e common: rename package common to internal/common. Add ENV helper funcs.
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
Jonathan Chauncey 0461c50666 chore(*): Fixes #94
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.
Nick Galbreath 99d93f93b2 shirou/gopsutil#90 make hostinfo more robust
Shirou WAKAYAMA ba88128af1 host_linux: change some virtualization check StringsContains to StringsHas.`
Shirou WAKAYAMA b5ffc220a6 common: Rename StringContains to StringsContains and add StringsHas.
Shirou WAKAYAMA 3bd9ace228 [linux] fix Host.BootTime(). It was seconds from Booted, not from epoch.
Fabian Ruff 91a97374c4 Add SuSe platform detection
Shirou WAKAYAMA cfb473f810 host linux now use godefs.
Shirou WAKAYAMA 13cd195a7e change package name.
Shirou WAKAYAMA a1c1d7b25f fix on Linux.
WAKAYAMA shirou d11680c773 fix bugs on FreeBSD.
Shirou WAKAYAMA a4671fcc2a move subdirectories. refer to issue #24