Skip to content

Commit

Permalink
Merge pull request #1074 from scop/feat/solaris-load-procsrunning
Browse files Browse the repository at this point in the history
[load][solaris] support MiscStat.ProcsRunning
  • Loading branch information
shirou authored May 29, 2021
2 parents 7ffa844 + eab3aea commit b76e0ff
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 2 deletions.
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
}

0 comments on commit b76e0ff

Please sign in to comment.