Commit Graph

157 Commits

Author SHA1 Message Date
Adam Medzinski 22f3299fd7
Add missing doc for cpu.TimesStat structure 2017-11-27 12:17:18 +01:00
leaf 65598d98cc To prevent hang if wmi.Query hangs, add a context-aware wrapper for it. 2017-11-20 10:13:27 -08:00
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.
2017-10-05 08:45:56 +01:00
WAKAYAMA Shirou 4c9fd1f200 [cpu]linux: add testcode with testdata. 2017-09-20 15:58:30 +09:00
HeChuan c818f7b647 set win cpu total name to "cpu-total"
set the name of windows cpu total percent to "cpu-total"
keep the same with Linux, Freebsd system
2017-07-20 11:47:15 +08:00
Andrew Danforth 484470889f Only read /proc/stat once when cpu.Times(true) is called on Linux 2017-06-09 22:34:58 -04:00
shirou 3dd8bd46d9 Merge pull request #376 from ContinuumLLC/win_percpu_feature
Windows: Read processor performance metrics overall, per cpu and per core
2017-06-05 22:30:45 +09:00
Rajkumar Gupta b657e83fed Added comments for structs and functions 2017-06-05 15:46:35 +05:30
Rajkumar Gupta 2d2db4203f Change to adapt current cpu.Times API for per cpu and core time stats 2017-06-05 14:18:20 +05:30
Sean Chittenden 635b971c0e
Move from the `syscall` package to the `golang.org/x/sys/{unix,windows}` 2017-06-02 13:51:00 -07:00
Rajkumar Gupta ea683cd370 Read processor performance metrics per cpu and per core 2017-05-25 17:54:43 +05:30
WAKAYAMA shirou b6da2bd76e [freebsd] cpu: fix CPUInfo on 10.3R
Related: #307
2017-05-10 11:47:26 +09:00
WAKAYAMA Shirou dfbb3e40da fix build bugs. 2017-04-10 22:24:36 +09:00
Jakob Gillich facb241c12 clarify return value of cpu.Percent() 2017-03-31 16:07:44 +02:00
WAKAYAMA Shirou 3499dec5c0 [cpu]linux: handle hz values by tmm1 2017-03-23 21:36:54 +09:00
WAKAYAMA Shirou a63f1aeeec use Processor entry as model name fallback by @tmm1 2017-03-23 21:35:50 +09:00
WAKAYAMA Shirou 36b408780c cpu[linux]: ignore cpufreq/cpuinfo_max_freq error 2017-03-21 00:55:21 +09:00
WAKAYAMA Shirou bad1ce0748 fix typo 2017-03-15 23:32:55 +09:00
WAKAYAMA Shirou 30ebb9ca3a rename expected dir to testdata. 2017-03-15 23:01:06 +09:00
WAKAYAMA Shirou f8ef680a47 error strings change to lowercase 2017-03-15 22:43:20 +09:00
shirou d4c8874c19 Merge pull request #328 from jen20/solaris-cpu
cpu: Implement Solaris support for Info()
2017-03-14 01:51:04 +09:00
James Nugent 49ed700c0d cpu: Implement Solaris support for Info()
This commit adds Solaris(^1) support for the Info() function of package
cpu, with the exception of the L2 cache size which is not trivially
available(^2).

Support is implemented by parsing the output of `isainfo -b -v` (for the
instruction set flags), and `psr-info -p -v` for other information.
Example outputs from a range of different size VMs and Joyent containers
are included as part of the tests.

(^1): This has only been tested with Illumos in the form of SmartOS. I
believe it to be portable to other Illumos distributions but have not
tested on Oracle Solaris.

(^2): Enough support is added here to be usable for my port of
HashiCorp's Nomad to SmartOS.
2017-03-12 21:19:42 -05:00
Simarpreet Singh 5a4c90ad5f cpu: Expose CPU microcode information
This commit exposes the CPU microcode information.

Signed-off-by: Simarpreet Singh <simar@opendns.com>
2017-03-07 16:18:20 -08:00
Sam Kleinman 915d1e930e fix panic in starvation situations 2017-02-15 11:25:49 -05:00
shirou 77b5d0080a Merge pull request #311 from sparrc/cpu-times-panic
fix panic when /proc/stat is empty
2017-02-02 09:16:45 +09:00
Cameron Sparr 0c9a1d33cb
fix panic when /proc/stat is empty
don't really know why this would be the case, but I suppose there are
always edge-cases.

