From 74602a634dc4f7063b3328acf2a5927303913bb7 Mon Sep 17 00:00:00 2001 From: Steve Domino Date: Wed, 11 Jul 2018 17:43:49 -0600 Subject: [PATCH] Moved system package inputs out to top level (#4406) --- plugins/inputs/all/all.go | 10 ++++++ .../{system/CPU_README.md => cpu/README.md} | 0 plugins/inputs/{system => cpu}/cpu.go | 9 +++--- plugins/inputs/{system => cpu}/cpu_test.go | 17 +++++----- .../{system/DISK_README.md => disk/README.md} | 0 plugins/inputs/{system => disk}/disk.go | 7 ++-- plugins/inputs/{system => disk}/disk_test.go | 9 +++--- .../DISKIO_README.md => diskio/README.md} | 0 plugins/inputs/{system => diskio}/diskio.go | 7 ++-- .../inputs/{system => diskio}/diskio_linux.go | 2 +- .../{system => diskio}/diskio_linux_test.go | 2 +- .../inputs/{system => diskio}/diskio_other.go | 2 +- .../inputs/{system => diskio}/diskio_test.go | 5 +-- .../KERNEL_README.md => kernel/README.md} | 0 plugins/inputs/{system => kernel}/kernel.go | 2 +- .../{system => kernel}/kernel_notlinux.go | 2 +- .../inputs/{system => kernel}/kernel_test.go | 4 +-- .../README.md} | 0 .../kernel_vmstat.go | 2 +- .../kernel_vmstat/kernel_vmstat_notlinux.go | 3 ++ .../kernel_vmstat_test.go | 10 +++--- .../README.md} | 0 .../linux_sysctl_fs.go | 2 +- .../linux_sysctl_fs_test.go | 2 +- .../{system/MEM_README.md => mem/README.md} | 0 plugins/inputs/{system => mem}/memory.go | 7 ++-- plugins/inputs/{system => mem}/memory_test.go | 5 +-- .../inputs/{system => net}/NETSTAT_README.md | 19 +++++++---- plugins/inputs/{system => net}/NET_README.md | 0 plugins/inputs/{system => net}/net.go | 7 ++-- plugins/inputs/{system => net}/net_test.go | 5 +-- plugins/inputs/{system => net}/netstat.go | 7 ++-- .../README.md} | 0 .../inputs/{system => processes}/processes.go | 5 +-- .../{system => processes}/processes_test.go | 4 ++- plugins/inputs/processes/processes_windows.go | 3 ++ .../{system/SWAP_README.md => swap/README.md} | 0 plugins/inputs/{system => swap}/swap.go | 7 ++-- plugins/inputs/{system => swap}/swap_test.go | 5 +-- .../system/{SYSTEM_README.md => README.md} | 0 plugins/inputs/system/mock_PS.go | 12 +++---- plugins/inputs/system/ps.go | 32 +++++++++---------- 42 files changed, 126 insertions(+), 89 deletions(-) rename plugins/inputs/{system/CPU_README.md => cpu/README.md} (100%) rename plugins/inputs/{system => cpu}/cpu.go (95%) rename plugins/inputs/{system => cpu}/cpu_test.go (97%) rename plugins/inputs/{system/DISK_README.md => disk/README.md} (100%) rename plugins/inputs/{system => disk}/disk.go (95%) rename plugins/inputs/{system => disk}/disk_test.go (96%) rename plugins/inputs/{system/DISKIO_README.md => diskio/README.md} (100%) rename plugins/inputs/{system => diskio}/diskio.go (97%) rename plugins/inputs/{system => diskio}/diskio_linux.go (98%) rename plugins/inputs/{system => diskio}/diskio_linux_test.go (99%) rename plugins/inputs/{system => diskio}/diskio_other.go (90%) rename plugins/inputs/{system => diskio}/diskio_test.go (96%) rename plugins/inputs/{system/KERNEL_README.md => kernel/README.md} (100%) rename plugins/inputs/{system => kernel}/kernel.go (99%) rename plugins/inputs/{system => kernel}/kernel_notlinux.go (96%) rename plugins/inputs/{system => kernel}/kernel_test.go (98%) rename plugins/inputs/{system/KERNEL_VMSTAT_README.md => kernel_vmstat/README.md} (100%) rename plugins/inputs/{system => kernel_vmstat}/kernel_vmstat.go (98%) create mode 100644 plugins/inputs/kernel_vmstat/kernel_vmstat_notlinux.go rename plugins/inputs/{system => kernel_vmstat}/kernel_vmstat_test.go (97%) rename plugins/inputs/{system/LINUX_SYSCTL_FS_README.md => linux_sysctl_fs/README.md} (100%) rename plugins/inputs/{system => linux_sysctl_fs}/linux_sysctl_fs.go (98%) rename plugins/inputs/{system => linux_sysctl_fs}/linux_sysctl_fs_test.go (98%) rename plugins/inputs/{system/MEM_README.md => mem/README.md} (100%) rename plugins/inputs/{system => mem}/memory.go (90%) rename plugins/inputs/{system => mem}/memory_test.go (93%) rename plugins/inputs/{system => net}/NETSTAT_README.md (67%) rename plugins/inputs/{system => net}/NET_README.md (100%) rename plugins/inputs/{system => net}/net.go (95%) rename plugins/inputs/{system => net}/net_test.go (96%) rename plugins/inputs/{system => net}/netstat.go (92%) rename plugins/inputs/{system/PROCESSES_README.md => processes/README.md} (100%) rename plugins/inputs/{system => processes}/processes.go (97%) rename plugins/inputs/{system => processes}/processes_test.go (98%) create mode 100644 plugins/inputs/processes/processes_windows.go rename plugins/inputs/{system/SWAP_README.md => swap/README.md} (100%) rename plugins/inputs/{system => swap}/swap.go (88%) rename plugins/inputs/{system => swap}/swap_test.go (89%) rename plugins/inputs/system/{SYSTEM_README.md => README.md} (100%) diff --git a/plugins/inputs/all/all.go b/plugins/inputs/all/all.go index b2be2be5a55ca..594e0ea422c3a 100644 --- a/plugins/inputs/all/all.go +++ b/plugins/inputs/all/all.go @@ -17,7 +17,10 @@ import ( _ "github.com/influxdata/telegraf/plugins/inputs/consul" _ "github.com/influxdata/telegraf/plugins/inputs/couchbase" _ "github.com/influxdata/telegraf/plugins/inputs/couchdb" + _ "github.com/influxdata/telegraf/plugins/inputs/cpu" _ "github.com/influxdata/telegraf/plugins/inputs/dcos" + _ "github.com/influxdata/telegraf/plugins/inputs/disk" + _ "github.com/influxdata/telegraf/plugins/inputs/diskio" _ "github.com/influxdata/telegraf/plugins/inputs/disque" _ "github.com/influxdata/telegraf/plugins/inputs/dmcache" _ "github.com/influxdata/telegraf/plugins/inputs/dns_query" @@ -48,12 +51,16 @@ import ( _ "github.com/influxdata/telegraf/plugins/inputs/kafka_consumer" _ "github.com/influxdata/telegraf/plugins/inputs/kafka_consumer_legacy" _ "github.com/influxdata/telegraf/plugins/inputs/kapacitor" + _ "github.com/influxdata/telegraf/plugins/inputs/kernel" + _ "github.com/influxdata/telegraf/plugins/inputs/kernel_vmstat" _ "github.com/influxdata/telegraf/plugins/inputs/kubernetes" _ "github.com/influxdata/telegraf/plugins/inputs/leofs" + _ "github.com/influxdata/telegraf/plugins/inputs/linux_sysctl_fs" _ "github.com/influxdata/telegraf/plugins/inputs/logparser" _ "github.com/influxdata/telegraf/plugins/inputs/lustre2" _ "github.com/influxdata/telegraf/plugins/inputs/mailchimp" _ "github.com/influxdata/telegraf/plugins/inputs/mcrouter" + _ "github.com/influxdata/telegraf/plugins/inputs/mem" _ "github.com/influxdata/telegraf/plugins/inputs/memcached" _ "github.com/influxdata/telegraf/plugins/inputs/mesos" _ "github.com/influxdata/telegraf/plugins/inputs/minecraft" @@ -62,6 +69,7 @@ import ( _ "github.com/influxdata/telegraf/plugins/inputs/mysql" _ "github.com/influxdata/telegraf/plugins/inputs/nats" _ "github.com/influxdata/telegraf/plugins/inputs/nats_consumer" + _ "github.com/influxdata/telegraf/plugins/inputs/net" _ "github.com/influxdata/telegraf/plugins/inputs/net_response" _ "github.com/influxdata/telegraf/plugins/inputs/nginx" _ "github.com/influxdata/telegraf/plugins/inputs/nginx_plus" @@ -80,6 +88,7 @@ import ( _ "github.com/influxdata/telegraf/plugins/inputs/postgresql" _ "github.com/influxdata/telegraf/plugins/inputs/postgresql_extensible" _ "github.com/influxdata/telegraf/plugins/inputs/powerdns" + _ "github.com/influxdata/telegraf/plugins/inputs/processes" _ "github.com/influxdata/telegraf/plugins/inputs/procstat" _ "github.com/influxdata/telegraf/plugins/inputs/prometheus" _ "github.com/influxdata/telegraf/plugins/inputs/puppetagent" @@ -97,6 +106,7 @@ import ( _ "github.com/influxdata/telegraf/plugins/inputs/solr" _ "github.com/influxdata/telegraf/plugins/inputs/sqlserver" _ "github.com/influxdata/telegraf/plugins/inputs/statsd" + _ "github.com/influxdata/telegraf/plugins/inputs/swap" _ "github.com/influxdata/telegraf/plugins/inputs/syslog" _ "github.com/influxdata/telegraf/plugins/inputs/sysstat" _ "github.com/influxdata/telegraf/plugins/inputs/system" diff --git a/plugins/inputs/system/CPU_README.md b/plugins/inputs/cpu/README.md similarity index 100% rename from plugins/inputs/system/CPU_README.md rename to plugins/inputs/cpu/README.md diff --git a/plugins/inputs/system/cpu.go b/plugins/inputs/cpu/cpu.go similarity index 95% rename from plugins/inputs/system/cpu.go rename to plugins/inputs/cpu/cpu.go index 99fa451b37e3a..e073309e47e3b 100644 --- a/plugins/inputs/system/cpu.go +++ b/plugins/inputs/cpu/cpu.go @@ -1,4 +1,4 @@ -package system +package cpu import ( "fmt" @@ -6,11 +6,12 @@ import ( "github.com/influxdata/telegraf" "github.com/influxdata/telegraf/plugins/inputs" + "github.com/influxdata/telegraf/plugins/inputs/system" "github.com/shirou/gopsutil/cpu" ) type CPUStats struct { - ps PS + ps system.PS lastStats map[string]cpu.TimesStat PerCPU bool `toml:"percpu"` @@ -19,7 +20,7 @@ type CPUStats struct { ReportActive bool `toml:"report_active"` } -func NewCPUStats(ps PS) *CPUStats { +func NewCPUStats(ps system.PS) *CPUStats { return &CPUStats{ ps: ps, CollectCPUTime: true, @@ -146,7 +147,7 @@ func init() { return &CPUStats{ PerCPU: true, TotalCPU: true, - ps: newSystemPS(), + ps: system.NewSystemPS(), } }) } diff --git a/plugins/inputs/system/cpu_test.go b/plugins/inputs/cpu/cpu_test.go similarity index 97% rename from plugins/inputs/system/cpu_test.go rename to plugins/inputs/cpu/cpu_test.go index 43825fca7dc85..b4a6f87ffa8d3 100644 --- a/plugins/inputs/system/cpu_test.go +++ b/plugins/inputs/cpu/cpu_test.go @@ -1,9 +1,10 @@ -package system +package cpu import ( "fmt" "testing" + "github.com/influxdata/telegraf/plugins/inputs/system" "github.com/influxdata/telegraf/testutil" "github.com/shirou/gopsutil/cpu" "github.com/stretchr/testify/assert" @@ -11,7 +12,7 @@ import ( ) func TestCPUStats(t *testing.T) { - var mps MockPS + var mps system.MockPS defer mps.AssertExpectations(t) var acc testutil.Accumulator @@ -68,7 +69,7 @@ func TestCPUStats(t *testing.T) { assertContainsTaggedFloat(t, &acc, "cpu", "time_guest", 3.1, 0, cputags) assertContainsTaggedFloat(t, &acc, "cpu", "time_guest_nice", 0.324, 0, cputags) - mps2 := MockPS{} + mps2 := system.MockPS{} mps2.On("CPUTimes").Return([]cpu.TimesStat{cts2}, nil) cs.ps = &mps2 @@ -153,8 +154,8 @@ func assertContainsTaggedFloat( // TestCPUCountChange tests that no errors are encountered if the number of // CPUs increases as reported with LXC. func TestCPUCountIncrease(t *testing.T) { - var mps MockPS - var mps2 MockPS + var mps system.MockPS + var mps2 system.MockPS var acc testutil.Accumulator var err error @@ -188,7 +189,7 @@ func TestCPUCountIncrease(t *testing.T) { // TestCPUTimesDecrease tests that telegraf continue to works after // CPU times decrease, which seems to occur when Linux system is suspended. func TestCPUTimesDecrease(t *testing.T) { - var mps MockPS + var mps system.MockPS defer mps.AssertExpectations(t) var acc testutil.Accumulator @@ -230,7 +231,7 @@ func TestCPUTimesDecrease(t *testing.T) { assertContainsTaggedFloat(t, &acc, "cpu", "time_idle", 80, 0, cputags) assertContainsTaggedFloat(t, &acc, "cpu", "time_iowait", 2, 0, cputags) - mps2 := MockPS{} + mps2 := system.MockPS{} mps2.On("CPUTimes").Return([]cpu.TimesStat{cts2}, nil) cs.ps = &mps2 @@ -238,7 +239,7 @@ func TestCPUTimesDecrease(t *testing.T) { err = cs.Gather(&acc) require.Error(t, err) - mps3 := MockPS{} + mps3 := system.MockPS{} mps3.On("CPUTimes").Return([]cpu.TimesStat{cts3}, nil) cs.ps = &mps3 diff --git a/plugins/inputs/system/DISK_README.md b/plugins/inputs/disk/README.md similarity index 100% rename from plugins/inputs/system/DISK_README.md rename to plugins/inputs/disk/README.md diff --git a/plugins/inputs/system/disk.go b/plugins/inputs/disk/disk.go similarity index 95% rename from plugins/inputs/system/disk.go rename to plugins/inputs/disk/disk.go index 17226156054b0..5a30dbecff71e 100644 --- a/plugins/inputs/system/disk.go +++ b/plugins/inputs/disk/disk.go @@ -1,4 +1,4 @@ -package system +package disk import ( "fmt" @@ -6,10 +6,11 @@ import ( "github.com/influxdata/telegraf" "github.com/influxdata/telegraf/plugins/inputs" + "github.com/influxdata/telegraf/plugins/inputs/system" ) type DiskStats struct { - ps PS + ps system.PS // Legacy support Mountpoints []string @@ -105,7 +106,7 @@ func parseOptions(opts string) MountOptions { } func init() { - ps := newSystemPS() + ps := system.NewSystemPS() inputs.Add("disk", func() telegraf.Input { return &DiskStats{ps: ps} }) diff --git a/plugins/inputs/system/disk_test.go b/plugins/inputs/disk/disk_test.go similarity index 96% rename from plugins/inputs/system/disk_test.go rename to plugins/inputs/disk/disk_test.go index 938ca1b06574d..c20df41db699e 100644 --- a/plugins/inputs/system/disk_test.go +++ b/plugins/inputs/disk/disk_test.go @@ -1,9 +1,10 @@ -package system +package disk import ( "os" "testing" + "github.com/influxdata/telegraf/plugins/inputs/system" "github.com/influxdata/telegraf/testutil" "github.com/shirou/gopsutil/disk" "github.com/stretchr/testify/assert" @@ -17,7 +18,7 @@ type MockFileInfo struct { func TestDiskUsage(t *testing.T) { mck := &mock.Mock{} - mps := MockPSDisk{&systemPS{&mockDiskUsage{mck}}, mck} + mps := system.MockPSDisk{SystemPS: &system.SystemPS{PSDiskDeps: &system.MockDiskUsage{Mock: mck}}, Mock: mck} defer mps.AssertExpectations(t) var acc testutil.Accumulator @@ -229,7 +230,7 @@ func TestDiskUsageHostMountPrefix(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { mck := &mock.Mock{} - mps := MockPSDisk{&systemPS{&mockDiskUsage{mck}}, mck} + mps := system.MockPSDisk{SystemPS: &system.SystemPS{PSDiskDeps: &system.MockDiskUsage{Mock: mck}}, Mock: mck} defer mps.AssertExpectations(t) var acc testutil.Accumulator @@ -252,7 +253,7 @@ func TestDiskUsageHostMountPrefix(t *testing.T) { } func TestDiskStats(t *testing.T) { - var mps MockPS + var mps system.MockPS defer mps.AssertExpectations(t) var acc testutil.Accumulator var err error diff --git a/plugins/inputs/system/DISKIO_README.md b/plugins/inputs/diskio/README.md similarity index 100% rename from plugins/inputs/system/DISKIO_README.md rename to plugins/inputs/diskio/README.md diff --git a/plugins/inputs/system/diskio.go b/plugins/inputs/diskio/diskio.go similarity index 97% rename from plugins/inputs/system/diskio.go rename to plugins/inputs/diskio/diskio.go index 21e70d5eb281c..54e74d5185f3f 100644 --- a/plugins/inputs/system/diskio.go +++ b/plugins/inputs/diskio/diskio.go @@ -1,4 +1,4 @@ -package system +package diskio import ( "fmt" @@ -9,6 +9,7 @@ import ( "github.com/influxdata/telegraf" "github.com/influxdata/telegraf/filter" "github.com/influxdata/telegraf/plugins/inputs" + "github.com/influxdata/telegraf/plugins/inputs/system" ) var ( @@ -16,7 +17,7 @@ var ( ) type DiskIO struct { - ps PS + ps system.PS Devices []string DeviceTags []string @@ -189,7 +190,7 @@ func (s *DiskIO) diskTags(devName string) map[string]string { } func init() { - ps := newSystemPS() + ps := system.NewSystemPS() inputs.Add("diskio", func() telegraf.Input { return &DiskIO{ps: ps, SkipSerialNumber: true} }) diff --git a/plugins/inputs/system/diskio_linux.go b/plugins/inputs/diskio/diskio_linux.go similarity index 98% rename from plugins/inputs/system/diskio_linux.go rename to plugins/inputs/diskio/diskio_linux.go index b15f7438342e9..38240a0a1148d 100644 --- a/plugins/inputs/system/diskio_linux.go +++ b/plugins/inputs/diskio/diskio_linux.go @@ -1,4 +1,4 @@ -package system +package diskio import ( "bufio" diff --git a/plugins/inputs/system/diskio_linux_test.go b/plugins/inputs/diskio/diskio_linux_test.go similarity index 99% rename from plugins/inputs/system/diskio_linux_test.go rename to plugins/inputs/diskio/diskio_linux_test.go index 96aed211beb2e..b18bb67a8dcb0 100644 --- a/plugins/inputs/system/diskio_linux_test.go +++ b/plugins/inputs/diskio/diskio_linux_test.go @@ -1,6 +1,6 @@ // +build linux -package system +package diskio import ( "io/ioutil" diff --git a/plugins/inputs/system/diskio_other.go b/plugins/inputs/diskio/diskio_other.go similarity index 90% rename from plugins/inputs/system/diskio_other.go rename to plugins/inputs/diskio/diskio_other.go index 0a3abb686b7b5..07fb8c3b87faa 100644 --- a/plugins/inputs/system/diskio_other.go +++ b/plugins/inputs/diskio/diskio_other.go @@ -1,6 +1,6 @@ // +build !linux -package system +package diskio type diskInfoCache struct{} diff --git a/plugins/inputs/system/diskio_test.go b/plugins/inputs/diskio/diskio_test.go similarity index 96% rename from plugins/inputs/system/diskio_test.go rename to plugins/inputs/diskio/diskio_test.go index d8b908c3e80bd..ac58331651f0c 100644 --- a/plugins/inputs/system/diskio_test.go +++ b/plugins/inputs/diskio/diskio_test.go @@ -1,8 +1,9 @@ -package system +package diskio import ( "testing" + "github.com/influxdata/telegraf/plugins/inputs/system" "github.com/influxdata/telegraf/testutil" "github.com/shirou/gopsutil/disk" "github.com/stretchr/testify/require" @@ -96,7 +97,7 @@ func TestDiskIO(t *testing.T) { } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - var mps MockPS + var mps system.MockPS mps.On("DiskIO").Return(tt.result.stats, tt.result.err) var acc testutil.Accumulator diff --git a/plugins/inputs/system/KERNEL_README.md b/plugins/inputs/kernel/README.md similarity index 100% rename from plugins/inputs/system/KERNEL_README.md rename to plugins/inputs/kernel/README.md diff --git a/plugins/inputs/system/kernel.go b/plugins/inputs/kernel/kernel.go similarity index 99% rename from plugins/inputs/system/kernel.go rename to plugins/inputs/kernel/kernel.go index 1b3bc1dfa13f5..461c9564a38e9 100644 --- a/plugins/inputs/system/kernel.go +++ b/plugins/inputs/kernel/kernel.go @@ -1,6 +1,6 @@ // +build linux -package system +package kernel import ( "bytes" diff --git a/plugins/inputs/system/kernel_notlinux.go b/plugins/inputs/kernel/kernel_notlinux.go similarity index 96% rename from plugins/inputs/system/kernel_notlinux.go rename to plugins/inputs/kernel/kernel_notlinux.go index 9053b5c04f7b6..05f6e55c453c5 100644 --- a/plugins/inputs/system/kernel_notlinux.go +++ b/plugins/inputs/kernel/kernel_notlinux.go @@ -1,6 +1,6 @@ // +build !linux -package system +package kernel import ( "github.com/influxdata/telegraf" diff --git a/plugins/inputs/system/kernel_test.go b/plugins/inputs/kernel/kernel_test.go similarity index 98% rename from plugins/inputs/system/kernel_test.go rename to plugins/inputs/kernel/kernel_test.go index bf090eb88a06b..d356f43802798 100644 --- a/plugins/inputs/system/kernel_test.go +++ b/plugins/inputs/kernel/kernel_test.go @@ -1,6 +1,6 @@ // +build linux -package system +package kernel import ( "io/ioutil" @@ -168,7 +168,7 @@ const entropyStatFile_Partial = `1024` const entropyStatFile_Invalid = `` func makeFakeStatFile(content []byte) string { - tmpfile, err := ioutil.TempFile("", "kerneltest") + tmpfile, err := ioutil.TempFile("", "kernel_test") if err != nil { panic(err) } diff --git a/plugins/inputs/system/KERNEL_VMSTAT_README.md b/plugins/inputs/kernel_vmstat/README.md similarity index 100% rename from plugins/inputs/system/KERNEL_VMSTAT_README.md rename to plugins/inputs/kernel_vmstat/README.md diff --git a/plugins/inputs/system/kernel_vmstat.go b/plugins/inputs/kernel_vmstat/kernel_vmstat.go similarity index 98% rename from plugins/inputs/system/kernel_vmstat.go rename to plugins/inputs/kernel_vmstat/kernel_vmstat.go index 197d81185cf2b..ffc56d97d154e 100644 --- a/plugins/inputs/system/kernel_vmstat.go +++ b/plugins/inputs/kernel_vmstat/kernel_vmstat.go @@ -1,6 +1,6 @@ // +build linux -package system +package kernel_vmstat import ( "bytes" diff --git a/plugins/inputs/kernel_vmstat/kernel_vmstat_notlinux.go b/plugins/inputs/kernel_vmstat/kernel_vmstat_notlinux.go new file mode 100644 index 0000000000000..11a5d2e553dff --- /dev/null +++ b/plugins/inputs/kernel_vmstat/kernel_vmstat_notlinux.go @@ -0,0 +1,3 @@ +// +build !linux + +package kernel_vmstat diff --git a/plugins/inputs/system/kernel_vmstat_test.go b/plugins/inputs/kernel_vmstat/kernel_vmstat_test.go similarity index 97% rename from plugins/inputs/system/kernel_vmstat_test.go rename to plugins/inputs/kernel_vmstat/kernel_vmstat_test.go index ed0c03e2896d8..bba615a743e54 100644 --- a/plugins/inputs/system/kernel_vmstat_test.go +++ b/plugins/inputs/kernel_vmstat/kernel_vmstat_test.go @@ -1,6 +1,6 @@ // +build linux -package system +package kernel_vmstat import ( "io/ioutil" @@ -13,7 +13,7 @@ import ( ) func TestFullVmStatProcFile(t *testing.T) { - tmpfile := makeFakeStatFile([]byte(vmStatFile_Full)) + tmpfile := makeFakeVmStatFile([]byte(vmStatFile_Full)) defer os.Remove(tmpfile) k := KernelVmstat{ @@ -121,7 +121,7 @@ func TestFullVmStatProcFile(t *testing.T) { } func TestPartialVmStatProcFile(t *testing.T) { - tmpfile := makeFakeStatFile([]byte(vmStatFile_Partial)) + tmpfile := makeFakeVmStatFile([]byte(vmStatFile_Partial)) defer os.Remove(tmpfile) k := KernelVmstat{ @@ -151,7 +151,7 @@ func TestPartialVmStatProcFile(t *testing.T) { } func TestInvalidVmStatProcFile1(t *testing.T) { - tmpfile := makeFakeStatFile([]byte(vmStatFile_Invalid)) + tmpfile := makeFakeVmStatFile([]byte(vmStatFile_Invalid)) defer os.Remove(tmpfile) k := KernelVmstat{ @@ -164,7 +164,7 @@ func TestInvalidVmStatProcFile1(t *testing.T) { } func TestNoVmStatProcFile(t *testing.T) { - tmpfile := makeFakeStatFile([]byte(vmStatFile_Invalid)) + tmpfile := makeFakeVmStatFile([]byte(vmStatFile_Invalid)) os.Remove(tmpfile) k := KernelVmstat{ diff --git a/plugins/inputs/system/LINUX_SYSCTL_FS_README.md b/plugins/inputs/linux_sysctl_fs/README.md similarity index 100% rename from plugins/inputs/system/LINUX_SYSCTL_FS_README.md rename to plugins/inputs/linux_sysctl_fs/README.md diff --git a/plugins/inputs/system/linux_sysctl_fs.go b/plugins/inputs/linux_sysctl_fs/linux_sysctl_fs.go similarity index 98% rename from plugins/inputs/system/linux_sysctl_fs.go rename to plugins/inputs/linux_sysctl_fs/linux_sysctl_fs.go index 55ebcb668d1f1..ed24963404fc2 100644 --- a/plugins/inputs/system/linux_sysctl_fs.go +++ b/plugins/inputs/linux_sysctl_fs/linux_sysctl_fs.go @@ -1,4 +1,4 @@ -package system +package linux_sysctl_fs import ( "bytes" diff --git a/plugins/inputs/system/linux_sysctl_fs_test.go b/plugins/inputs/linux_sysctl_fs/linux_sysctl_fs_test.go similarity index 98% rename from plugins/inputs/system/linux_sysctl_fs_test.go rename to plugins/inputs/linux_sysctl_fs/linux_sysctl_fs_test.go index 6561465cb1452..78011e288b962 100644 --- a/plugins/inputs/system/linux_sysctl_fs_test.go +++ b/plugins/inputs/linux_sysctl_fs/linux_sysctl_fs_test.go @@ -1,4 +1,4 @@ -package system +package linux_sysctl_fs import ( "io/ioutil" diff --git a/plugins/inputs/system/MEM_README.md b/plugins/inputs/mem/README.md similarity index 100% rename from plugins/inputs/system/MEM_README.md rename to plugins/inputs/mem/README.md diff --git a/plugins/inputs/system/memory.go b/plugins/inputs/mem/memory.go similarity index 90% rename from plugins/inputs/system/memory.go rename to plugins/inputs/mem/memory.go index b44fabc49ef5e..f664dd3f42669 100644 --- a/plugins/inputs/system/memory.go +++ b/plugins/inputs/mem/memory.go @@ -1,14 +1,15 @@ -package system +package mem import ( "fmt" "github.com/influxdata/telegraf" "github.com/influxdata/telegraf/plugins/inputs" + "github.com/influxdata/telegraf/plugins/inputs/system" ) type MemStats struct { - ps PS + ps system.PS } func (_ *MemStats) Description() string { @@ -43,7 +44,7 @@ func (s *MemStats) Gather(acc telegraf.Accumulator) error { } func init() { - ps := newSystemPS() + ps := system.NewSystemPS() inputs.Add("mem", func() telegraf.Input { return &MemStats{ps: ps} }) diff --git a/plugins/inputs/system/memory_test.go b/plugins/inputs/mem/memory_test.go similarity index 93% rename from plugins/inputs/system/memory_test.go rename to plugins/inputs/mem/memory_test.go index 34914db9cbdc3..ef9af8d22c973 100644 --- a/plugins/inputs/system/memory_test.go +++ b/plugins/inputs/mem/memory_test.go @@ -1,15 +1,16 @@ -package system +package mem import ( "testing" + "github.com/influxdata/telegraf/plugins/inputs/system" "github.com/influxdata/telegraf/testutil" "github.com/shirou/gopsutil/mem" "github.com/stretchr/testify/require" ) func TestMemStats(t *testing.T) { - var mps MockPS + var mps system.MockPS var err error defer mps.AssertExpectations(t) var acc testutil.Accumulator diff --git a/plugins/inputs/system/NETSTAT_README.md b/plugins/inputs/net/NETSTAT_README.md similarity index 67% rename from plugins/inputs/system/NETSTAT_README.md rename to plugins/inputs/net/NETSTAT_README.md index 636a7e3af1985..d0f39f5e400e6 100644 --- a/plugins/inputs/system/NETSTAT_README.md +++ b/plugins/inputs/net/NETSTAT_README.md @@ -1,10 +1,18 @@ -Telegraf plugin: NETSTAT +# Netstat Input Plugin -#### Description +This plugin collects TCP connections state and UDP socket counts by using `lsof`. -The NETSTAT plugin collects TCP connections state and UDP socket counts by using `lsof`. +### Configuration: -Supported TCP Connection states are follows. +``` toml +# Collect TCP connections state and UDP socket counts +[[inputs.netstat]] + # no configuration +``` + +# Measurements: + +Supported TCP Connection states are follows. - established - syn_sent @@ -19,8 +27,6 @@ Supported TCP Connection states are follows. - closing - none - -# Measurements: ### TCP Connection State measurements: Meta: @@ -49,4 +55,3 @@ Meta: Measurement names: - udp_socket - diff --git a/plugins/inputs/system/NET_README.md b/plugins/inputs/net/NET_README.md similarity index 100% rename from plugins/inputs/system/NET_README.md rename to plugins/inputs/net/NET_README.md diff --git a/plugins/inputs/system/net.go b/plugins/inputs/net/net.go similarity index 95% rename from plugins/inputs/system/net.go rename to plugins/inputs/net/net.go index a7ba5c63d35f9..35d4a2448038c 100644 --- a/plugins/inputs/system/net.go +++ b/plugins/inputs/net/net.go @@ -1,4 +1,4 @@ -package system +package net import ( "fmt" @@ -8,11 +8,12 @@ import ( "github.com/influxdata/telegraf" "github.com/influxdata/telegraf/filter" "github.com/influxdata/telegraf/plugins/inputs" + "github.com/influxdata/telegraf/plugins/inputs/system" ) type NetIOStats struct { filter filter.Filter - ps PS + ps system.PS skipChecks bool IgnoreProtocolStats bool @@ -119,6 +120,6 @@ func (s *NetIOStats) Gather(acc telegraf.Accumulator) error { func init() { inputs.Add("net", func() telegraf.Input { - return &NetIOStats{ps: newSystemPS()} + return &NetIOStats{ps: system.NewSystemPS()} }) } diff --git a/plugins/inputs/system/net_test.go b/plugins/inputs/net/net_test.go similarity index 96% rename from plugins/inputs/system/net_test.go rename to plugins/inputs/net/net_test.go index 83b9bd4601d8b..035dbaecd4766 100644 --- a/plugins/inputs/system/net_test.go +++ b/plugins/inputs/net/net_test.go @@ -1,16 +1,17 @@ -package system +package net import ( "syscall" "testing" + "github.com/influxdata/telegraf/plugins/inputs/system" "github.com/influxdata/telegraf/testutil" "github.com/shirou/gopsutil/net" "github.com/stretchr/testify/require" ) func TestNetStats(t *testing.T) { - var mps MockPS + var mps system.MockPS var err error defer mps.AssertExpectations(t) var acc testutil.Accumulator diff --git a/plugins/inputs/system/netstat.go b/plugins/inputs/net/netstat.go similarity index 92% rename from plugins/inputs/system/netstat.go rename to plugins/inputs/net/netstat.go index 1699e08085d31..555b396afd357 100644 --- a/plugins/inputs/system/netstat.go +++ b/plugins/inputs/net/netstat.go @@ -1,4 +1,4 @@ -package system +package net import ( "fmt" @@ -6,10 +6,11 @@ import ( "github.com/influxdata/telegraf" "github.com/influxdata/telegraf/plugins/inputs" + "github.com/influxdata/telegraf/plugins/inputs/system" ) type NetStats struct { - ps PS + ps system.PS } func (_ *NetStats) Description() string { @@ -66,6 +67,6 @@ func (s *NetStats) Gather(acc telegraf.Accumulator) error { func init() { inputs.Add("netstat", func() telegraf.Input { - return &NetStats{ps: newSystemPS()} + return &NetStats{ps: system.NewSystemPS()} }) } diff --git a/plugins/inputs/system/PROCESSES_README.md b/plugins/inputs/processes/README.md similarity index 100% rename from plugins/inputs/system/PROCESSES_README.md rename to plugins/inputs/processes/README.md diff --git a/plugins/inputs/system/processes.go b/plugins/inputs/processes/processes.go similarity index 97% rename from plugins/inputs/system/processes.go rename to plugins/inputs/processes/processes.go index 9258bc4174a5e..c71d72f505e85 100644 --- a/plugins/inputs/system/processes.go +++ b/plugins/inputs/processes/processes.go @@ -1,6 +1,6 @@ // +build !windows -package system +package processes import ( "bytes" @@ -16,6 +16,7 @@ import ( "github.com/influxdata/telegraf" "github.com/influxdata/telegraf/plugins/inputs" + "github.com/influxdata/telegraf/plugins/inputs/linux_sysctl_fs" ) type Processes struct { @@ -133,7 +134,7 @@ func (p *Processes) gatherFromPS(fields map[string]interface{}) error { // get process states from /proc/(pid)/stat files func (p *Processes) gatherFromProc(fields map[string]interface{}) error { - filenames, err := filepath.Glob(GetHostProc() + "/[0-9]*/stat") + filenames, err := filepath.Glob(linux_sysctl_fs.GetHostProc() + "/[0-9]*/stat") if err != nil { return err diff --git a/plugins/inputs/system/processes_test.go b/plugins/inputs/processes/processes_test.go similarity index 98% rename from plugins/inputs/system/processes_test.go rename to plugins/inputs/processes/processes_test.go index 5401e1a70aaa5..27fdf76a17858 100644 --- a/plugins/inputs/system/processes_test.go +++ b/plugins/inputs/processes/processes_test.go @@ -1,4 +1,6 @@ -package system +// +build !windows + +package processes import ( "fmt" diff --git a/plugins/inputs/processes/processes_windows.go b/plugins/inputs/processes/processes_windows.go new file mode 100644 index 0000000000000..32c73f918165d --- /dev/null +++ b/plugins/inputs/processes/processes_windows.go @@ -0,0 +1,3 @@ +// +build windows + +package processes diff --git a/plugins/inputs/system/SWAP_README.md b/plugins/inputs/swap/README.md similarity index 100% rename from plugins/inputs/system/SWAP_README.md rename to plugins/inputs/swap/README.md diff --git a/plugins/inputs/system/swap.go b/plugins/inputs/swap/swap.go similarity index 88% rename from plugins/inputs/system/swap.go rename to plugins/inputs/swap/swap.go index f1f7c8e237447..eabb40a038e7d 100644 --- a/plugins/inputs/system/swap.go +++ b/plugins/inputs/swap/swap.go @@ -1,14 +1,15 @@ -package system +package swap import ( "fmt" "github.com/influxdata/telegraf" "github.com/influxdata/telegraf/plugins/inputs" + "github.com/influxdata/telegraf/plugins/inputs/system" ) type SwapStats struct { - ps PS + ps system.PS } func (_ *SwapStats) Description() string { @@ -40,7 +41,7 @@ func (s *SwapStats) Gather(acc telegraf.Accumulator) error { } func init() { - ps := newSystemPS() + ps := system.NewSystemPS() inputs.Add("swap", func() telegraf.Input { return &SwapStats{ps: ps} }) diff --git a/plugins/inputs/system/swap_test.go b/plugins/inputs/swap/swap_test.go similarity index 89% rename from plugins/inputs/system/swap_test.go rename to plugins/inputs/swap/swap_test.go index ec9a0fe540a4d..3f97b354e86b4 100644 --- a/plugins/inputs/system/swap_test.go +++ b/plugins/inputs/swap/swap_test.go @@ -1,15 +1,16 @@ -package system +package swap import ( "testing" + "github.com/influxdata/telegraf/plugins/inputs/system" "github.com/influxdata/telegraf/testutil" "github.com/shirou/gopsutil/mem" "github.com/stretchr/testify/require" ) func TestSwapStats(t *testing.T) { - var mps MockPS + var mps system.MockPS var err error defer mps.AssertExpectations(t) var acc testutil.Accumulator diff --git a/plugins/inputs/system/SYSTEM_README.md b/plugins/inputs/system/README.md similarity index 100% rename from plugins/inputs/system/SYSTEM_README.md rename to plugins/inputs/system/README.md diff --git a/plugins/inputs/system/mock_PS.go b/plugins/inputs/system/mock_PS.go index d5093f0315844..323332f3ebaf3 100644 --- a/plugins/inputs/system/mock_PS.go +++ b/plugins/inputs/system/mock_PS.go @@ -19,11 +19,11 @@ type MockPS struct { } type MockPSDisk struct { - *systemPS + *SystemPS *mock.Mock } -type mockDiskUsage struct { +type MockDiskUsage struct { *mock.Mock } @@ -109,7 +109,7 @@ func (m *MockPS) NetConnections() ([]net.ConnectionStat, error) { return r0, r1 } -func (m *mockDiskUsage) Partitions(all bool) ([]disk.PartitionStat, error) { +func (m *MockDiskUsage) Partitions(all bool) ([]disk.PartitionStat, error) { ret := m.Called(all) r0 := ret.Get(0).([]disk.PartitionStat) @@ -118,12 +118,12 @@ func (m *mockDiskUsage) Partitions(all bool) ([]disk.PartitionStat, error) { return r0, r1 } -func (m *mockDiskUsage) OSGetenv(key string) string { +func (m *MockDiskUsage) OSGetenv(key string) string { ret := m.Called(key) return ret.Get(0).(string) } -func (m *mockDiskUsage) OSStat(name string) (os.FileInfo, error) { +func (m *MockDiskUsage) OSStat(name string) (os.FileInfo, error) { ret := m.Called(name) r0 := ret.Get(0).(os.FileInfo) @@ -132,7 +132,7 @@ func (m *mockDiskUsage) OSStat(name string) (os.FileInfo, error) { return r0, r1 } -func (m *mockDiskUsage) PSDiskUsage(path string) (*disk.UsageStat, error) { +func (m *MockDiskUsage) PSDiskUsage(path string) (*disk.UsageStat, error) { ret := m.Called(path) r0 := ret.Get(0).(*disk.UsageStat) diff --git a/plugins/inputs/system/ps.go b/plugins/inputs/system/ps.go index 81161ae68492b..038e2a0a89e56 100644 --- a/plugins/inputs/system/ps.go +++ b/plugins/inputs/system/ps.go @@ -39,17 +39,17 @@ func add(acc telegraf.Accumulator, } } -func newSystemPS() *systemPS { - return &systemPS{&systemPSDisk{}} +func NewSystemPS() *SystemPS { + return &SystemPS{&SystemPSDisk{}} } -type systemPS struct { +type SystemPS struct { PSDiskDeps } -type systemPSDisk struct{} +type SystemPSDisk struct{} -func (s *systemPS) CPUTimes(perCPU, totalCPU bool) ([]cpu.TimesStat, error) { +func (s *SystemPS) CPUTimes(perCPU, totalCPU bool) ([]cpu.TimesStat, error) { var cpuTimes []cpu.TimesStat if perCPU { if perCPUTimes, err := cpu.Times(true); err == nil { @@ -68,7 +68,7 @@ func (s *systemPS) CPUTimes(perCPU, totalCPU bool) ([]cpu.TimesStat, error) { return cpuTimes, nil } -func (s *systemPS) DiskUsage( +func (s *SystemPS) DiskUsage( mountPointFilter []string, fstypeExclude []string, ) ([]*disk.UsageStat, []*disk.PartitionStat, error) { @@ -139,19 +139,19 @@ func (s *systemPS) DiskUsage( return usage, partitions, nil } -func (s *systemPS) NetProto() ([]net.ProtoCountersStat, error) { +func (s *SystemPS) NetProto() ([]net.ProtoCountersStat, error) { return net.ProtoCounters(nil) } -func (s *systemPS) NetIO() ([]net.IOCountersStat, error) { +func (s *SystemPS) NetIO() ([]net.IOCountersStat, error) { return net.IOCounters(true) } -func (s *systemPS) NetConnections() ([]net.ConnectionStat, error) { +func (s *SystemPS) NetConnections() ([]net.ConnectionStat, error) { return net.Connections("all") } -func (s *systemPS) DiskIO(names []string) (map[string]disk.IOCountersStat, error) { +func (s *SystemPS) DiskIO(names []string) (map[string]disk.IOCountersStat, error) { m, err := disk.IOCounters(names...) if err == internal.NotImplementedError { return nil, nil @@ -160,26 +160,26 @@ func (s *systemPS) DiskIO(names []string) (map[string]disk.IOCountersStat, error return m, err } -func (s *systemPS) VMStat() (*mem.VirtualMemoryStat, error) { +func (s *SystemPS) VMStat() (*mem.VirtualMemoryStat, error) { return mem.VirtualMemory() } -func (s *systemPS) SwapStat() (*mem.SwapMemoryStat, error) { +func (s *SystemPS) SwapStat() (*mem.SwapMemoryStat, error) { return mem.SwapMemory() } -func (s *systemPSDisk) Partitions(all bool) ([]disk.PartitionStat, error) { +func (s *SystemPSDisk) Partitions(all bool) ([]disk.PartitionStat, error) { return disk.Partitions(all) } -func (s *systemPSDisk) OSGetenv(key string) string { +func (s *SystemPSDisk) OSGetenv(key string) string { return os.Getenv(key) } -func (s *systemPSDisk) OSStat(name string) (os.FileInfo, error) { +func (s *SystemPSDisk) OSStat(name string) (os.FileInfo, error) { return os.Stat(name) } -func (s *systemPSDisk) PSDiskUsage(path string) (*disk.UsageStat, error) { +func (s *SystemPSDisk) PSDiskUsage(path string) (*disk.UsageStat, error) { return disk.Usage(path) }