Commit Graph

126 Commits

Author SHA1 Message Date
Lomanic ccc1c1016b [mem][darwin] Fix #622 include Inactive memory in total calculation in TestVirtual_memory 2018-12-25 21:55:58 +01:00
Minje Park f9e238c38b SReclaimable should be added to Cached Memory 2018-12-14 00:48:38 +09:00
Isida Zyun'iti bd7b2f8148 Add mem(laundry) numbers on FreeBSD.
After FreeBSD 11.1, mem number of cached replaced by laundry.

https://reviews.freebsd.org/D8302
2018-08-08 19:54:18 +09:00
Isida Zyun'iti 48da6ade9e Fix FreeBSD total memory.
Like this.
FreeBSD: fix total memory giampaolo/psutil@bd9a58b bd9a58b2af
2018-08-07 10:42:15 +00:00
Lomanic 6b586d2fcd [mem][windows] Fix TestVirtual_memory test 2018-07-19 00:19:02 +02:00
shirou 6b48f3bd01 [mem] fix test. 2018-07-13 23:34:38 +09:00
Arnaud Rebillout 558a95bf02 Fix TestVirtual_memory #552
Based on https://stackoverflow.com/a/30772733/776208

Signed-off-by: Arnaud Rebillout <arnaud.rebillout@collabora.com>
2018-07-12 13:05:28 +07:00
shirou 9937d4109d mem[linux]: fix test. 2018-06-23 23:38:51 +09:00
Shrug 42 6a38ce2069 fix json tags 2018-06-20 10:20:54 -07:00
Shrug 42 12fad953c1 added additional linux meminfo fields 2018-06-19 13:12:33 -07:00
Steven Lee 3adcafe5fd mem[windows]: if no swap, just return 0 used percent default 2018-05-19 10:45:38 +08:00
shirou 0f1576d63c mem[windows]: if no swap, total and/or used is 0. 2018-05-19 09:25:20 +09:00
Daniel Nelson 28b1d7477e
Use uint64 when retrieving vfs.bufspace
On some system using a the uint32 function would return the error
"cannot allocate memory".
2018-04-12 15:33:51 -07:00
shirou 145dca90f7 change to use CommandContext. 2018-03-31 21:35:53 +09:00
shirou c3f470a77a
Merge pull request #504 from dimrozakis/linux-used-mem
Always calculate linux used mem as total-(free+buffered+cache)
2018-03-28 11:00:28 +09:00
shirou 1ba5059aca [memory] Linux: add document url about OverCommiting. 2018-03-28 10:57:05 +09:00
shirou a1564d2e89
Merge pull request #478 from DataDog/olivielpeau/commit-vm-stats
[mem] Add commit-related stats to VirtualMemoryStat on Linux
2018-03-28 10:49:09 +09:00
Dimitris Rozakis 4510db20db Always calculate linux used mem as total-(free+buffered+cache)
Used memory was calculated as Total - Available.
For newer kernels (3.14+), available memory is taken from /proc/meminfo,
whereas for older kernels it is computed as free+buffered+cached.

This commit changes that behavior. Available memory is still taken from
/proc/meminfo, if available, but used memory is always computed as
total-free-buffered-cached.

This way, it matches the output of `free` for used memory (in the -/+
buffers/cache line) and other tools.

Prior to this change, I'd see a reported used memory of 600MiB whereas
free, htop and other tools would report a used memory of 1.8GiB. And
adding used, cached, buffered and free memory would leave ~1.2GiB
unaccounted for.
2018-03-26 21:38:02 +03:00
Chevy 699deed6c6
Fix float64 casting 2018-03-26 12:16:33 -05:00
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.
2018-03-21 14:08:39 +00:00
Steven Hartland d968f63e51 Eliminate call to swapinfo on FreeBSD
Improve performance by eliminating the fork out to swapinfo on FreeBSD which also helps prevent crashes / hangs due to the outstanding fork crash bug:
golang/go#15658

