From 56aee1ceeedd1865f2ac3d3352bad5d360afd1ca Mon Sep 17 00:00:00 2001 From: Cameron Sparr Date: Thu, 19 May 2016 15:05:08 +0100 Subject: [PATCH] Update gopsutil dependency closes #1233 --- CHANGELOG.md | 1 + Godeps | 2 +- plugins/inputs/procstat/spec_processor.go | 4 +-- plugins/inputs/system/cpu.go | 4 +-- plugins/inputs/system/cpu_test.go | 8 ++--- plugins/inputs/system/disk_test.go | 10 +++--- plugins/inputs/system/mock_PS.go | 28 +++++++-------- plugins/inputs/system/net_test.go | 18 +++++----- plugins/inputs/system/ps.go | 44 +++++++++++------------ plugins/inputs/system/system.go | 4 +-- 10 files changed, 62 insertions(+), 61 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 46b46a5d0..6ac72ef12 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ - [#1138](https://github.com/influxdata/telegraf/pull/1138): nstat input plugin. Thanks @Maksadbek! - [#1139](https://github.com/influxdata/telegraf/pull/1139): instrumental output plugin. Thanks @jasonroelofs! - [#1172](https://github.com/influxdata/telegraf/pull/1172): Ceph storage stats. Thanks @robinpercy! +- [#1233](https://github.com/influxdata/telegraf/pull/1233): Updated golint gopsutil dependency. ### Bugfixes diff --git a/Godeps b/Godeps index 60fe99840..59c09d514 100644 --- a/Godeps +++ b/Godeps @@ -42,7 +42,7 @@ github.com/prometheus/client_model fa8ad6fec33561be4280a8f0514318c79d7f6cb6 github.com/prometheus/common e8eabff8812b05acf522b45fdcd725a785188e37 github.com/prometheus/procfs 406e5b7bfd8201a36e2bb5f7bdae0b03380c2ce8 github.com/samuel/go-zookeeper 218e9c81c0dd8b3b18172b2bbfad92cc7d6db55f -github.com/shirou/gopsutil 37d89088411de59a4ef9fc340afa0e89dfcb4ea9 +github.com/shirou/gopsutil bae75faa5ad1212d3e80f11f5e9cd147c6be9198 github.com/soniah/gosnmp b1b4f885b12c5dcbd021c5cee1c904110de6db7d github.com/streadway/amqp b4f3ceab0337f013208d31348b578d83c0064744 github.com/stretchr/testify 1f4a1643a57e798696635ea4c126e9127adb7d3c diff --git a/plugins/inputs/procstat/spec_processor.go b/plugins/inputs/procstat/spec_processor.go index 18cc286fc..0e73b60e9 100644 --- a/plugins/inputs/procstat/spec_processor.go +++ b/plugins/inputs/procstat/spec_processor.go @@ -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 } diff --git a/plugins/inputs/system/cpu.go b/plugins/inputs/system/cpu.go index 035b8e1f5..8fc9739ba 100644 --- a/plugins/inputs/system/cpu.go +++ b/plugins/inputs/system/cpu.go @@ -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 diff --git a/plugins/inputs/system/cpu_test.go b/plugins/inputs/system/cpu_test.go index 0db92d39b..f1f659e6f 100644 --- a/plugins/inputs/system/cpu_test.go +++ b/plugins/inputs/system/cpu_test.go @@ -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 diff --git a/plugins/inputs/system/disk_test.go b/plugins/inputs/system/disk_test.go index 0a722148b..71c9bff1b 100644 --- a/plugins/inputs/system/disk_test.go +++ b/plugins/inputs/system/disk_test.go @@ -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) diff --git a/plugins/inputs/system/mock_PS.go b/plugins/inputs/system/mock_PS.go index fd6afda0f..f10cc94c0 100644 --- a/plugins/inputs/system/mock_PS.go +++ b/plugins/inputs/system/mock_PS.go @@ -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 diff --git a/plugins/inputs/system/net_test.go b/plugins/inputs/system/net_test.go index 0391a005a..5eb30fe4f 100644 --- a/plugins/inputs/system/net_test.go +++ b/plugins/inputs/system/net_test.go @@ -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", }, } diff --git a/plugins/inputs/system/ps.go b/plugins/inputs/system/ps.go index 9602acd55..23bfe1628 100644 --- a/plugins/inputs/system/ps.go +++ b/plugins/inputs/system/ps.go @@ -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 } diff --git a/plugins/inputs/system/system.go b/plugins/inputs/system/system.go index 55e606225..ff64740bf 100644 --- a/plugins/inputs/system/system.go +++ b/plugins/inputs/system/system.go @@ -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 }