34 lines
483 B
Go
34 lines
483 B
Go
|
package stat
|
||
|
|
||
|
import (
|
||
|
"io"
|
||
|
"bufio"
|
||
|
"strings"
|
||
|
)
|
||
|
|
||
|
type LoadAvg struct {
|
||
|
min1,
|
||
|
min5,
|
||
|
min15 string
|
||
|
}
|
||
|
|
||
|
func (loadavg LoadAvg) Command() string {
|
||
|
return "cat /proc/loadavg"
|
||
|
}
|
||
|
|
||
|
func (loadavg LoadAvg) Parse(r io.Reader) (LoadAvg, error) {
|
||
|
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]
|
||
|
}
|
||
|
return load, scanner.Err()
|
||
|
}
|