mirror of
https://github.com/shirou/gopsutil.git
synced 2025-05-10 19:29:14 +08:00
Merge pull request #1140 from punya/proc-created-v3
Copy load.MiscStat ProcsCreated field from v2 to v3 (supersedes #1123)
This commit is contained in:
commit
5bdd02c944
@ -21,6 +21,7 @@ func (l AvgStat) String() string {
|
|||||||
|
|
||||||
type MiscStat struct {
|
type MiscStat struct {
|
||||||
ProcsTotal int `json:"procsTotal"`
|
ProcsTotal int `json:"procsTotal"`
|
||||||
|
ProcsCreated int `json:"procsCreated"`
|
||||||
ProcsRunning int `json:"procsRunning"`
|
ProcsRunning int `json:"procsRunning"`
|
||||||
ProcsBlocked int `json:"procsBlocked"`
|
ProcsBlocked int `json:"procsBlocked"`
|
||||||
Ctxt int `json:"ctxt"`
|
Ctxt int `json:"ctxt"`
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
//go:build freebsd || openbsd
|
||||||
// +build freebsd openbsd
|
// +build freebsd openbsd
|
||||||
|
|
||||||
package load
|
package load
|
||||||
@ -37,6 +38,12 @@ func AvgWithContext(ctx context.Context) (*AvgStat, error) {
|
|||||||
return ret, nil
|
return ret, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type forkstat struct {
|
||||||
|
forks int
|
||||||
|
vforks int
|
||||||
|
__tforks int
|
||||||
|
}
|
||||||
|
|
||||||
// Misc returns miscellaneous host-wide statistics.
|
// Misc returns miscellaneous host-wide statistics.
|
||||||
// darwin use ps command to get process running/blocked count.
|
// darwin use ps command to get process running/blocked count.
|
||||||
// Almost same as Darwin implementation, but state is different.
|
// Almost same as Darwin implementation, but state is different.
|
||||||
@ -64,5 +71,11 @@ func MiscWithContext(ctx context.Context) (*MiscStat, error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
f, err := getForkStat()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
ret.ProcsCreated = f.forks
|
||||||
|
|
||||||
return &ret, nil
|
return &ret, nil
|
||||||
}
|
}
|
||||||
|
7
v3/load/load_freebsd.go
Normal file
7
v3/load/load_freebsd.go
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
// +build freebsd
|
||||||
|
|
||||||
|
package load
|
||||||
|
|
||||||
|
func getForkStat() (forkstat, error) {
|
||||||
|
return forkstat{}, nil
|
||||||
|
}
|
@ -92,6 +92,8 @@ func MiscWithContext(ctx context.Context) (*MiscStat, error) {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
switch fields[0] {
|
switch fields[0] {
|
||||||
|
case "processes":
|
||||||
|
ret.ProcsCreated = int(v)
|
||||||
case "procs_running":
|
case "procs_running":
|
||||||
ret.ProcsRunning = int(v)
|
ret.ProcsRunning = int(v)
|
||||||
case "procs_blocked":
|
case "procs_blocked":
|
||||||
|
17
v3/load/load_openbsd.go
Normal file
17
v3/load/load_openbsd.go
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
// +build openbsd
|
||||||
|
|
||||||
|
package load
|
||||||
|
|
||||||
|
import (
|
||||||
|
"unsafe"
|
||||||
|
|
||||||
|
"golang.org/x/sys/unix"
|
||||||
|
)
|
||||||
|
|
||||||
|
func getForkStat() (forkstat, error) {
|
||||||
|
b, err := unix.SysctlRaw("kern.forkstat")
|
||||||
|
if err != nil {
|
||||||
|
return forkstat{}, err
|
||||||
|
}
|
||||||
|
return *(*forkstat)(unsafe.Pointer((&b[0]))), nil
|
||||||
|
}
|
@ -57,11 +57,12 @@ func TestMisc(t *testing.T) {
|
|||||||
func TestMiscStatString(t *testing.T) {
|
func TestMiscStatString(t *testing.T) {
|
||||||
v := MiscStat{
|
v := MiscStat{
|
||||||
ProcsTotal: 4,
|
ProcsTotal: 4,
|
||||||
|
ProcsCreated: 5,
|
||||||
ProcsRunning: 1,
|
ProcsRunning: 1,
|
||||||
ProcsBlocked: 2,
|
ProcsBlocked: 2,
|
||||||
Ctxt: 3,
|
Ctxt: 3,
|
||||||
}
|
}
|
||||||
e := `{"procsTotal":4,"procsRunning":1,"procsBlocked":2,"ctxt":3}`
|
e := `{"procsTotal":4,"procsCreated":5,"procsRunning":1,"procsBlocked":2,"ctxt":3}`
|
||||||
if e != fmt.Sprintf("%v", v) {
|
if e != fmt.Sprintf("%v", v) {
|
||||||
t.Errorf("TestMiscString string is invalid: %v", v)
|
t.Errorf("TestMiscString string is invalid: %v", v)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user