Vendor psutils and remove neko
This commit is contained in:
16
plugins/system/ps/load/load.go
Normal file
16
plugins/system/ps/load/load.go
Normal file
@@ -0,0 +1,16 @@
|
||||
package load
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
)
|
||||
|
||||
type LoadAvgStat struct {
|
||||
Load1 float64 `json:"load1"`
|
||||
Load5 float64 `json:"load5"`
|
||||
Load15 float64 `json:"load15"`
|
||||
}
|
||||
|
||||
func (l LoadAvgStat) String() string {
|
||||
s, _ := json.Marshal(l)
|
||||
return string(s)
|
||||
}
|
||||
37
plugins/system/ps/load/load_darwin.go
Normal file
37
plugins/system/ps/load/load_darwin.go
Normal file
@@ -0,0 +1,37 @@
|
||||
// +build darwin
|
||||
|
||||
package load
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
|
||||
common "github.com/shirou/gopsutil/common"
|
||||
)
|
||||
|
||||
func LoadAvg() (*LoadAvgStat, error) {
|
||||
values, err := common.DoSysctrl("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 := &LoadAvgStat{
|
||||
Load1: float64(load1),
|
||||
Load5: float64(load5),
|
||||
Load15: float64(load15),
|
||||
}
|
||||
|
||||
return ret, nil
|
||||
}
|
||||
37
plugins/system/ps/load/load_freebsd.go
Normal file
37
plugins/system/ps/load/load_freebsd.go
Normal file
@@ -0,0 +1,37 @@
|
||||
// +build freebsd
|
||||
|
||||
package load
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
|
||||
common "github.com/shirou/gopsutil/common"
|
||||
)
|
||||
|
||||
func LoadAvg() (*LoadAvgStat, error) {
|
||||
values, err := common.DoSysctrl("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 := &LoadAvgStat{
|
||||
Load1: float64(load1),
|
||||
Load5: float64(load5),
|
||||
Load15: float64(load15),
|
||||
}
|
||||
|
||||
return ret, nil
|
||||
}
|
||||
40
plugins/system/ps/load/load_linux.go
Normal file
40
plugins/system/ps/load/load_linux.go
Normal file
@@ -0,0 +1,40 @@
|
||||
// +build linux
|
||||
|
||||
package load
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func LoadAvg() (*LoadAvgStat, error) {
|
||||
filename := "/proc/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 := &LoadAvgStat{
|
||||
Load1: load1,
|
||||
Load5: load5,
|
||||
Load15: load15,
|
||||
}
|
||||
|
||||
return ret, nil
|
||||
}
|
||||
30
plugins/system/ps/load/load_test.go
Normal file
30
plugins/system/ps/load/load_test.go
Normal file
@@ -0,0 +1,30 @@
|
||||
package load
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestLoad(t *testing.T) {
|
||||
v, err := LoadAvg()
|
||||
if err != nil {
|
||||
t.Errorf("error %v", err)
|
||||
}
|
||||
|
||||
empty := &LoadAvgStat{}
|
||||
if v == empty {
|
||||
t.Errorf("error load: %v", v)
|
||||
}
|
||||
}
|
||||
|
||||
func TestLoadAvgStat_String(t *testing.T) {
|
||||
v := LoadAvgStat{
|
||||
Load1: 10.1,
|
||||
Load5: 20.1,
|
||||
Load15: 30.1,
|
||||
}
|
||||
e := `{"load1":10.1,"load5":20.1,"load15":30.1}`
|
||||
if e != fmt.Sprintf("%v", v) {
|
||||
t.Errorf("LoadAvgStat string is invalid: %v", v)
|
||||
}
|
||||
}
|
||||
13
plugins/system/ps/load/load_windows.go
Normal file
13
plugins/system/ps/load/load_windows.go
Normal file
@@ -0,0 +1,13 @@
|
||||
// +build windows
|
||||
|
||||
package load
|
||||
|
||||
import (
|
||||
common "github.com/shirou/gopsutil/common"
|
||||
)
|
||||
|
||||
func LoadAvg() (*LoadAvgStat, error) {
|
||||
ret := LoadAvgStat{}
|
||||
|
||||
return &ret, common.NotImplementedError
|
||||
}
|
||||
Reference in New Issue
Block a user