2014-04-18 15:34:47 +08:00
|
|
|
// +build linux
|
|
|
|
|
2014-04-22 08:44:22 +08:00
|
|
|
package gopsutil
|
2014-04-18 15:34:47 +08:00
|
|
|
|
|
|
|
import (
|
|
|
|
"io/ioutil"
|
|
|
|
"strconv"
|
|
|
|
"strings"
|
|
|
|
)
|
|
|
|
|
2014-05-01 11:01:30 +08:00
|
|
|
func LoadAvg() (*LoadAvgStat, error) {
|
2014-04-18 15:34:47 +08:00
|
|
|
filename := "/proc/loadavg"
|
|
|
|
line, err := ioutil.ReadFile(filename)
|
|
|
|
if err != nil {
|
2014-05-01 11:01:30 +08:00
|
|
|
return nil, err
|
2014-04-18 15:34:47 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
values := strings.Fields(string(line))
|
|
|
|
|
|
|
|
load1, err := strconv.ParseFloat(values[0], 64)
|
|
|
|
if err != nil {
|
2014-05-01 11:01:30 +08:00
|
|
|
return nil, err
|
2014-04-18 15:34:47 +08:00
|
|
|
}
|
|
|
|
load5, err := strconv.ParseFloat(values[1], 64)
|
|
|
|
if err != nil {
|
2014-05-01 11:01:30 +08:00
|
|
|
return nil, err
|
2014-04-18 15:34:47 +08:00
|
|
|
}
|
|
|
|
load15, err := strconv.ParseFloat(values[2], 64)
|
|
|
|
if err != nil {
|
2014-05-01 11:01:30 +08:00
|
|
|
return nil, err
|
2014-04-18 15:34:47 +08:00
|
|
|
}
|
|
|
|
|
2014-05-01 11:01:30 +08:00
|
|
|
ret := &LoadAvgStat{
|
2014-04-18 15:34:47 +08:00
|
|
|
Load1: load1,
|
|
|
|
Load5: load5,
|
|
|
|
Load15: load15,
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret, nil
|
|
|
|
}
|