From 8d034f544c14a974fb7cb57acfff163cf91ff664 Mon Sep 17 00:00:00 2001 From: subhachandrachandra Date: Fri, 21 Aug 2015 16:08:54 -0700 Subject: [PATCH] Fixed 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) Closes #131 --- CHANGELOG.md | 1 + plugins/system/ps/mem/mem_linux.go | 12 ++++++------ 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6ab35aedf..068f65f44 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ ### Bugfixes - [#128](https://github.com/influxdb/telegraf/issues/128): system_load measurement missing. - [#129](https://github.com/influxdb/telegraf/issues/129): Latest pkg url fix. +- [#131](https://github.com/influxdb/telegraf/issues/131): Fix memory reporting on linux & darwin. Thanks @subhachandrachandra! - [#140](https://github.com/influxdb/telegraf/issues/140): Memory plugin prec->perc typo fix. Thanks @brunoqc! ## v0.1.6 [2015-08-20] diff --git a/plugins/system/ps/mem/mem_linux.go b/plugins/system/ps/mem/mem_linux.go index a0505b5f5..42a49a2b6 100644 --- a/plugins/system/ps/mem/mem_linux.go +++ b/plugins/system/ps/mem/mem_linux.go @@ -30,17 +30,17 @@ func VirtualMemory() (*VirtualMemoryStat, error) { } switch key { case "MemTotal": - ret.Total = t * 1000 + ret.Total = t * 1024 case "MemFree": - ret.Free = t * 1000 + ret.Free = t * 1024 case "Buffers": - ret.Buffers = t * 1000 + ret.Buffers = t * 1024 case "Cached": - ret.Cached = t * 1000 + ret.Cached = t * 1024 case "Active": - ret.Active = t * 1000 + ret.Active = t * 1024 case "Inactive": - ret.Inactive = t * 1000 + ret.Inactive = t * 1024 } } ret.Available = ret.Free + ret.Buffers + ret.Cached