From 28f9a2862642b0fcba08ec2e79a17c36518792ba Mon Sep 17 00:00:00 2001 From: Nikolay Sivko Date: Sun, 2 Nov 2014 10:17:50 +0300 Subject: [PATCH] [linux] fill SwapMemoryStat.Sin/Sout from /proc/vmstat --- mem_linux.go | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/mem_linux.go b/mem_linux.go index 2cb8911..fa113ba 100644 --- a/mem_linux.go +++ b/mem_linux.go @@ -65,6 +65,26 @@ func SwapMemory() (*SwapMemoryStat, error) { } else { ret.UsedPercent = 0 } - + lines, _ := readLines("/proc/vmstat") + for _, l := range lines { + fields := strings.Fields(l) + if len(fields) < 2 { + continue + } + switch fields[0] { + case "pswpin": + value, err := strconv.ParseUint(fields[1], 10, 64) + if err != nil { + continue + } + ret.Sin = value * 4 * 1024 + case "pswpout": + value, err := strconv.ParseUint(fields[1], 10, 64) + if err != nil { + continue + } + ret.Sout = value * 4 * 1024 + } + } return ret, nil }