see https://github.com/influxdata/telegraf/issues/2356
2017-02-01 23:13:59 +00:00
Cameron Sparr a213bf5e6d
run go fmt ./... 2017-02-01 23:05:29 +00:00
WAKAYAMA shirou dc8102185d separate freebsd specific test code. 2017-01-29 01:43:24 +09:00
WAKAYAMA shirou a54f700f00 fix test other than freebsd. 2017-01-29 01:38:52 +09:00
WAKAYAMA shirou eb5bfca902 [cpu]freebsd: cpu.Info() now returns CPUInfos same number as CPU nums. 2017-01-29 01:23:21 +09:00
WAKAYAMA shirou 7783018b9d [cpu]freebsd: CPU.CPU now indicates CPU num instead of MHz. 2017-01-22 22:31:05 +09:00
Marco Pfatschbacher b4846b445b Add support for OpenBSD/amd64
This code is based on the FreeBSD version
and implements roughly the same feature set.
2016-11-24 22:30:29 +01:00
Shirou WAKAYAMA ae251eb6a2 cpu[darwin]: fix Go arrays panic in cgo #279 2016-11-15 00:53:20 +09:00
Breno Leitao 286927a039 Improve CPU identification for POWER processors
Currently gopsutils fails to indentify the POWER processors family,
returning an almost empty Info() structure.

This patch improves the POWER identification without changing what is
available for x86.
2016-10-24 14:11:12 -04:00
Andreas Henriksson 9d51bfe3bb Allow clock field in /proc/cpuinfo as cpu MHz fallback value
Needed on ppc64le debian porter boxes atleast.

See #230
2016-10-14 14:05:32 +02:00
Hilko Bengen 832dcb96c8 cpu.Percent (Windows): Use the same implementation as on Unix
WMI is way too slow.
2016-09-27 18:15:05 +02:00
K.C. Wong 3dc4e52844 Handle the case when the `cpufreq` sysfs does not exist
* on virtualized host, this may happen.
* but we may have a value from parsing `/proc/cpuinfo`
* in this case, we do not return the error if we fail to extra
  a value from `cpufreq/cpuinfo_max_freq`
2016-08-29 16:21:17 -07:00
K.C. Wong 10a1ae2123 Standardize `Mhz` to mean maximum CPU frequency on Linux platform
* resolve #249
* in `cpu_windows.go`, `Mhz` is the value of `MaxClockSpeed`
* on Linux platform, the `Mhz` value is extracted from `/proc/cpuinfo`
  which reflects the current clock speed; treat this as the fallback
  value instead
* read from `cpufreq/cpuinfo_max_freq` under sysfs to get the
  maximum clock speed for `Mhz`, just like for Windows platform
* also fix the path to `cpu.CoreID` value; the filename is `core_id`
2016-08-29 10:11:30 -07:00
shirou a8e24d70f9 Merge pull request #247 from lfittl/fallback-for-unsupported-architectures
Add fallback code for all unsupported operating systems
2016-08-27 00:58:16 +09:00
K.C. Wong 123a6c9b0d Addressing frequency unit discrepancies
* for Darwin, it is a minor tweak for readability: the value
  returned is in Hz, so using a variable named 'hz' makes more
  sense than 'mhz'
* for Linux, the unit is in kHz so we need to divide the value
  from `cpuinfo_max_freq` by 10^3 to get MHz (see
  cpu-freq/user-guide.txt of the kernel documentation)
2016-08-23 17:21:30 -07:00
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.
2016-08-22 15:31:26 -07:00
Lukas Fittl 74541ba4a5 CPU: Fix linter warning on OSX. 2016-08-22 14:20:29 -07:00
shirou 5c1bfed855 Merge pull request #219 from sean-/freebsd-cpu-info
Improve FreeBSD's CPU InfoStat collection
2016-06-17 17:26:08 +09:00
Sean Chittenden 14b2ce8b81
Don't be lossy re: CPU model number. 2016-06-16 19:32:49 -07:00
Sean Chittenden 606680edc5
Improve the accuracy of CPU detection on FreeBSD. 2016-06-16 19:25:27 -07:00
Ben Aldrich 9dbebcf46e rename ALL to all 2016-06-01 16:03:11 -06:00
Ben Aldrich a76195e088 fixed imports and spelling error 2016-06-01 15:53:54 -06:00
Ben Aldrich c36f7ac8b0 rename var 2016-06-01 15:45:29 -06:00
Ben Aldrich fcc1747d9f Merge branch 'master' of https://github.com/shirou/gopsutil into calc_cpu_percent
Conflicts:
	cpu/cpu.go
