2014-04-18 15:34:47 +08:00
|
|
|
// +build freebsd
|
|
|
|
|
2014-04-22 08:44:22 +08:00
|
|
|
package gopsutil
|
2014-04-18 15:34:47 +08:00
|
|
|
|
|
|
|
import (
|
|
|
|
"exec"
|
|
|
|
"strconv"
|
|
|
|
"strings"
|
|
|
|
)
|
|
|
|
|
2014-04-22 09:02:01 +08:00
|
|
|
func LoadAvg() (LoadAvgStat, error) {
|
2014-04-18 15:34:47 +08:00
|
|
|
out, err := exec.Command("/sbin/sysctl", "-n", "vm.loadavg").Output()
|
|
|
|
if err != nil {
|
2014-04-22 09:02:01 +08:00
|
|
|
return LoadAvgStat{}, err
|
2014-04-18 15:34:47 +08:00
|
|
|
}
|
|
|
|
v := strings.Replace(string(out), "{ ", "", 1)
|
|
|
|
v = strings.Replace(string(v), " }", "", 1)
|
|
|
|
values := strings.Fields(string(v))
|
|
|
|
|
|
|
|
load1, err := strconv.ParseFloat(values[0], 32)
|
|
|
|
if err != nil {
|
2014-04-22 09:02:01 +08:00
|
|
|
return LoadAvgStat{}, err
|
2014-04-18 15:34:47 +08:00
|
|
|
}
|
|
|
|
load5, err := strconv.ParseFloat(values[1], 32)
|
|
|
|
if err != nil {
|
2014-04-22 09:02:01 +08:00
|
|
|
return LoadAvgStat{}, err
|
2014-04-18 15:34:47 +08:00
|
|
|
}
|
|
|
|
load15, err := strconv.ParseFloat(values[2], 32)
|
|
|
|
if err != nil {
|
2014-04-22 09:02:01 +08:00
|
|
|
return LoadAvgStat{}, err
|
2014-04-18 15:34:47 +08:00
|
|
|
}
|
|
|
|
|
2014-04-22 09:02:01 +08:00
|
|
|
ret := LoadAvgStat{
|
2014-04-18 15:34:47 +08:00
|
|
|
Load1: float32(load1),
|
|
|
|
Load5: float32(load5),
|
|
|
|
Load15: float32(load15),
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret, nil
|
|
|
|
}
|