This also fixes the value reported by SwapMemory and SwapMemoryWithContext on FreeBSD which previously only included the first swap device and also reported the values in terms of 1K blocks instead of bytes.
2018-03-11 22:15:22 +00:00
shirou 4c73494c78 Add WithContext functions. 2017-12-31 15:25:49 +09:00
Olivier Vielpeau 5b52fbbea5 [mem] Add commit-related stats to VirtualMemoryStat on Linux 2017-12-26 16:24:10 +01: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
Derek Brown 7c807c86e4 Add implementation of SwapMemory() for windows 2017-09-18 18:14:29 -07:00
Sean Chittenden 635b971c0e
Move from the `syscall` package to the `golang.org/x/sys/{unix,windows}` 2017-06-02 13:51:00 -07:00
WAKAYAMA Shirou f8ef680a47 error strings change to lowercase 2017-03-15 22:43:20 +09:00
James Nugent d19ac24a84 mem: Skip TestVirtual_memory on Solaris 2017-03-15 08:10:23 -05:00
James Nugent b7760bb5a6 memory: Add basic Solaris VirtualMemory() support
This commit adds support for VirtualMemory() in package mem. The support
only extends to total memory capcity, since that is all that is required
in Nomad. It does take into account global versus non-global zones, and
does not use cgo.

This has been tested inside a zone in the Joyent public cloud for a
non-global zone, and in the global zone of a SmartOS virtual machine.
2017-03-14 16:28:50 -05:00
Cameron Sparr a213bf5e6d
run go fmt ./... 2017-02-01 23:05:29 +00:00
WAKAYAMA Shirou 1123132e5a [mem]darwin: swap memory was Kbytes, since linux is bytes. 2017-01-17 22:38:46 +09:00
Maxime Mouial 4a1d5da977 Add 'SwapCached' to the VirtualMemoryStat informations on linux 2016-12-21 15:42:09 +01:00
Maxime Mouial 44e27c6972 Add Slab, Shared and PageTables metric for VirtualMemory under linux 2016-12-19 14:01:27 +01: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
Luca Berruti 36f47562c0 Fix: wrong swap values on i686 / 4GB ram.
According to sysinfo manpages: swap fields need to be interpreted along
with the mem_unit (Unit) field.

See also http://stackoverflow.com/a/4229727
2016-09-04 12:39:34 +02: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
kthommandra 1fd3a4dbad Added the writeback, dirty and writebacktmp fields from /proc/meminfo on Linux 2016-08-16 05:13:14 -07:00
Shirou WAKAYAMA 57f6aebc7e add Timeout to invoke command and use common.Invoke refs: #201 2016-05-20 17:59:41 +09:00
Shirou WAKAYAMA adf2f03a48 fix build and path error 2016-04-01 22:28:07 +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
Johan Walles dd875d4970 Fix memory stats on Darwin, non-CGO 2016-02-22 07:29:15 +01:00
Johan Walles d109284df3 Fix memory stats on Darwin, CGO 2016-02-22 07:28:55 +01:00
Johan Walles 27093ae2d2 mem_darwin_test.go: Compare `total` to `sysctl hw.memsize` 2016-02-22 07:28:55 +01:00
Johan Walles 0d5592714b Fix memory stats on LinuxFreeBSD 2016-02-22 07:28:44 +01:00
Johan Walles 66a07939f7 Fix memory stats on Linux 2016-02-21 20:56:11 +01:00
Johan Walles 4438159155 Document + add tests for for mem.VirtualMemory()
This change changes and documents the (previously undocumented) behavior of Used
to "RAM used by programs".

We also remove the undocumented and unused Shared field of that struct.

