2017-10-23 05:31:04 +00:00
|
|
|
package stat
|
|
|
|
|
|
|
|
import (
|
|
|
|
"io"
|
|
|
|
"strings"
|
|
|
|
"bufio"
|
|
|
|
)
|
|
|
|
|
2017-10-23 06:59:38 +00:00
|
|
|
type MemStat struct {
|
2017-10-23 05:31:04 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2017-10-23 06:59:38 +00:00
|
|
|
func (mem MemStat) Command() string {
|
2017-10-23 05:31:04 +00:00
|
|
|
return "cat /proc/meminfo"
|
|
|
|
}
|
|
|
|
|
2017-10-23 06:59:38 +00:00
|
|
|
func (mem MemStat) Parse(r io.Reader) (map[string]string, error) {
|
2017-10-23 05:31:04 +00:00
|
|
|
var (
|
|
|
|
memInfo = map[string]string{}
|
|
|
|
scanner = bufio.NewScanner(r)
|
|
|
|
)
|
|
|
|
|
|
|
|
for scanner.Scan() {
|
|
|
|
line := scanner.Text()
|
|
|
|
parts := strings.Fields(line)
|
|
|
|
key := parts[0][:len(parts[0])-1]
|
|
|
|
memInfo[key] = parts[1]
|
|
|
|
}
|
|
|
|
|
|
|
|
return memInfo, scanner.Err()
|
|
|
|
}
|