Commit Graph

282 Commits (30aff030d0edbef6c4a54172a038358405eb3829)

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>
5 years ago
Tobias Klauser 1e61ed79fa host: add support for linux/riscv64 5 years ago
Lomanic 42c6875555 [host][darwin][cgo] Fix #832 work around once-again broken go modules not including C files
Supersedes #885 by @afontaine
5 years ago
shirou a81cf97fce
Merge pull request #861 from Lomanic/issue391
[host][linux] Fix #391 retrieve sensors temps on OSes lacking hwmon
5 years ago
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.
5 years ago
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.
5 years ago
shirou f4fc0580b8
Merge pull request #802 from dmgk/master
Add support for freebsd/arm64
5 years ago
Dmitri Goutnik 270f6afc22
Add support for freebsd/arm64 5 years ago
Alessandro De Angelis b7ac341eac fix compilation warnings 5 years ago
Alessandro De Angelis 65a2e0e9bb Restored temperature info for macOS 5 years ago
Lomanic c58a1e8ec7 [host][linux] Fix #391 retrieve sensors temps on OSes lacking hwmon 6 years ago
Aman Gupta 25be4d08fe
Trim null bytes from kernel arch 6 years ago
Aman Gupta 62a406ec1b
Trim null bytes from kernel version 6 years ago
shirou 8a5bcfdb53
Merge pull request #739 from Lomanic/issue738
[host][linux] Fix #738 use uname syscall to get version in KernelVersion()
6 years ago
Lomanic 4bf185067d [host] Fix #737 add KernelArch field in InfoStat struct returning 'uname -m' result 6 years ago
Lomanic 98c779765f [host] go-fmt and propagate context on Windows in Info() 6 years ago
Lomanic 8c28c3ba17 [host][linux] Fix #738 use uname syscall to get version in KernelVersion() 6 years ago
Lomanic 9219f16f03 [host][linux] Fix #340 return Solus OS as from the "solus" PlatformFamily in Info() 6 years ago
WAKAYAMA shirou 669b2710bf [freebsd]host: change freebsd struct for 386 and arm. 6 years ago
WAKAYAMA shirou 2fd3f03f84 [freebsd][host]: fix Users() return start secs. 6 years ago
shirou a83baef6e4
Merge pull request #698 from picatz/fix-platformFamily-on-macOS
Update host_darwin.go
6 years ago
shirou 7c2ac48f84
Merge branch 'master' into td-remove-cycle 6 years ago
shirou 3d9d5e60ef
Merge pull request #688 from asnowfox/master
use /proc/buc/pci/devices to identify a VM is a guest
6 years ago
shirou d8686bcd5c
Merge pull request #675 from marcv81/fix_665_v2
Fix for #665
6 years ago
Kent 'picat' Gruber e507f44421 Update host_darwin.go
Copy+pasta got me again! 🍝

No new variable on the left of `:=` 😂
6 years ago
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.
6 years ago
Lomanic 3af6e1ffe7 [host][linux] Properly handle double quotes in /etc/os-release in PlatformInformation 6 years ago
Arturo Reuschenbach Puncernau 2a0b67d19c added sles to the suse platform family 6 years ago
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.
6 years ago
litong 6dfd8d56bb Merge branch 'master' of https://github.com/asnowfox/gopsutil 6 years ago
litong 119f26c1df use bus/pci/devices to identify a vm guest 6 years ago
Snow Fox 0cad0faa11
Merge pull request #1 from shirou/master
merge master
6 years ago
litong 12005ab922 use /proc/bus/pci/devices to idenetify a kvm guest 6 years ago
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.
6 years ago
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)
		}
	}