2016-06-01 15:24:23 -06:00
Ben Aldrich c389989453 calculate cpu percentage compared to last call if 0 interval is given 2016-06-01 15:21:58 -06:00
Sean Chittenden d2ca7e8d2c
Remove redundant build tag 2016-05-20 10:04:58 -04:00
Shirou WAKAYAMA 57f6aebc7e add Timeout to invoke command and use common.Invoke refs: #201 2016-05-20 17:59:41 +09:00
Aaron Zinman 4041e7d31e Fix compile errors for iOS/arm64
- Added conditional preprocessor guard on cpu_darwin_cgo.go

- Duplicated disk_darwin_amd64 for arm64 (after confirming
that sys/mount.h are the same between the two platforms, hence the
constants should be valid).
2016-05-10 12:27:10 -07:00
Shirou WAKAYAMA 5daf090513 [cpu]linux: vendorId in cpuinfo is sometimes vendor_id. 2016-04-12 23:08:13 +09:00
Shirou WAKAYAMA bce9212def fix build bugs. 2016-04-01 22:22:03 +09:00
Shirou WAKAYAMA d21ed2b40d search path via exec.LookPath before actual invoke. 2016-04-01 22:13:05 +09:00
Shirou WAKAYAMA 613a8a90e1 fixed by golint. 2016-04-01 21:34:39 +09:00
Shirou WAKAYAMA 4bb84648bf JSON representation is renamed to fit Google JSON style, camelCase. 2016-03-23 10:52:46 +09:00
Shirou WAKAYAMA ea152ea901 [BREAKING CHANGE] rename functions to pass golint. ex) net.NetIOCounters -> net.IOCounters 2016-03-22 23:09:12 +09:00
Shirou WAKAYAMA 7f22150707 CPU num is different on the CircleCI environemnt, so we skip it. 2016-02-12 22:44:17 +09:00
Johan Walles ebaa641e63 Make a public function for computing total CPU time
This function used to be a private part of process.go.

Since I needed that functionality however I think it's better to make it public
than for me to copy it into my own code.

As a side effect of this change, I also fixed a bug in the function where Stolen
was not part of the sum. Having the function close to the CPUTimesStat
declaration will make problems like this less likely to re-occur in the future.
2016-02-10 17:53:39 +01:00
Ryan J. O'Neil 4d7275adf7 Rebrandoning back. 2015-12-15 16:19:20 -05:00
Ryan J. O'Neil 2434a327b9 Removing race condition in CPUPercent calculation. 2015-12-15 15:22:30 -05:00
Ryan J. O'Neil 1b9883dc76 Rebrandoning so we can patch this library and have it work in our Godeps. 2015-12-15 14:51:35 -05:00
Daniel Theophanes fa7f8ba4e8 cpu: CPUInfo returns one item per physical thread. Fix "Cores" to 1 on Linux.
Fixes #104
2015-10-22 09:43:45 -07:00
Daniel Theophanes bc6481f7e0 Merge branch 'master' of https://github.com/shirou/gopsutil into cpu_test 2015-10-19 08:46:06 -07:00
Shirou WAKAYAMA 7288e9a5af common[all]: add internal 2015-10-20 00:04:57 +09:00
Daniel Theophanes 726e7c6406 cpu: fix cpu test on small ARM device where CPU can be at 100%+rounding.
Fixes #99
2015-10-18 20:53:01 -07:00
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
2015-10-18 20:40:01 -07:00
Daniel Theophanes 69221741e8 cpu: allow override of /sys dir. Fix CPUInfo /proc + cpuinfo combine. 2015-10-18 09:46:21 -07:00
Daniel Theophanes ab2cba55ee Merge branch 'master' of https://github.com/shirou/gopsutil into cpu_arm 2015-10-18 09:29:54 -07:00
Daniel Theophanes 9f2e6a74cc cpu: support ARM CPUs.
ARM CPUs don't include the same fields as  x86 and amd64 CPUs in
the /proc/cpuinfo list. Pull information from the /sys/...
device tree as well as updating when a CPU is done in cpuinfo.

