Update gopsutil dependency

closes #1233
This commit is contained in:
Cameron Sparr
2016-05-19 15:05:08 +01:00
parent f176c28a56
commit 56aee1ceee
10 changed files with 62 additions and 61 deletions

View File

@@ -71,7 +71,7 @@ func (p *SpecProcessor) pushMetrics() {
fields[prefix+"write_bytes"] = io.WriteCount
}
cpu_time, err := p.proc.CPUTimes()
cpu_time, err := p.proc.Times()
if err == nil {
fields[prefix+"cpu_time_user"] = cpu_time.User
fields[prefix+"cpu_time_system"] = cpu_time.System
@@ -86,7 +86,7 @@ func (p *SpecProcessor) pushMetrics() {
fields[prefix+"cpu_time_guest_nice"] = cpu_time.GuestNice
}
cpu_perc, err := p.proc.CPUPercent(time.Duration(0))
cpu_perc, err := p.proc.Percent(time.Duration(0))
if err == nil && cpu_perc != 0 {
fields[prefix+"cpu_usage"] = cpu_perc
}

View File

@@ -11,7 +11,7 @@ import (
type CPUStats struct {
ps PS
lastStats []cpu.CPUTimesStat
lastStats []cpu.TimesStat
PerCPU bool `toml:"percpu"`
TotalCPU bool `toml:"totalcpu"`
@@ -105,7 +105,7 @@ func (s *CPUStats) Gather(acc telegraf.Accumulator) error {
return nil
}
func totalCpuTime(t cpu.CPUTimesStat) float64 {
func totalCpuTime(t cpu.TimesStat) float64 {
total := t.User + t.System + t.Nice + t.Iowait + t.Irq + t.Softirq + t.Steal +
t.Guest + t.GuestNice + t.Idle
return total

View File

@@ -15,7 +15,7 @@ func TestCPUStats(t *testing.T) {
defer mps.AssertExpectations(t)
var acc testutil.Accumulator
cts := cpu.CPUTimesStat{
cts := cpu.TimesStat{
CPU: "cpu0",
User: 3.1,
System: 8.2,
@@ -29,7 +29,7 @@ func TestCPUStats(t *testing.T) {
GuestNice: 0.324,
}
cts2 := cpu.CPUTimesStat{
cts2 := cpu.TimesStat{
CPU: "cpu0",
User: 11.4, // increased by 8.3
System: 10.9, // increased by 2.7
@@ -43,7 +43,7 @@ func TestCPUStats(t *testing.T) {
GuestNice: 2.524, // increased by 2.2
}
mps.On("CPUTimes").Return([]cpu.CPUTimesStat{cts}, nil)
mps.On("CPUTimes").Return([]cpu.TimesStat{cts}, nil)
cs := NewCPUStats(&mps)
@@ -68,7 +68,7 @@ func TestCPUStats(t *testing.T) {
assertContainsTaggedFloat(t, &acc, "cpu", "time_guest_nice", 0.324, 0, cputags)
mps2 := MockPS{}
mps2.On("CPUTimes").Return([]cpu.CPUTimesStat{cts2}, nil)
mps2.On("CPUTimes").Return([]cpu.TimesStat{cts2}, nil)
cs.ps = &mps2
// Should have added cpu percentages too

View File

@@ -15,7 +15,7 @@ func TestDiskStats(t *testing.T) {
var acc testutil.Accumulator
var err error
duAll := []*disk.DiskUsageStat{
duAll := []*disk.UsageStat{
{
Path: "/",
Fstype: "ext4",
@@ -37,7 +37,7 @@ func TestDiskStats(t *testing.T) {
InodesUsed: 2000,
},
}
duFiltered := []*disk.DiskUsageStat{
duFiltered := []*disk.UsageStat{
{
Path: "/",
Fstype: "ext4",
@@ -108,7 +108,7 @@ func TestDiskStats(t *testing.T) {
// var acc testutil.Accumulator
// var err error
// diskio1 := disk.DiskIOCountersStat{
// diskio1 := disk.IOCountersStat{
// ReadCount: 888,
// WriteCount: 5341,
// ReadBytes: 100000,
@@ -119,7 +119,7 @@ func TestDiskStats(t *testing.T) {
// IoTime: 123552,
// SerialNumber: "ab-123-ad",
// }
// diskio2 := disk.DiskIOCountersStat{
// diskio2 := disk.IOCountersStat{
// ReadCount: 444,
// WriteCount: 2341,
// ReadBytes: 200000,
@@ -132,7 +132,7 @@ func TestDiskStats(t *testing.T) {
// }
// mps.On("DiskIO").Return(
// map[string]disk.DiskIOCountersStat{"sda1": diskio1, "sdb1": diskio2},
// map[string]disk.IOCountersStat{"sda1": diskio1, "sdb1": diskio2},
// nil)
// err = (&DiskIOStats{ps: &mps}).Gather(&acc)

View File

@@ -15,55 +15,55 @@ type MockPS struct {
mock.Mock
}
func (m *MockPS) LoadAvg() (*load.LoadAvgStat, error) {
func (m *MockPS) LoadAvg() (*load.AvgStat, error) {
ret := m.Called()
r0 := ret.Get(0).(*load.LoadAvgStat)
r0 := ret.Get(0).(*load.AvgStat)
r1 := ret.Error(1)
return r0, r1
}
func (m *MockPS) CPUTimes(perCPU, totalCPU bool) ([]cpu.CPUTimesStat, error) {
func (m *MockPS) CPUTimes(perCPU, totalCPU bool) ([]cpu.TimesStat, error) {
ret := m.Called()
r0 := ret.Get(0).([]cpu.CPUTimesStat)
r0 := ret.Get(0).([]cpu.TimesStat)
r1 := ret.Error(1)
return r0, r1
}
func (m *MockPS) DiskUsage(mountPointFilter []string, fstypeExclude []string) ([]*disk.DiskUsageStat, error) {
func (m *MockPS) DiskUsage(mountPointFilter []string, fstypeExclude []string) ([]*disk.UsageStat, error) {
ret := m.Called(mountPointFilter, fstypeExclude)
r0 := ret.Get(0).([]*disk.DiskUsageStat)
r0 := ret.Get(0).([]*disk.UsageStat)
r1 := ret.Error(1)
return r0, r1
}
func (m *MockPS) NetIO() ([]net.NetIOCountersStat, error) {
func (m *MockPS) NetIO() ([]net.IOCountersStat, error) {
ret := m.Called()
r0 := ret.Get(0).([]net.NetIOCountersStat)
r0 := ret.Get(0).([]net.IOCountersStat)
r1 := ret.Error(1)
return r0, r1
}
func (m *MockPS) NetProto() ([]net.NetProtoCountersStat, error) {
func (m *MockPS) NetProto() ([]net.ProtoCountersStat, error) {
ret := m.Called()
r0 := ret.Get(0).([]net.NetProtoCountersStat)
r0 := ret.Get(0).([]net.ProtoCountersStat)
r1 := ret.Error(1)
return r0, r1
}
func (m *MockPS) DiskIO() (map[string]disk.DiskIOCountersStat, error) {
func (m *MockPS) DiskIO() (map[string]disk.IOCountersStat, error) {
ret := m.Called()
r0 := ret.Get(0).(map[string]disk.DiskIOCountersStat)
r0 := ret.Get(0).(map[string]disk.IOCountersStat)
r1 := ret.Error(1)
return r0, r1
@@ -87,10 +87,10 @@ func (m *MockPS) SwapStat() (*mem.SwapMemoryStat, error) {
return r0, r1
}
func (m *MockPS) NetConnections() ([]net.NetConnectionStat, error) {
func (m *MockPS) NetConnections() ([]net.ConnectionStat, error) {
ret := m.Called()
r0 := ret.Get(0).([]net.NetConnectionStat)
r0 := ret.Get(0).([]net.ConnectionStat)
r1 := ret.Error(1)
return r0, r1

View File

@@ -15,7 +15,7 @@ func TestNetStats(t *testing.T) {
defer mps.AssertExpectations(t)
var acc testutil.Accumulator
netio := net.NetIOCountersStat{
netio := net.IOCountersStat{
Name: "eth0",
BytesSent: 1123,
BytesRecv: 8734422,
@@ -27,10 +27,10 @@ func TestNetStats(t *testing.T) {
Dropout: 1,
}
mps.On("NetIO").Return([]net.NetIOCountersStat{netio}, nil)
mps.On("NetIO").Return([]net.IOCountersStat{netio}, nil)
netprotos := []net.NetProtoCountersStat{
net.NetProtoCountersStat{
netprotos := []net.ProtoCountersStat{
net.ProtoCountersStat{
Protocol: "Udp",
Stats: map[string]int64{
"InDatagrams": 4655,
@@ -40,17 +40,17 @@ func TestNetStats(t *testing.T) {
}
mps.On("NetProto").Return(netprotos, nil)
netstats := []net.NetConnectionStat{
net.NetConnectionStat{
netstats := []net.ConnectionStat{
net.ConnectionStat{
Type: syscall.SOCK_DGRAM,
},
net.NetConnectionStat{
net.ConnectionStat{
Status: "ESTABLISHED",
},
net.NetConnectionStat{
net.ConnectionStat{
Status: "ESTABLISHED",
},
net.NetConnectionStat{
net.ConnectionStat{
Status: "CLOSE",
},
}

View File

@@ -13,14 +13,14 @@ import (
)
type PS interface {
CPUTimes(perCPU, totalCPU bool) ([]cpu.CPUTimesStat, error)
DiskUsage(mountPointFilter []string, fstypeExclude []string) ([]*disk.DiskUsageStat, error)
NetIO() ([]net.NetIOCountersStat, error)
NetProto() ([]net.NetProtoCountersStat, error)
DiskIO() (map[string]disk.DiskIOCountersStat, error)
CPUTimes(perCPU, totalCPU bool) ([]cpu.TimesStat, error)
DiskUsage(mountPointFilter []string, fstypeExclude []string) ([]*disk.UsageStat, error)
NetIO() ([]net.IOCountersStat, error)
NetProto() ([]net.ProtoCountersStat, error)
DiskIO() (map[string]disk.IOCountersStat, error)
VMStat() (*mem.VirtualMemoryStat, error)
SwapStat() (*mem.SwapMemoryStat, error)
NetConnections() ([]net.NetConnectionStat, error)
NetConnections() ([]net.ConnectionStat, error)
}
func add(acc telegraf.Accumulator,
@@ -32,17 +32,17 @@ func add(acc telegraf.Accumulator,
type systemPS struct{}
func (s *systemPS) CPUTimes(perCPU, totalCPU bool) ([]cpu.CPUTimesStat, error) {
var cpuTimes []cpu.CPUTimesStat
func (s *systemPS) CPUTimes(perCPU, totalCPU bool) ([]cpu.TimesStat, error) {
var cpuTimes []cpu.TimesStat
if perCPU {
if perCPUTimes, err := cpu.CPUTimes(true); err == nil {
if perCPUTimes, err := cpu.Times(true); err == nil {
cpuTimes = append(cpuTimes, perCPUTimes...)
} else {
return nil, err
}
}
if totalCPU {
if totalCPUTimes, err := cpu.CPUTimes(false); err == nil {
if totalCPUTimes, err := cpu.Times(false); err == nil {
cpuTimes = append(cpuTimes, totalCPUTimes...)
} else {
return nil, err
@@ -54,8 +54,8 @@ func (s *systemPS) CPUTimes(perCPU, totalCPU bool) ([]cpu.CPUTimesStat, error) {
func (s *systemPS) DiskUsage(
mountPointFilter []string,
fstypeExclude []string,
) ([]*disk.DiskUsageStat, error) {
parts, err := disk.DiskPartitions(true)
) ([]*disk.UsageStat, error) {
parts, err := disk.Partitions(true)
if err != nil {
return nil, err
}
@@ -70,7 +70,7 @@ func (s *systemPS) DiskUsage(
fstypeExcludeSet[filter] = true
}
var usage []*disk.DiskUsageStat
var usage []*disk.UsageStat
for _, p := range parts {
if len(mountPointFilter) > 0 {
@@ -83,7 +83,7 @@ func (s *systemPS) DiskUsage(
}
mountpoint := os.Getenv("HOST_MOUNT_PREFIX") + p.Mountpoint
if _, err := os.Stat(mountpoint); err == nil {
du, err := disk.DiskUsage(mountpoint)
du, err := disk.Usage(mountpoint)
du.Path = p.Mountpoint
if err != nil {
return nil, err
@@ -102,20 +102,20 @@ func (s *systemPS) DiskUsage(
return usage, nil
}
func (s *systemPS) NetProto() ([]net.NetProtoCountersStat, error) {
return net.NetProtoCounters(nil)
func (s *systemPS) NetProto() ([]net.ProtoCountersStat, error) {
return net.ProtoCounters(nil)
}
func (s *systemPS) NetIO() ([]net.NetIOCountersStat, error) {
return net.NetIOCounters(true)
func (s *systemPS) NetIO() ([]net.IOCountersStat, error) {
return net.IOCounters(true)
}
func (s *systemPS) NetConnections() ([]net.NetConnectionStat, error) {
return net.NetConnections("all")
func (s *systemPS) NetConnections() ([]net.ConnectionStat, error) {
return net.Connections("all")
}
func (s *systemPS) DiskIO() (map[string]disk.DiskIOCountersStat, error) {
m, err := disk.DiskIOCounters()
func (s *systemPS) DiskIO() (map[string]disk.IOCountersStat, error) {
m, err := disk.IOCounters()
if err == internal.NotImplementedError {
return nil, nil
}

View File

@@ -22,12 +22,12 @@ func (_ *SystemStats) Description() string {
func (_ *SystemStats) SampleConfig() string { return "" }
func (_ *SystemStats) Gather(acc telegraf.Accumulator) error {
loadavg, err := load.LoadAvg()
loadavg, err := load.Avg()
if err != nil {
return err
}
hostinfo, err := host.HostInfo()
hostinfo, err := host.Info()
if err != nil {
return err
}