ssh_crawler/stat/mem.go
insanity 3ef6659f46 ing
2017-10-23 18:08:19 +09:00

31 lines
468 B
Go

package stat
import (
"bufio"
"io"
"strings"
)
type MemStat struct {
}
func (mem MemStat) Command() string {
return "cat /proc/meminfo"
}
func (mem MemStat) Parse(r io.Reader) (*map[string]string, error) {
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()
}