Vendor psutils and remove neko

This commit is contained in:
Evan Phoenix
2015-04-03 17:22:31 -07:00
parent db74acb86d
commit 9c42aea28c
84 changed files with 9370 additions and 74 deletions

View 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)
}

View 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
}

View 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
}

View 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
}

View 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)
}
}

View 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
}