6 years ago
mingrammer 017c9f9cbc Fix typos 6 years ago
Lomanic 27ec6a0789 [host][linux] Remove call to sysctl binary in host/host_linux.go #639 6 years ago
Lomanic 7e9e36b568 [host][openbsd] Remove calls to sysctl binary in host/host_openbsd.go #639 6 years ago
Lomanic d110536e10 [host][darwin] Remove calls to sysctl binary in host/host_darwin.go #639 6 years ago
Lomanic 738b966ed1 [host][darwin] Use unix.Sysctl to get kernel version and platform name 6 years ago
Lomanic 8294f67566 [host][openbsd] Remove external calls to uname in PlatformInformation() 6 years ago
Pierre Souchay 890eb80501 Better comments for fallback on /etc/machine-id 6 years ago
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
6 years ago
Lomanic 18b2744df2 [host][darwin] Fix #574, use 'uname -r' in KernelVersion() 7 years ago
Ozair Jr 0bab9611d2 Adding Slackware platform information 7 years ago
Lomanic bb518e9c4e [host][windows] Remove exported wmi type from #550 7 years ago
pytimer 62fcd00c4d [host] Implement windows temperature use wmi 7 years ago
shirou 4923bd298a host: remove empty virtualzation check.
related to #547
There is an architecture which supports no virtualization.
7 years ago
Lomanic 6c4f577e6e
Merge branch 'master' into winapihost 7 years ago
Michal Rostecki 0225d9ddcc host: Check for error object 7 years ago
Lomanic 61e2d92d95 [host][windows] Query registry via golang.org/x/sys/windows instead of golang.org/x/sys/windows/registry
See https://github.com/shirou/gopsutil/pull/312#issuecomment-277422612
7 years ago
Lomanic d8a6a50129 Revert "[host][windows] Refactor code to query registry via golang.org/x/sys/windows/registry"
This reverts commit c729bbd6a8.
7 years ago
Lomanic c729bbd6a8 [host][windows] Refactor code to query registry via golang.org/x/sys/windows/registry 7 years ago
Lomanic eb11fd6e2f [host][windows] Completely remove slow wmi calls to retrieve OS version, use registry and RtlGetVersion 7 years ago
Lomanic df331c7615 [host][windows] Use win32 API to get host's uptime instead of (slow) wmi 7 years ago
shirou c95755e4bc [host]darwin: remove GPL code 7 years ago
Maddie Zhan 8c8eeb32d3 [host] linux/mips: mips64le definition from mipsle
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
7 years ago
shirou cd915bdc31
Merge pull request #508 from shirou/issue507
[host] Fix docker uptime parsing (fix #507)
7 years ago
Lomanic 1b47825dcb [host] Fix docker uptime parsing (fix #507) 7 years ago
shirou fc04d2dd9a [host]linux/mips: copy mips64 definition from mips.
It just copy from mips, so it may be corrupt, but I can not check it.
If something wrong, please open an issue.
7 years ago
shirou 145dca90f7 change to use CommandContext. 7 years ago
shirou b99342a9ce [host] fallback: implement PlatformInformation() 7 years ago
shirou ebe614f6e1 [solaris] host: add PlatformInformation() which is missing. 7 years ago
Laurie Clark-Michalek 413cb32b6c Use static initialisation for invoke instances, instead of init funcs
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.
7 years ago
linuxhe ee5d6a3d8f fix docker uptime 7 years ago
shirou d76e8c18d8
Merge pull request #496 from shirou/add_docker_to_use_btime
[host] linux: use uptime even if docker guest.
7 years ago
Steven Hartland f846eda923 Eliminate call to uname on FreeBSD
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.
7 years ago
shirou 28f7cb0d63 [host] linux: use uptime even if docker guest. 7 years ago
sada 8dd42707e2 windows: fix WithContext functions
set timeout only if parent context doesn't set.
7 years ago
CHEVY S. HUNGERFORD 29f8dfa1ad fixing SensorKey output 7 years ago
CHEVY S. HUNGERFORD 1c4fa5628c giving temperature more verbose output 7 years ago
shirou 4ac6b5b4d3 Revert "Merge pull request #470 from improbable-io/bug-darwin-build-2"
This reverts commit bb09b4e7d9, reversing
changes made to 6a368fb7cd.
7 years ago
shirou bb09b4e7d9
Merge pull request #470 from improbable-io/bug-darwin-build-2
Fix build with bazel on OSX attempt 2 (add stub for host_cgo.go)
7 years ago
Tatiana Borisova 945c2f41de Fix host_cgo file 7 years ago
Tatiana Borisova a271cb7c1c Fix package name in host_cgo.go 7 years ago
shirou a97abd3450
Merge branch 'master' into feature/add_context_support 7 years ago
shirou d1fb05a30b Skip some test if CircleCI. 7 years ago
shirou cd61c36c4f
Merge branch 'master' into feature/add_context_support 7 years ago
shirou 8b2468f1e7 Merge branch 'master' of github.com:shirou/gopsutil into feature/lxd_boot_time 7 years ago
shirou 4c73494c78 Add WithContext functions. 7 years ago
Lomanic e3ae39aa5b Fix #442, trim sensor names and properly handle CentOS in host.SensorsTemperatures() 7 years ago
Tatiana Borisova 1be443f398 Fix build attempt 3 (add stub for host_cgo.go) 7 years ago
leaf 65598d98cc To prevent hang if wmi.Query hangs, add a context-aware wrapper for it. 7 years ago
shawnps befc2c3d92 call Fatal if length of Users() is 0 7 years ago
shirou dc3a09c1d0 [host] linux: change file if in a lxc container. 8 years ago
Daniel Nelson df2f1a8dd1
Add HOST_VAR envvar and use to locate utmp on Linux. 8 years ago
Steven Hartland 6450c60b61 Eliminate use of sysctl command on FreeBSD
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.
8 years ago
Yoshio HANAWA a889bcce1a Add type definitions for mips and mipsle 8 years ago
WAKAYAMA Shirou 114c78c777 [host]: add not implemented methods. 8 years ago
WAKAYAMA Shirou 9c5b318e0d [host] windows: define Virtualization() 8 years ago
Sean Chittenden 42a72cbfae
Add HostID support to the `solaris` build target. 8 years ago
Sean Chittenden 635b971c0e
Move from the `syscall` package to the `golang.org/x/sys/{unix,windows}` 8 years ago
Frank Schroeder a9e803ef6a
Fix data race in host.BootTime 8 years ago
Shirou WAKAYAMA cdcb9bb2ed [linux] host: fix typo 8 years ago
WAKAYAMA Shirou 25d50d5bc3 [linux]host: change to use filepath.Join 8 years ago
WAKAYAMA Shirou dfbb3e40da fix build bugs. 8 years ago
Shirou WAKAYAMA fee973abda [linux]host: fix HostTempreture func 8 years ago
shirou 8e36fe6d8f Merge pull request #334 from dotpy3/macos-linux-temperatures
Added temperatures sensors for macOS and Linux
8 years ago
WAKAYAMA Shirou e49a95f3d5 [host]darwin: PlatformInformation has been 5 values other is 4. 8 years ago
itnihao 490dbd4ea4 Add hostinfo Virtualization vmware 8 years ago
Eric Gourlaouen 22aefb460a Replaced sys by HostSys
Added TemperatureStat string test
8 years ago
Eric Gourlaouen 8b08ca5fdc added temperatures 8 years ago
WAKAYAMA Shirou f8ef680a47 error strings change to lowercase 8 years ago
James Nugent 408005be94 host: Add Solaris support for Info, {Boot,Up}time
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`.
8 years ago
shirou 23f4b7eb14 Merge pull request #323 from molecul/patch-2
Fix for getMachineGuid() return value
8 years ago
Shirou WAKAYAMA 85d3530ae8 fix test. 8 years ago
Alexey Galkin b1f19a76c7 Fix for getMachineGuid() return value
getMachineGuid() function return a empty value in x86 windows builds.
Issue: https://github.com/shirou/gopsutil/issues/322
8 years ago
Alexey Galkin 2287b035c8 Add new test 'TestHostGuid'
For issue: https://github.com/shirou/gopsutil/issues/322
8 years ago
tycho garen 22c56d292e close open files 8 years ago
Sean Chittenden 36f5033d97
Unconditionally lowercase the `HostID` from all supported platforms. 8 years ago
Sean Chittenden 650c4d595f
Use `HKLM/SOFTWARE\Microsoft\Cryptography`'s `MachineGuid` registry key to enable `HostID` support on Windows. 8 years ago
Cameron Sparr a213bf5e6d
run go fmt ./... 8 years ago
Sean Chittenden 955821b5ab
Add Go-native structs for Darwin/386 and FreeBSD/arm 8 years ago
Sam Kleinman 488c56586b add platform compatibility 8 years ago
shirou a2257218e1 Merge pull request #289 from DataDog/conor/cache-boot-time
Cache the boot time after first query.
8 years ago
Marco Pfatschbacher b4846b445b Add support for OpenBSD/amd64
This code is based on the FreeBSD version
and implements roughly the same feature set.
8 years ago
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.
9 years ago
Shirou WAKAYAMA b9067179ef [host]darwin: change to use sw_vers to get platform version 9 years ago
shirou a8e24d70f9 Merge pull request #247 from lfittl/fallback-for-unsupported-architectures
Add fallback code for all unsupported operating systems
9 years ago
Lukas Fittl da9fa1162b Add fallback code for all unsupported operating systems.
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.
9 years ago
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.
9 years ago
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.
9 years ago
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.
9 years ago
Sean Chittenden 4f79984afe
Remove redefined import name for common. 9 years ago
Sean Chittenden a3f57b1314
Resolve cyclic import and create a common helper func, NumProcs() 9 years ago
Sean Chittenden fcd296ea11
Merge branch 'master' of github.com:shirou/gopsutil 9 years ago
Sean Chittenden 69f7f8eaeb
Update host.Info() to return the number of processes on all platforms.
Fixes: #227
9 years ago
Shirou WAKAYAMA dd9b50926c [host]linux: add coreos to Info() and Virtualization(). 9 years ago
WAKAYAMA Shirou 53406b2832 [host]Windows: BootTime and Uptime are reversed on Windows. 9 years ago
Shirou WAKAYAMA e9afb36ccf [host] linux: detect docker and rkt correctly 9 years ago
Shirou WAKAYAMA c0d1185809 [host]linux: add alpine linux to detect host.Info(). 9 years ago
Shirou WAKAYAMA 57f6aebc7e add Timeout to invoke command and use common.Invoke refs: #201 9 years ago
Johannes 'fish' Ziemke 2a69690d62 Add type definitions for arm64 and ppc64le 9 years ago
WAKAYAMA shirou e864f2a037 [disk]freebsd: update 386. 9 years ago
WAKAYAMA shirou 01832c6a58 [host]freebsd: add freebsd_386. 9 years ago
WAKAYAMA shirou d9e994bec8 [host]freebsd: update freebsd_amd64 9 years ago
Shirou WAKAYAMA ce98590a35 [host]linux: forgot to add sizeOfUtmp. 9 years ago
Shirou WAKAYAMA 15ff7e19df [host]linux: fix i386 and gofmt. 9 years ago
Shirou WAKAYAMA b1df5a912c [host]linux: type file changed. 9 years ago
Shirou WAKAYAMA 0787e8ba3e [host]linux-arm: update type_liux.go. Test will fail. 9 years ago
Shirou WAKAYAMA bce9212def fix build bugs. 9 years ago
Shirou WAKAYAMA d21ed2b40d search path via exec.LookPath before actual invoke. 9 years ago
Shirou WAKAYAMA 4bb84648bf JSON representation is renamed to fit Google JSON style, camelCase. 9 years ago
Shirou WAKAYAMA ea152ea901 [BREAKING CHANGE] rename functions to pass golint. ex) net.NetIOCounters -> net.IOCounters 9 years ago
Shirou WAKAYAMA fa3e1cc196 [common]linux: add HostEtc to switch '/etc' See #175. 9 years ago
Robin Burchell 55cacb4730 host_darwin: Use a named constant for USER_PROCESS.
Matches the host_linux change.
9 years ago
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}
9 years ago
Paul Querna 008f2b4e18 Get Arch Linux Version from LSB 9 years ago
WAKAYAMA shirou 54a6c186c1 host[freebsd]: BREAKING CHANGE. Boottime() should return uint64 same as other. 9 years ago
Shirou WAKAYAMA 0afd653fab host[all]: fix #114 String() issue. 9 years ago