From 79e9a0726366520ba69f0ad28db8641aef30733d Mon Sep 17 00:00:00 2001 From: James Bebbington Date: Sat, 12 Sep 2020 12:35:21 +1000 Subject: [PATCH] Add ProcsCreated stat for openbsd --- load/load_bsd.go | 12 ++++++++++++ load/load_freebsd.go | 7 +++++++ load/load_openbsd.go | 17 +++++++++++++++++ 3 files changed, 36 insertions(+) create mode 100644 load/load_freebsd.go create mode 100644 load/load_openbsd.go diff --git a/load/load_bsd.go b/load/load_bsd.go index dfac10c..9cb254a 100644 --- a/load/load_bsd.go +++ b/load/load_bsd.go @@ -37,6 +37,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. @@ -64,5 +70,11 @@ func MiscWithContext(ctx context.Context) (*MiscStat, error) { } } + f, err := getForkStat() + if err != nil { + return nil, err + } + ret.ProcsCreated = f.forks + return &ret, nil } diff --git a/load/load_freebsd.go b/load/load_freebsd.go new file mode 100644 index 0000000..bee8f55 --- /dev/null +++ b/load/load_freebsd.go @@ -0,0 +1,7 @@ +// +build freebsd + +package load + +func getForkStat() (forkstat, error) { + return forkstat{}, nil +} diff --git a/load/load_openbsd.go b/load/load_openbsd.go new file mode 100644 index 0000000..b299f58 --- /dev/null +++ b/load/load_openbsd.go @@ -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 +}