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

[load][solaris] support MiscStat.ProcsRunning #1074

Merged
merged 1 commit into from
May 29, 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
2 changes: 1 addition & 1 deletion load/load_fallback.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// +build !darwin,!linux,!freebsd,!openbsd,!windows
// +build !darwin,!linux,!freebsd,!openbsd,!windows,!solaris

package load

Expand Down
44 changes: 44 additions & 0 deletions load/load_solaris.go
Original file line number Diff line number Diff line change
@@ -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
}
2 changes: 1 addition & 1 deletion v3/load/load_fallback.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// +build !darwin,!linux,!freebsd,!openbsd,!windows
// +build !darwin,!linux,!freebsd,!openbsd,!windows,!solaris

package load

Expand Down
44 changes: 44 additions & 0 deletions v3/load/load_solaris.go
Original file line number Diff line number Diff line change
@@ -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
}