Moved system package inputs out to top level (#4406)

This commit is contained in:
Steve Domino 2018-07-11 17:43:49 -06:00 committed by Daniel Nelson
parent 9a14d1f074
commit 7b73b0db3a
42 changed files with 126 additions and 89 deletions

View File

@ -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"

View File

@ -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(),
}
})
}

View File

@ -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

View File

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

View File

@ -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

View File

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

View File

@ -1,4 +1,4 @@
package system
package diskio
import (
"bufio"

View File

@ -1,6 +1,6 @@
// +build linux
package system
package diskio
import (
"io/ioutil"

View File

@ -1,6 +1,6 @@
// +build !linux
package system
package diskio
type diskInfoCache struct{}

View File

@ -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

View File

@ -1,6 +1,6 @@
// +build linux
package system
package kernel
import (
"bytes"

View File

@ -1,6 +1,6 @@
// +build !linux
package system
package kernel
import (
"github.com/influxdata/telegraf"

View File

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

View File

@ -1,6 +1,6 @@
// +build linux
package system
package kernel_vmstat
import (
"bytes"

View File

@ -0,0 +1,3 @@
// +build !linux
package kernel_vmstat

View File

@ -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{

View File

@ -1,4 +1,4 @@
package system
package linux_sysctl_fs
import (
"bytes"

View File

@ -1,4 +1,4 @@
package system
package linux_sysctl_fs
import (
"io/ioutil"

View File

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

View File

@ -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

View File

@ -1,8 +1,16 @@
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:
``` toml
# Collect TCP connections state and UDP socket counts
[[inputs.netstat]]
# no configuration
```
# Measurements:
Supported TCP Connection states are follows.
@ -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

View File

@ -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()}
})
}

View File

@ -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

View File

@ -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()}
})
}

View File

@ -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

View File

@ -1,4 +1,6 @@
package system
// +build !windows
package processes
import (
"fmt"

View File

@ -0,0 +1,3 @@
// +build windows
package processes

View File

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

View File

@ -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

View File

@ -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)

View File

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