Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Copy load.MiscStat ProcsCreated field from v2 to v3 (supersedes #1123) #1140

Merged
merged 5 commits into from
Oct 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions v3/load/load.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ func (l AvgStat) String() string {

type MiscStat struct {
ProcsTotal int `json:"procsTotal"`
ProcsCreated int `json:"procsCreated"`
ProcsRunning int `json:"procsRunning"`
ProcsBlocked int `json:"procsBlocked"`
Ctxt int `json:"ctxt"`
Expand Down
13 changes: 13 additions & 0 deletions v3/load/load_bsd.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build freebsd || openbsd
// +build freebsd openbsd

package load
Expand Down Expand Up @@ -37,6 +38,12 @@ func AvgWithContext(ctx context.Context) (*AvgStat, error) {
return ret, nil
}

type forkstat struct {
forks int
vforks int
__tforks int
}

// Misc returns miscellaneous host-wide statistics.
// darwin use ps command to get process running/blocked count.
// Almost same as Darwin implementation, but state is different.
Expand Down Expand Up @@ -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
}
7 changes: 7 additions & 0 deletions v3/load/load_freebsd.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// +build freebsd

package load

func getForkStat() (forkstat, error) {
return forkstat{}, nil
}
2 changes: 2 additions & 0 deletions v3/load/load_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ func MiscWithContext(ctx context.Context) (*MiscStat, error) {
continue
}
switch fields[0] {
case "processes":
ret.ProcsCreated = int(v)
case "procs_running":
ret.ProcsRunning = int(v)
case "procs_blocked":
Expand Down
17 changes: 17 additions & 0 deletions v3/load/load_openbsd.go
Original file line number Diff line number Diff line change
@@ -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
}
3 changes: 2 additions & 1 deletion v3/load/load_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,12 @@ func TestMisc(t *testing.T) {
func TestMiscStatString(t *testing.T) {
v := MiscStat{
ProcsTotal: 4,
ProcsCreated: 5,
ProcsRunning: 1,
ProcsBlocked: 2,
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) {
t.Errorf("TestMiscString string is invalid: %v", v)
}
Expand Down