mirror of https://github.com/shirou/gopsutil
Eliminate use of sysctl command on FreeBSD
In order to improve performance and help prevent crashes due to the outstanding fork crash bug: https://github.com/golang/go/issues/15658 Replace string parsed values from the sysctl command with native reads of sysctl values using unix.SysctlRaw and unix.SysctlUint32. This also merges OpenBSD and FreeBSD load implementations which are identical.pull/432/head
parent
1ba77cdb3d
commit
6450c60b61
@ -0,0 +1,9 @@
|
|||||||
|
package cpu
|
||||||
|
|
||||||
|
type cpuTimes struct {
|
||||||
|
User uint32
|
||||||
|
Nice uint32
|
||||||
|
Sys uint32
|
||||||
|
Intr uint32
|
||||||
|
Idle uint32
|
||||||
|
}
|
@ -0,0 +1,9 @@
|
|||||||
|
package cpu
|
||||||
|
|
||||||
|
type cpuTimes struct {
|
||||||
|
User uint64
|
||||||
|
Nice uint64
|
||||||
|
Sys uint64
|
||||||
|
Intr uint64
|
||||||
|
Idle uint64
|
||||||
|
}
|
@ -1,65 +0,0 @@
|
|||||||
// +build openbsd
|
|
||||||
|
|
||||||
package load
|
|
||||||
|
|
||||||
import (
|
|
||||||
"os/exec"
|
|
||||||
"strconv"
|
|
||||||
"strings"
|
|
||||||
|
|
||||||
"github.com/shirou/gopsutil/internal/common"
|
|
||||||
)
|
|
||||||
|
|
||||||
func Avg() (*AvgStat, error) {
|
|
||||||
values, err := common.DoSysctrl("vm.loadavg")
|
|
||||||
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 := &AvgStat{
|
|
||||||
Load1: float64(load1),
|
|
||||||
Load5: float64(load5),
|
|
||||||
Load15: float64(load15),
|
|
||||||
}
|
|
||||||
|
|
||||||
return ret, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// 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") {
|
|
||||||
ret.ProcsRunning++
|
|
||||||
} else if strings.Contains(l, "D") {
|
|
||||||
ret.ProcsBlocked++
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return &ret, nil
|
|
||||||
}
|
|
Loading…
Reference in New Issue