1
0
mirror of https://github.com/shirou/gopsutil.git synced 2025-04-28 13:48:49 +08:00
shirou_gopsutil/load/load_freebsd.go

66 lines
1.2 KiB
Go
Raw Normal View History

2014-04-18 16:34:47 +09:00
// +build freebsd
2014-12-30 22:09:05 +09:00
package load
2014-04-18 16:34:47 +09:00
import (
"os/exec"
2014-04-18 16:34:47 +09:00
"strconv"
"strings"
2015-10-20 00:04:57 +09:00
"github.com/shirou/gopsutil/internal/common"
2014-04-18 16:34:47 +09:00
)
func Avg() (*AvgStat, error) {
values, err := common.DoSysctrl("vm.loadavg")
2014-04-18 16:34:47 +09:00
if err != nil {
2014-05-20 19:29:41 +09:00
return nil, err
2014-04-18 16:34:47 +09:00
}
2014-04-22 10:12:01 +09:00
load1, err := strconv.ParseFloat(values[0], 64)
2014-04-18 16:34:47 +09:00
if err != nil {
2014-05-20 19:29:41 +09:00
return nil, err
2014-04-18 16:34:47 +09:00
}
2014-04-22 10:12:01 +09:00
load5, err := strconv.ParseFloat(values[1], 64)
2014-04-18 16:34:47 +09:00
if err != nil {
2014-05-20 19:29:41 +09:00
return nil, err
2014-04-18 16:34:47 +09:00
}
2014-04-22 10:12:01 +09:00
load15, err := strconv.ParseFloat(values[2], 64)
2014-04-18 16:34:47 +09:00
if err != nil {
2014-05-20 19:29:41 +09:00
return nil, err
2014-04-18 16:34:47 +09:00
}
ret := &AvgStat{
2014-04-22 10:12:01 +09:00
Load1: float64(load1),
Load5: float64(load5),
Load15: float64(load15),
2014-04-18 16:34:47 +09:00
}
return ret, nil
}
2016-02-20 23:17:20 +09:00
// Misc returnes miscellaneous host-wide statistics.
// darwin use ps command to get process running/blocked count.
// Almost same as Darwin implementation, but state is different.
func Misc() (*MiscStat, error) {
bin, err := exec.LookPath("ps")
if err != nil {
return nil, err
}
out, err := invoke.Command(bin, "axo", "state")
if err != nil {
return nil, err
}
lines := strings.Split(string(out), "\n")
ret := MiscStat{}
for _, l := range lines {
if strings.Contains(l, "R") {
2016-04-01 21:34:39 +09:00
ret.ProcsRunning++
} else if strings.Contains(l, "D") {
2016-04-01 21:34:39 +09:00
ret.ProcsBlocked++
}
}
return &ret, nil
}