Commit Graph

182 Commits

Author SHA1 Message Date
Tobias Klauser 28890b0482 Use common implementation for BootTime/Uptime on all BSDs
All BSDs use the same implementation to get BootTime{,WithContext} and
Uptime{,WithContext} based on the kern.boottime sysctl. Move this
implementation to a separate host/host_bsd.go file shared by darwin,
freebsd and openbsd. Also use SysctlTimeval to get
the boot time directly as a type Timeval instead of manually
extracting it using package unsafe. It will also allow for easier reuse
to support package host on e.g. Dragonfly BSD or NetBSD.

This requires updating the golang.org/x/sys/unix dependency to the
latest revision.

Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
2020-07-23 13:23:20 +02:00
Tobias Klauser 1e61ed79fa host: add support for linux/riscv64 2020-06-30 11:34:17 +02:00
Lomanic 42c6875555 [host][darwin][cgo] Fix #832 work around once-again broken go modules not including C files
Supersedes #885 by @afontaine
2020-05-31 20:40:36 +02:00
shirou a81cf97fce
Merge pull request #861 from Lomanic/issue391
[host][linux] Fix #391 retrieve sensors temps on OSes lacking hwmon
2020-05-01 22:02:23 +09:00
Tobias Klauser 7bee6a934d host: fix TestHostInfoStat_String
TestHostInfoStat_String has been broken since kernelArch has been
introduced. Fix it.

Also adjust the error message to show the wanted string, aligned with
the gotten string so it's easier to spot differences.
2020-02-13 14:41:11 +01:00
Tim Gross c69ef749eb fix host.Info() panic if /etc/debian_version is empty
The ReadLines helper function doesn't guarantee that the length of
lines is non-zero or that the lines have contents. Most callers
include a check for length but this was missing for version
fingerprinting on Debian if `/etc/debian_version` was empty, leading
to a panic.
2020-01-17 14:23:27 -05:00
shirou f4fc0580b8
Merge pull request #802 from dmgk/master
Add support for freebsd/arm64
2019-12-21 10:01:17 +09:00
Dmitri Goutnik 270f6afc22
Add support for freebsd/arm64 2019-12-17 03:12:29 -05:00
Alessandro De Angelis b7ac341eac fix compilation warnings 2019-12-16 11:24:55 +01:00
Alessandro De Angelis 65a2e0e9bb Restored temperature info for macOS 2019-12-13 16:03:44 +01:00
Lomanic c58a1e8ec7 [host][linux] Fix #391 retrieve sensors temps on OSes lacking hwmon 2019-08-18 20:48:31 +02:00
Aman Gupta 25be4d08fe
Trim null bytes from kernel arch 2019-08-12 13:32:14 -07:00
Aman Gupta 62a406ec1b
Trim null bytes from kernel version 2019-08-12 13:30:54 -07:00
shirou 8a5bcfdb53
Merge pull request #739 from Lomanic/issue738
[host][linux] Fix #738 use uname syscall to get version in KernelVersion()
2019-08-11 21:57:14 +09:00
Lomanic 4bf185067d [host] Fix #737 add KernelArch field in InfoStat struct returning 'uname -m' result 2019-08-08 23:11:41 +02:00
Lomanic 98c779765f [host] go-fmt and propagate context on Windows in Info() 2019-08-07 22:34:36 +02:00
Lomanic 8c28c3ba17 [host][linux] Fix #738 use uname syscall to get version in KernelVersion() 2019-08-03 18:36:36 +02:00
Lomanic 9219f16f03 [host][linux] Fix #340 return Solus OS as from the "solus" PlatformFamily in Info() 2019-07-11 22:18:40 +02:00
WAKAYAMA shirou 669b2710bf [freebsd]host: change freebsd struct for 386 and arm. 2019-07-06 23:49:57 +09:00
WAKAYAMA shirou 2fd3f03f84 [freebsd][host]: fix Users() return start secs. 2019-07-06 23:45:22 +09:00
shirou a83baef6e4
Merge pull request #698 from picatz/fix-platformFamily-on-macOS
Update host_darwin.go
2019-06-04 23:58:34 +09:00
shirou 7c2ac48f84
Merge branch 'master' into td-remove-cycle 2019-06-01 11:26:59 +09:00
shirou 3d9d5e60ef
Merge pull request #688 from asnowfox/master
use /proc/buc/pci/devices to identify a VM is a guest
2019-06-01 11:18:40 +09:00
shirou d8686bcd5c
Merge pull request #675 from marcv81/fix_665_v2
Fix for #665
2019-06-01 10:28:14 +09:00
Kent 'picat' Gruber e507f44421 Update host_darwin.go
Copy+pasta got me again! 🍝

