2017-10-23 05:31:04 +00:00
|
|
|
package stat
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bufio"
|
2017-10-23 09:08:19 +00:00
|
|
|
"io"
|
2017-10-23 05:31:04 +00:00
|
|
|
"strings"
|
|
|
|
)
|
|
|
|
|
|
|
|
type LoadAvg struct {
|
|
|
|
min1,
|
|
|
|
min5,
|
|
|
|
min15 string
|
|
|
|
}
|
|
|
|
|
|
|
|
func (loadavg LoadAvg) Command() string {
|
|
|
|
return "cat /proc/loadavg"
|
|
|
|
}
|
|
|
|
|
2017-10-23 09:08:19 +00:00
|
|
|
func (loadavg LoadAvg) Parse(r io.Reader) (*LoadAvg, error) {
|
2017-10-23 05:31:04 +00:00
|
|
|
var (
|
|
|
|
scanner = bufio.NewScanner(r)
|
|
|
|
)
|
|
|
|
|
|
|
|
load := LoadAvg{}
|
|
|
|
for scanner.Scan() {
|
|
|
|
line := scanner.Text()
|
|
|
|
parts := strings.Fields(line)
|
|
|
|
load.min1 = parts[0]
|
|
|
|
load.min5 = parts[1]
|
|
|
|
load.min15 = parts[2]
|
|
|
|
}
|
2017-10-23 09:08:19 +00:00
|
|
|
return &load, scanner.Err()
|
2017-10-23 05:31:04 +00:00
|
|
|
}
|