vendorify
diff --git a/go/vendor/github.com/shirou/gopsutil/load/load.go b/go/vendor/github.com/shirou/gopsutil/load/load.go
new file mode 100644
index 0000000..9085889
--- /dev/null
+++ b/go/vendor/github.com/shirou/gopsutil/load/load.go
@@ -0,0 +1,31 @@
+package load
+
+import (
+ "encoding/json"
+
+ "github.com/shirou/gopsutil/internal/common"
+)
+
+var invoke common.Invoker = common.Invoke{}
+
+type AvgStat struct {
+ Load1 float64 `json:"load1"`
+ Load5 float64 `json:"load5"`
+ Load15 float64 `json:"load15"`
+}
+
+func (l AvgStat) String() string {
+ s, _ := json.Marshal(l)
+ return string(s)
+}
+
+type MiscStat struct {
+ ProcsRunning int `json:"procsRunning"`
+ ProcsBlocked int `json:"procsBlocked"`
+ Ctxt int `json:"ctxt"`
+}
+
+func (m MiscStat) String() string {
+ s, _ := json.Marshal(m)
+ return string(s)
+}
diff --git a/go/vendor/github.com/shirou/gopsutil/load/load_bsd.go b/go/vendor/github.com/shirou/gopsutil/load/load_bsd.go
new file mode 100644
index 0000000..dfac10c
--- /dev/null
+++ b/go/vendor/github.com/shirou/gopsutil/load/load_bsd.go
@@ -0,0 +1,68 @@
+// +build freebsd openbsd
+
+package load
+
+import (
+ "context"
+ "os/exec"
+ "strings"
+ "unsafe"
+
+ "golang.org/x/sys/unix"
+)
+
+func Avg() (*AvgStat, error) {
+ return AvgWithContext(context.Background())
+}
+
+func AvgWithContext(ctx context.Context) (*AvgStat, error) {
+ // This SysctlRaw method borrowed from
+ // https://github.com/prometheus/node_exporter/blob/master/collector/loadavg_freebsd.go
+ type loadavg struct {
+ load [3]uint32
+ scale int
+ }
+ b, err := unix.SysctlRaw("vm.loadavg")
+ if err != nil {
+ return nil, err
+ }
+ load := *(*loadavg)(unsafe.Pointer((&b[0])))
+ scale := float64(load.scale)
+ ret := &AvgStat{
+ Load1: float64(load.load[0]) / scale,
+ Load5: float64(load.load[1]) / scale,
+ Load15: float64(load.load[2]) / scale,
+ }
+
+ return ret, nil
+}
+
+// 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.
+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, "axo", "state")
+ if err != nil {
+ return nil, err
+ }
+ lines := strings.Split(string(out), "\n")
+
+ ret := MiscStat{}
+ for _, l := range lines {
+ if strings.Contains(l, "R") {
+ ret.ProcsRunning++
+ } else if strings.Contains(l, "D") {
+ ret.ProcsBlocked++
+ }
+ }
+
+ return &ret, nil
+}
diff --git a/go/vendor/github.com/shirou/gopsutil/load/load_darwin.go b/go/vendor/github.com/shirou/gopsutil/load/load_darwin.go
new file mode 100644
index 0000000..cd7b74d
--- /dev/null
+++ b/go/vendor/github.com/shirou/gopsutil/load/load_darwin.go
@@ -0,0 +1,76 @@
+// +build darwin
+
+package load
+
+import (
+ "context"
+ "os/exec"
+ "strconv"
+ "strings"
+
+ "github.com/shirou/gopsutil/internal/common"
+)
+
+func Avg() (*AvgStat, error) {
+ return AvgWithContext(context.Background())
+}
+
+func AvgWithContext(ctx context.Context) (*AvgStat, error) {
+ values, err := common.DoSysctrlWithContext(ctx, "vm.loadavg")
+ if err != nil {
+ return nil, err
+ }
+
+ load1, err := strconv.ParseFloat(values[0], 64)
+ if err != nil {
+ return nil, err
+ }
+ load5, err := strconv.ParseFloat(values[1], 64)
+ if err != nil {
+ return nil, err
+ }
+ load15, err := strconv.ParseFloat(values[2], 64)
+ if err != nil {
+ return nil, err
+ }
+
+ ret := &AvgStat{
+ Load1: float64(load1),
+ Load5: float64(load5),
+ Load15: float64(load15),
+ }
+
+ return ret, nil
+}
+
+// Misc returnes miscellaneous host-wide statistics.
+// darwin use ps command to get process running/blocked count.
+// Almost same as FreeBSD implementation, but state is different.
+// U means 'Uninterruptible Sleep'.
+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, "axo", "state")
+ if err != nil {
+ return nil, err
+ }
+ lines := strings.Split(string(out), "\n")
+
+ ret := MiscStat{}
+ for _, l := range lines {
+ if strings.Contains(l, "R") {
+ ret.ProcsRunning++
+ } else if strings.Contains(l, "U") {
+ // uninterruptible sleep == blocked
+ ret.ProcsBlocked++
+ }
+ }
+
+ return &ret, nil
+}
diff --git a/go/vendor/github.com/shirou/gopsutil/load/load_fallback.go b/go/vendor/github.com/shirou/gopsutil/load/load_fallback.go
new file mode 100644
index 0000000..1e3ade0
--- /dev/null
+++ b/go/vendor/github.com/shirou/gopsutil/load/load_fallback.go
@@ -0,0 +1,25 @@
+// +build !darwin,!linux,!freebsd,!openbsd,!windows
+
+package load
+
+import (
+ "context"
+
+ "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) {
+ return nil, common.ErrNotImplementedError
+}
diff --git a/go/vendor/github.com/shirou/gopsutil/load/load_linux.go b/go/vendor/github.com/shirou/gopsutil/load/load_linux.go
new file mode 100644
index 0000000..63c26a2
--- /dev/null
+++ b/go/vendor/github.com/shirou/gopsutil/load/load_linux.go
@@ -0,0 +1,87 @@
+// +build linux
+
+package load
+
+import (
+ "context"
+ "io/ioutil"
+ "strconv"
+ "strings"
+
+ "github.com/shirou/gopsutil/internal/common"
+)
+
+func Avg() (*AvgStat, error) {
+ return AvgWithContext(context.Background())
+}
+
+func AvgWithContext(ctx context.Context) (*AvgStat, error) {
+ filename := common.HostProc("loadavg")
+ line, err := ioutil.ReadFile(filename)
+ if err != nil {
+ return nil, err
+ }
+
+ values := strings.Fields(string(line))
+
+ load1, err := strconv.ParseFloat(values[0], 64)
+ if err != nil {
+ return nil, err
+ }
+ load5, err := strconv.ParseFloat(values[1], 64)
+ if err != nil {
+ return nil, err
+ }
+ load15, err := strconv.ParseFloat(values[2], 64)
+ if err != nil {
+ return nil, err
+ }
+
+ ret := &AvgStat{
+ Load1: load1,
+ Load5: load5,
+ Load15: load15,
+ }
+
+ return ret, nil
+}
+
+// Misc returnes miscellaneous host-wide statistics.
+// Note: the name should be changed near future.
+func Misc() (*MiscStat, error) {
+ return MiscWithContext(context.Background())
+}
+
+func MiscWithContext(ctx context.Context) (*MiscStat, error) {
+ filename := common.HostProc("stat")
+ out, err := ioutil.ReadFile(filename)
+ if err != nil {
+ return nil, err
+ }
+
+ ret := &MiscStat{}
+ lines := strings.Split(string(out), "\n")
+ for _, line := range lines {
+ fields := strings.Fields(line)
+ if len(fields) != 2 {
+ continue
+ }
+ v, err := strconv.ParseInt(fields[1], 10, 64)
+ if err != nil {
+ continue
+ }
+ switch fields[0] {
+ case "procs_running":
+ ret.ProcsRunning = int(v)
+ case "procs_blocked":
+ ret.ProcsBlocked = int(v)
+ case "ctxt":
+ ret.Ctxt = int(v)
+ default:
+ continue
+ }
+
+ }
+
+ return ret, nil
+}
diff --git a/go/vendor/github.com/shirou/gopsutil/load/load_windows.go b/go/vendor/github.com/shirou/gopsutil/load/load_windows.go
new file mode 100644
index 0000000..42968b3
--- /dev/null
+++ b/go/vendor/github.com/shirou/gopsutil/load/load_windows.go
@@ -0,0 +1,29 @@
+// +build windows
+
+package load
+
+import (
+ "context"
+
+ "github.com/shirou/gopsutil/internal/common"
+)
+
+func Avg() (*AvgStat, error) {
+ return AvgWithContext(context.Background())
+}
+
+func AvgWithContext(ctx context.Context) (*AvgStat, error) {
+ ret := AvgStat{}
+
+ return &ret, common.ErrNotImplementedError
+}
+
+func Misc() (*MiscStat, error) {
+ return MiscWithContext(context.Background())
+}
+
+func MiscWithContext(ctx context.Context) (*MiscStat, error) {
+ ret := MiscStat{}
+
+ return &ret, common.ErrNotImplementedError
+}