2014-08-08 22:09:28 +08:00
|
|
|
// +build darwin
|
|
|
|
|
2014-12-30 21:09:05 +08:00
|
|
|
package load
|
2014-08-08 22:09:28 +08:00
|
|
|
|
|
|
|
import (
|
|
|
|
"strconv"
|
2014-11-27 09:18:15 +08:00
|
|
|
|
2015-10-19 23:04:57 +08:00
|
|
|
"github.com/shirou/gopsutil/internal/common"
|
2014-08-08 22:09:28 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
func LoadAvg() (*LoadAvgStat, error) {
|
2014-11-27 09:18:15 +08:00
|
|
|
values, err := common.DoSysctrl("vm.loadavg")
|
2014-08-08 22:09:28 +08:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
load1, err := strconv.ParseFloat(values[0], 64)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
load5, err := strconv.ParseFloat(values[1], 64)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
load15, err := strconv.ParseFloat(values[2], 64)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
ret := &LoadAvgStat{
|
|
|
|
Load1: float64(load1),
|
|
|
|
Load5: float64(load5),
|
|
|
|
Load15: float64(load15),
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret, nil
|
|
|
|
}
|