Fixes #88
2015-10-17 12:25:18 -07:00
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.
2015-10-17 11:34:41 -06:00
Shirou WAKAYAMA a95dde9672 cpu[darwin]: separetes cpu_darwin to cgo and nocgo to get CPUTimes. 2015-10-10 22:13:38 +09:00
Ben Aldrich a4ec4177a6 Fix cpu percent on windows
Tested on windows 7:

When divided by 100 you get cpu percentage of  %0.14 when task manager shows %14. Once this is removed they match.
2015-09-04 18:48:20 -06:00
WAKAYAMA Shirou 4696985e84 cpu[windows]: skip if could not get cpu.LoadPercentage. 2015-09-03 21:48:18 +09:00
Shirou WAKAYAMA 47f6760cf3 cpu[darwin]: use CGO to get CPUTimes. This is breaking. see #66. 2015-08-28 17:01:43 +09:00
shirou 3c958a8ee6 Merge pull request #60 from mayowa/master
Bug fix and HostStatInfo.Platform* windows implementation
2015-08-28 16:26:02 +09:00
mayowa 6fa0704dbf fixed: ProcessorId doesnt return a value 2015-08-28 06:56:05 +01:00
Shirou WAKAYAMA 0d7ff2eb40 cpu[darwin]: convert cpu frequency to Mhz. 2015-08-27 15:50:35 +09:00
Chris Bednarski d5fa4f880f Read Darwin CPU frequency from sysctl hw.cpufrequency 2015-08-26 11:45:09 -07:00
mayowa 7889ce3e03 changed ProccessorId type to *string, cause wmi sometimes returns nil for it 2015-08-25 22:21:10 -07:00
mayowa 6a2bc5afe8 removed l2CacheSize as its not present in all wmi databases 2015-08-25 22:08:35 -07:00
Shirou WAKAYAMA cbe10d6761 cpu[darwin]: move helper path to under the HOME dir. 2015-07-29 22:25:42 +09:00
Shirou WAKAYAMA c195d77ce3 cpu[darwin]: enable cpu helper only the environemnetal variable set. 2015-07-25 12:49:02 +09:00
Shirou WAKAYAMA 755d3a4119 cpu[darwin]: change default tick to 100. 2015-07-24 15:01:22 +09:00
Shirou WAKAYAMA 12843632ca cpu[darwin]: experimental implemtation to get CPU times on darwin. 2015-07-24 14:49:35 +09:00
Shirou WAKAYAMA 5854011870 cpu: Steal, Guest, and GuestNice are not divided by CPU_TICK. 2015-07-17 22:11:30 +09:00
WAKAYAMA shirou 4bc631921f cpu: fix command output trim problem. 2015-07-17 21:52:43 +09:00
Shirou WAKAYAMA 8c17a750c6 get CLOCK TICK by using getconf. 2015-07-17 21:46:26 +09:00
gwind a750762737 Fix interpretation error about /proc/stat 2015-07-15 16:20:12 +08:00
WAKAYAMA shirou 64357f04e7 use StackExchange/wmi instead of invoking wmic process.
Note: This may not work on some old Windows XP.
2015-04-20 00:05:31 +09:00
WAKAYAMA Shirou 5f8b99aa65 windows: GetWmic returns [][]string where string split by "," 2015-03-20 22:48:58 +09:00
Shirou WAKAYAMA 170390c0df cpu: fix build option on unix. 2015-03-11 23:06:00 +09:00
WAKAYAMA Shirou ead8393137 cpu: use wmic to get CPU usage on Windows. 2015-03-11 23:00:06 +09:00
WAKAYAMA Shirou ec2b509dda cpu: skip percpu percent test if windows. Windows can only get one CPU info currently. 2015-03-07 21:52:43 +09:00
WAKAYAMA Shirou 4694ce0e4d cpu: use wmic to get CPUInfo on Windows 2015-02-15 21:25:33 +09:00
WAKAYAMA shirou b8dc51929a forget to change float32 to float64 2015-02-15 20:48:29 +09:00
Shirou WAKAYAMA 753ea1bb48 fix when converting CPUTimes to JSON, sometimes idel have exponent 2015-02-13 23:11:27 +09:00
Shirou WAKAYAMA 4b5bf22b88 change CPUTimes type from float32 to float64 to resolve precision issue. 2015-02-13 22:45:12 +09:00