So with this change in place, the VirtualMemoryStruct contains:
* three human-consumable fields for Total, Used and Available memory
* one human-consumable UsedPercentage field
* a number of kernel specific fields
2016-02-21 20:56:11 +01:00
Johan Walles 44f817eb8d Split mem_darwin.go into CGO and non CGO variants 2016-02-20 21:49:23 +01:00
Johan Walles 00504a37e3 Remove unused import 2016-02-19 23:39:00 +01:00
Johan Walles a6cd6f803b Use Go's built in syscall.Getpagesize() 2016-02-19 23:37:43 +01:00
Johan Walles 13e00c76e4 Use OS calls rather than exec() to get memory statistics
Before this change we used to exec() various binaries to find out memory
information.

While this worked, it was awfully slow.

And if somebody would want to compute how many percent of available memory all
PIDs on the system uses, that would take almost ten seconds on my laptop with
the previous implementation.

This implementation fares a lot better, and is smaller.
2016-02-19 21:28:50 +01:00
Johan Walles 5771ea9465 Add Darwin specific mem.VirtualMemory() tests 2016-02-19 20:53:29 +01:00
Masayoshi Sekimura 3a1fa5dc80 format go program with go 1.5.2 "go fmt" 2016-01-09 16:17:21 -08:00
Nikolay Sivko 075839d9f1 fix imports 2015-11-25 10:50:51 +03:00
Nikolay Sivko d4e648e253 [freebsd] fix SwapMemory for hosts without swap 2015-11-24 17:37:01 +03:00
Shirou WAKAYAMA 7288e9a5af common[all]: add internal 2015-10-20 00:04:57 +09: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
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 202a805f46 mem[darwin]: fix printf verb. 2015-10-14 15:59:10 +09:00
Cameron Sparr 6cd8284b30 When MemAvailable is in /proc/meminfo, use it (kernel 3.14+) 2015-09-21 17:18:20 -07:00
shirou c1313e7634 Merge pull request #82 from influxdb/darwin-mem
Use vm_stat command on darwin to get memory
2015-09-18 16:31:13 +09:00
Cameron Sparr 4bba3025ca Use vm_stat command on darwin to get memory
This has the benefit of allowing us to also grab the cached memory so
that we can get an "available" measurement
2015-09-18 00:24:09 -07:00
WAKAYAMA shirou be88485e9f mem[freebsd]: fix virtual memory available and used. 2015-09-18 14:01:49 +09:00
Cameron Sparr ce70817f55 Fix memory reporting for linux systems
/proc/meminfo reports memory in KiloBytes and so needs a multiplier of
1024 instead of 1000.
The kernel reports in terms of pages and the proc filesystem is left
shifting by 2 for 4KB pages to get KB. Since this is a binary shift,
Bytes will need to shift by 10 and so get multiplied by 1024.

From the kernel code. PAGE_SHIFT = 12 for 4KB pages
"MemTotal:       %8lu kB\n", K(i.totalram)

Thanks to @subhachandrachandra!
2015-08-27 09:41:19 -06:00
Myungjun Kim c5b94d3e4c memory[darwin]: return value of "sysctl hw.memsize" is memory size in bytes. 2015-08-16 16:32:53 +09:00
Shirou WAKAYAMA a9e65ec556 mem[darwin]: fix VirtualMem stat multiply. 2015-07-23 11:39:22 +09:00
Nikolay Sivko 06282a319c [darwin] hw.memsize already in bytes 2015-04-08 14:53:21 +03:00
若山史郎 cea341c690 mem: add 0 check to darwin.swapmem. 2015-02-26 16:23:35 +09:00
Shirou WAKAYAMA 13cd195a7e change package name. 2014-12-30 22:09:05 +09:00
Shirou WAKAYAMA 1cb67eb4c2 merge 039b9defab 2014-12-27 23:43:18 +09:00
Shirou WAKAYAMA 16de570414 merge 039b9defab 2014-12-27 23:42:00 +09:00
WAKAYAMA Shirou 9f2c985a28 fix windows build. 2014-11-27 22:28:05 +09:00
WAKAYAMA shirou d11680c773 fix bugs on FreeBSD. 2014-11-27 10:25:14 +09:00
Shirou WAKAYAMA a4671fcc2a move subdirectories. refer to issue #24 2014-11-27 10:18:15 +09:00