Commit Graph

168 Commits (master)

Author SHA1 Message Date
Ville Skyttä 09c3ba3896 [mem][solaris] simplify regular expressions 3 years ago
Ville Skyttä 093e68cb91 [mem][solaris] improve prtconf memory size scraping
Accept uppercase Memory, that's how it appears to be at least in Solaris
11.3 and OpenIndiana oi_151a7.
3 years ago
Ville Skyttä 768c3b1888 [mem][solaris] don't hardcode path to prtconf in error message 3 years ago
shirou 7ae41c1f40 [v2][solaris][mem] fix invoke ctx. 3 years ago
shirou 3e7da36a46 [mem][solaris] fix wrong variable name. 3 years ago
WAKAYAMA shirou 46d6fcc192 [mem][bsd] fix missing arg 3 years ago
shirou 582bb14d8a
[linux][mem] remove unnecessary import 4 years ago
Punya Biswal 32b14a3723 Use invoke.CommandWithContext 4 years ago
Punya Biswal 5169bfe02d
Update mem/mem_bsd.go
Co-authored-by: shirou <shirou.faw@gmail.com>
4 years ago
Punya Biswal 7c1aa06a5e Respond to review comments
* use LookPath for better error messages
* support procfs in containers
4 years ago
Tom Barker 84a665b712 Add mem.SwapDevices() method. 4 years ago
Guillaume Ballet 992d17af94 add support for OpenBSD arm64 4 years ago
Lomanic cd25417bd7 [mem][linux] Fix #1002 only try to parse /proc/meminfo numeric values on fields we're interested in 4 years ago
Lomanic 07887a9e9f [mem][linux] Add mocked test for VirtualMemory() and fix SReclaimable SUnreclaim retrieval 4 years ago
Lomanic 4cfc60d68b
Merge pull request #928 from Lomanic/skip-tests-when-not-implemented 5 years ago
Lomanic 84afaae670 [host][mem][process][openbsd] Add 386 const and types definitions
Continuation of #721, this type using mktypes.sh that I didn't know at the time.
Weirdly, `go tool cgo -godefs` doesn't produce propery go-fmt-ed code, had to do run go-fmt manually afterwards.
5 years ago
Lomanic 7f588ac380
Merge pull request #930 from tklauser/openbsd-uvmpexp
Use unix.SysctlUvmexp on OpenBSD
5 years ago
Tobias Klauser 62354ea032 Fix TestVirtual_memory on OpenBSD
On OpenBSD, the total is used + free + cached + inactive like on macOS.

Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
5 years ago
Tobias Klauser aacbba22ae Use unix.SysctlUvmexp on OpenBSD
Use SysctlUvmexp from golang.org/x/sys/unix to avoid having to define
the type Uvmexp and the sysctl consts. This will also allow to build on
GOOS=openbsd with e.g. GOARCH=arm64.

Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
5 years ago
Lomanic ea86cbc3ff [mem] Skip tests on non-implemented platforms #446 5 years ago
Simon Thoby 3b64944534 Set the 'free' memory value to the 'available' memory on windows 5 years ago
James Bebbington 61cb122a84
Added comment noting that PgMajFault is Linux specific 5 years ago
James Bebbington 16fdb92bfc Add pgmajfault to data returned by vmstat on Linux 5 years ago
GameXG 144c67833a
fix #863 Swap.UsedPercent is inconsistent 5 years ago
Xuewei Zhang 929068ccd5 mem: Add VirtualMemoryEx() and VirtualMemoryExWithContext() 5 years ago
Xuewei Zhang 3695635d09 Collect Active(anon), Inactive(anon) and Unevictable in /proc/meminfo
These fields helps people understand anonymous memory usage pattern.
5 years ago
lanixzcj 38b78c3eac rename InActive(file) to Inactive(file) in mem_linux.go 5 years ago
Minje Park b7f9acbce8 add unreclaim metric, this closes #719 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
lootek 1cbb212a6b
Add pages in/out/fault statistics (as read from vmstat) 6 years ago
mingrammer 64a995aad4 Refactor with gofmt 6 years ago
mingrammer 017c9f9cbc Fix typos 6 years ago
WAKAYAMA shirou bb15c85289 [mem][freebsd]: add SysctlUint which can adapt both 32 and 64 bit 6 years ago
Lomanic e3c878cc43 [mem][darwin] Remove calls to sysctl binary in mem/mem_darwin.go #639 6 years ago
shirou 6c6abd6d16
Merge pull request #626 from mznet/manual-available-memory-calculation
Manual available memory calculation
6 years ago
Minje Park c75deb9dc0 debug codes were removed 6 years ago
Minje Park 47ed6aaebd activefile and inactivefile fields were removed from VirtualMemoryStat 6 years ago
shirou b3d992b0f6 [mem]freebsd: update xswdev_version to adapt FreeBSD 12. 6 years ago
Minje Park d23abede78 struct typo and broken test case were fixed 6 years ago
Minje Park d7ce61cac8 Error checks and fallback for old linux 6 years ago
Minje Park 9fb3b9625d mem available fallback under kernel 2.6.13 6 years ago
Minje Park 73545ec820 AvailableMemory is't calculated automatically under kenel 3.14 so it is needed to calcuate manually
manual available memory calculation should be done if only memavail is false

