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
This commit is contained in:
subhachandrachandra 2015-08-21 16:08:54 -07:00 committed by Cameron Sparr
parent ca1d2c7000
commit 8d034f544c
2 changed files with 7 additions and 6 deletions

View File

@ -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]

View File

@ -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