From eab3aea46b8063fd0ff38b545f0522f1b9f68090 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ville=20Skytt=C3=A4?= Date: Wed, 19 May 2021 21:57:49 +0300 Subject: [PATCH] [load][solaris] support MiscStat.ProcsRunning --- load/load_fallback.go | 2 +- load/load_solaris.go | 44 ++++++++++++++++++++++++++++++++++++++++++++ v3/load/load_fallback.go | 2 +- v3/load/load_solaris.go | 44 ++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 90 insertions(+), 2 deletions(-) create mode 100644 load/load_solaris.go create mode 100644 v3/load/load_solaris.go diff --git a/load/load_fallback.go b/load/load_fallback.go index 1e3ade0..4642b44 100644 --- a/load/load_fallback.go +++ b/load/load_fallback.go @@ -1,4 +1,4 @@ -// +build !darwin,!linux,!freebsd,!openbsd,!windows +// +build !darwin,!linux,!freebsd,!openbsd,!windows,!solaris package load diff --git a/load/load_solaris.go b/load/load_solaris.go new file mode 100644 index 0000000..5cad05e --- /dev/null +++ b/load/load_solaris.go @@ -0,0 +1,44 @@ +// +build solaris + +package load + +import ( + "context" + "os/exec" + "strings" + + "github.com/shirou/gopsutil/internal/common" +) + +func Avg() (*AvgStat, error) { + return AvgWithContext(context.Background()) +} + +func AvgWithContext(ctx context.Context) (*AvgStat, error) { + return nil, common.ErrNotImplementedError +} + +func Misc() (*MiscStat, error) { + return MiscWithContext(context.Background()) +} + +func MiscWithContext(ctx context.Context) (*MiscStat, error) { + bin, err := exec.LookPath("ps") + if err != nil { + return nil, err + } + out, err := invoke.CommandWithContext(ctx, bin, "-efo", "s") + if err != nil { + return nil, err + } + lines := strings.Split(string(out), "\n") + + ret := MiscStat{} + for _, l := range lines { + if l == "O" { + ret.ProcsRunning++ + } + } + + return &ret, nil +} diff --git a/v3/load/load_fallback.go b/v3/load/load_fallback.go index 5092f96..631e0ff 100644 --- a/v3/load/load_fallback.go +++ b/v3/load/load_fallback.go @@ -1,4 +1,4 @@ -// +build !darwin,!linux,!freebsd,!openbsd,!windows +// +build !darwin,!linux,!freebsd,!openbsd,!windows,!solaris package load diff --git a/v3/load/load_solaris.go b/v3/load/load_solaris.go new file mode 100644 index 0000000..ae47dff --- /dev/null +++ b/v3/load/load_solaris.go @@ -0,0 +1,44 @@ +// +build solaris + +package load + +import ( + "context" + "os/exec" + "strings" + + "github.com/shirou/gopsutil/v3/internal/common" +) + +func Avg() (*AvgStat, error) { + return AvgWithContext(context.Background()) +} + +func AvgWithContext(ctx context.Context) (*AvgStat, error) { + return nil, common.ErrNotImplementedError +} + +func Misc() (*MiscStat, error) { + return MiscWithContext(context.Background()) +} + +func MiscWithContext(ctx context.Context) (*MiscStat, error) { + bin, err := exec.LookPath("ps") + if err != nil { + return nil, err + } + out, err := invoke.CommandWithContext(ctx, bin, "-efo", "s") + if err != nil { + return nil, err + } + lines := strings.Split(string(out), "\n") + + ret := MiscStat{} + for _, l := range lines { + if l == "O" { + ret.ProcsRunning++ + } + } + + return &ret, nil +}