32 lines
467 B
Go
32 lines
467 B
Go
package stat
|
|
|
|
import (
|
|
"io"
|
|
"strings"
|
|
"bufio"
|
|
)
|
|
|
|
type MEMStat struct {
|
|
|
|
}
|
|
|
|
func (cpu MEMStat) Command() string {
|
|
return "cat /proc/meminfo"
|
|
}
|
|
|
|
func (cpu 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()
|
|
}
|