No new variable on the left of `:=` 😂
2019-05-31 13:19:04 -04:00
Kent 'picat' Gruber d13ba02ef0 Update host_darwin.go
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.
2019-05-31 13:13:06 -04:00
Lomanic 3af6e1ffe7 [host][linux] Properly handle double quotes in /etc/os-release in PlatformInformation 2019-05-31 18:04:45 +02:00
Arturo Reuschenbach Puncernau 2a0b67d19c added sles to the suse platform family 2019-05-24 11:33:07 +02:00
Tyler Dixon a02925055c Remove cycle between process and host packages
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.
2019-05-22 17:45:50 -07:00
litong 6dfd8d56bb Merge branch 'master' of https://github.com/asnowfox/gopsutil 2019-05-22 11:02:14 +08:00
litong 119f26c1df use bus/pci/devices to identify a vm guest 2019-05-22 11:01:09 +08:00
Snow Fox 0cad0faa11
Merge pull request #1 from shirou/master
merge master
2019-05-22 10:46:50 +08:00
litong 12005ab922 use /proc/bus/pci/devices to idenetify a kvm guest 2019-05-06 07:18:49 +08:00
Segflow 86c7289ccc Fix: use filename in exec.LookPath instead of full path
exec.LookPath searches for the file in the $PATH, which mean giving it an absolute path is against it's own purposes.
2019-05-05 20:45:07 +01:00
Marc 174b31f146 Fix for #665
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)
		}
	}
2019-04-26 23:15:23 +08:00
mingrammer 017c9f9cbc Fix typos 2019-03-18 02:52:26 +09:00
Lomanic 27ec6a0789 [host][linux] Remove call to sysctl binary in host/host_linux.go #639 2019-03-02 23:22:53 +01:00
Lomanic 7e9e36b568 [host][openbsd] Remove calls to sysctl binary in host/host_openbsd.go #639 2019-03-02 23:22:53 +01:00
Lomanic d110536e10 [host][darwin] Remove calls to sysctl binary in host/host_darwin.go #639 2019-03-02 23:22:53 +01:00
Lomanic 738b966ed1 [host][darwin] Use unix.Sysctl to get kernel version and platform name 2018-12-29 14:59:17 +01:00
Lomanic 8294f67566 [host][openbsd] Remove external calls to uname in PlatformInformation() 2018-12-29 14:56:23 +01:00
Pierre Souchay 890eb80501 Better comments for fallback on /etc/machine-id 2018-11-07 00:09:22 +01:00
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
2018-11-06 18:06:40 +01:00
Lomanic 18b2744df2 [host][darwin] Fix #574, use 'uname -r' in KernelVersion() 2018-09-01 17:23:39 +02:00
Ozair Jr 0bab9611d2 Adding Slackware platform information 2018-07-25 10:17:08 -03:00
Lomanic bb518e9c4e [host][windows] Remove exported wmi type from #550 2018-07-14 18:52:10 +02:00
pytimer 62fcd00c4d [host] Implement windows temperature use wmi 2018-07-09 15:21:26 +08:00
shirou 4923bd298a host: remove empty virtualzation check.
related to #547
There is an architecture which supports no virtualization.
2018-07-05 21:54:46 +09:00
Lomanic 6c4f577e6e
Merge branch 'master' into winapihost 2018-06-23 16:44:14 +02:00
Michal Rostecki 0225d9ddcc host: Check for error object 2018-06-21 16:58:40 +02:00