Merge pull request #84 from influxdb/mem-new-kern
When MemAvailable is in /proc/meminfo, use it (kernel 3.14+)
This commit is contained in:
commit
b389cc66e3
|
@ -13,6 +13,8 @@ import (
|
||||||
func VirtualMemory() (*VirtualMemoryStat, error) {
|
func VirtualMemory() (*VirtualMemoryStat, error) {
|
||||||
filename := "/proc/meminfo"
|
filename := "/proc/meminfo"
|
||||||
lines, _ := common.ReadLines(filename)
|
lines, _ := common.ReadLines(filename)
|
||||||
|
// flag if MemAvailable is in /proc/meminfo (kernel 3.14+)
|
||||||
|
memavail := false
|
||||||
|
|
||||||
ret := &VirtualMemoryStat{}
|
ret := &VirtualMemoryStat{}
|
||||||
for _, line := range lines {
|
for _, line := range lines {
|
||||||
|
@ -33,6 +35,9 @@ func VirtualMemory() (*VirtualMemoryStat, error) {
|
||||||
ret.Total = t * 1024
|
ret.Total = t * 1024
|
||||||
case "MemFree":
|
case "MemFree":
|
||||||
ret.Free = t * 1024
|
ret.Free = t * 1024
|
||||||
|
case "MemAvailable":
|
||||||
|
memavail = true
|
||||||
|
ret.Available = t * 1024
|
||||||
case "Buffers":
|
case "Buffers":
|
||||||
ret.Buffers = t * 1024
|
ret.Buffers = t * 1024
|
||||||
case "Cached":
|
case "Cached":
|
||||||
|
@ -43,7 +48,9 @@ func VirtualMemory() (*VirtualMemoryStat, error) {
|
||||||
ret.Inactive = t * 1024
|
ret.Inactive = t * 1024
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ret.Available = ret.Free + ret.Buffers + ret.Cached
|
if !memavail {
|
||||||
|
ret.Available = ret.Free + ret.Buffers + ret.Cached
|
||||||
|
}
|
||||||
ret.Used = ret.Total - ret.Free
|
ret.Used = ret.Total - ret.Free
|
||||||
ret.UsedPercent = float64(ret.Total-ret.Available) / float64(ret.Total) * 100.0
|
ret.UsedPercent = float64(ret.Total-ret.Available) / float64(ret.Total) * 100.0
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue