32 lines
526 B
Go
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()
|
|
}
|