ssh_crawler/stat/loadavg.go
insanity 3134350172 ing
2017-10-24 18:23:56 +09:00

32 lines
526 B
Go

package stat
import (
"bufio"
"io"
"strings"
)
type LoadAvg struct {
}
func (loadavg LoadAvg) Command() string {
return "cat /proc/loadavg"
}
func (loadavg LoadAvg) Read(r io.Reader) (*map[string]string, error) {
var (
scanner = bufio.NewScanner(r)
resMap = make(map[string]string)
)
for scanner.Scan() {
line := scanner.Text()
parts := strings.Fields(line)
resMap["cpu.load.avg1"] = parts[0]
resMap["cpu.load.avg5"]= parts[1]
resMap["cpu.load.avg15"] = parts[2]
}
return &resMap, scanner.Err()
}