Manual Available Memory calculation under kernel 3.14

accurate manaul available memory calculation
6 years ago
Lomanic ccc1c1016b [mem][darwin] Fix #622 include Inactive memory in total calculation in TestVirtual_memory 6 years ago
Minje Park f9e238c38b SReclaimable should be added to Cached Memory 6 years ago
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
7 years ago
Isida Zyun'iti 48da6ade9e Fix FreeBSD total memory.
Like this.
FreeBSD: fix total memory giampaolo/psutil@bd9a58b bd9a58b2af
7 years ago
Lomanic 6b586d2fcd [mem][windows] Fix TestVirtual_memory test 7 years ago
shirou 6b48f3bd01 [mem] fix test. 7 years ago
Arnaud Rebillout 558a95bf02 Fix TestVirtual_memory #552
Based on https://stackoverflow.com/a/30772733/776208

Signed-off-by: Arnaud Rebillout <arnaud.rebillout@collabora.com>
7 years ago
shirou 9937d4109d mem[linux]: fix test. 7 years ago
Shrug 42 6a38ce2069 fix json tags 7 years ago
Shrug 42 12fad953c1 added additional linux meminfo fields 7 years ago
Steven Lee 3adcafe5fd mem[windows]: if no swap, just return 0 used percent default 7 years ago
shirou 0f1576d63c mem[windows]: if no swap, total and/or used is 0. 7 years ago
Daniel Nelson 28b1d7477e
Use uint64 when retrieving vfs.bufspace
On some system using a the uint32 function would return the error
"cannot allocate memory".
7 years ago
shirou 145dca90f7 change to use CommandContext. 7 years ago
shirou c3f470a77a
Merge pull request #504 from dimrozakis/linux-used-mem
Always calculate linux used mem as total-(free+buffered+cache)
7 years ago
shirou 1ba5059aca [memory] Linux: add document url about OverCommiting. 7 years ago
shirou a1564d2e89
Merge pull request #478 from DataDog/olivielpeau/commit-vm-stats
[mem] Add commit-related stats to VirtualMemoryStat on Linux
7 years ago
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.
7 years ago
Chevy 699deed6c6
Fix float64 casting 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
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.
7 years ago
shirou 4c73494c78 Add WithContext functions. 7 years ago
Olivier Vielpeau 5b52fbbea5 [mem] Add commit-related stats to VirtualMemoryStat on Linux 7 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
Derek Brown 7c807c86e4 Add implementation of SwapMemory() for windows 8 years ago
Sean Chittenden 635b971c0e
Move from the `syscall` package to the `golang.org/x/sys/{unix,windows}` 8 years ago
WAKAYAMA Shirou f8ef680a47 error strings change to lowercase 8 years ago
James Nugent d19ac24a84 mem: Skip TestVirtual_memory on Solaris 8 years ago
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.
8 years ago
Cameron Sparr a213bf5e6d
run go fmt ./... 8 years ago
WAKAYAMA Shirou 1123132e5a [mem]darwin: swap memory was Kbytes, since linux is bytes. 8 years ago
Maxime Mouial 4a1d5da977 Add 'SwapCached' to the VirtualMemoryStat informations on linux 8 years ago
Maxime Mouial 44e27c6972 Add Slab, Shared and PageTables metric for VirtualMemory under linux 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
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
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
kthommandra 1fd3a4dbad Added the writeback, dirty and writebacktmp fields from /proc/meminfo on Linux 9 years ago
Shirou WAKAYAMA 57f6aebc7e add Timeout to invoke command and use common.Invoke refs: #201 9 years ago
Shirou WAKAYAMA adf2f03a48 fix build and path error 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 613a8a90e1 fixed by golint. 9 years ago
Shirou WAKAYAMA 4bb84648bf JSON representation is renamed to fit Google JSON style, camelCase. 9 years ago
Johan Walles dd875d4970 Fix memory stats on Darwin, non-CGO 9 years ago
Johan Walles d109284df3 Fix memory stats on Darwin, CGO 9 years ago
Johan Walles 27093ae2d2 mem_darwin_test.go: Compare `total` to `sysctl hw.memsize` 9 years ago
Johan Walles 0d5592714b Fix memory stats on LinuxFreeBSD 9 years ago
Johan Walles 66a07939f7 Fix memory stats on Linux 9 years ago
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
9 years ago
Johan Walles 44f817eb8d Split mem_darwin.go into CGO and non CGO variants 9 years ago
Johan Walles 00504a37e3 Remove unused import 9 years ago
Johan Walles a6cd6f803b Use Go's built in syscall.Getpagesize() 9 years ago
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.
9 years ago
Johan Walles 5771ea9465 Add Darwin specific mem.VirtualMemory() tests 9 years ago
Masayoshi Sekimura 3a1fa5dc80 format go program with go 1.5.2 "go fmt" 9 years ago
Nikolay Sivko 075839d9f1 fix imports 9 years ago
Nikolay Sivko d4e648e253 [freebsd] fix SwapMemory for hosts without swap 9 years ago
Shirou WAKAYAMA 7288e9a5af common[all]: add internal 10 years ago