Moved system package inputs out to top level (#4406)
This commit is contained in:
parent
9a14d1f074
commit
7b73b0db3a
|
@ -17,7 +17,10 @@ import (
|
||||||
_ "github.com/influxdata/telegraf/plugins/inputs/consul"
|
_ "github.com/influxdata/telegraf/plugins/inputs/consul"
|
||||||
_ "github.com/influxdata/telegraf/plugins/inputs/couchbase"
|
_ "github.com/influxdata/telegraf/plugins/inputs/couchbase"
|
||||||
_ "github.com/influxdata/telegraf/plugins/inputs/couchdb"
|
_ "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/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/disque"
|
||||||
_ "github.com/influxdata/telegraf/plugins/inputs/dmcache"
|
_ "github.com/influxdata/telegraf/plugins/inputs/dmcache"
|
||||||
_ "github.com/influxdata/telegraf/plugins/inputs/dns_query"
|
_ "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"
|
||||||
_ "github.com/influxdata/telegraf/plugins/inputs/kafka_consumer_legacy"
|
_ "github.com/influxdata/telegraf/plugins/inputs/kafka_consumer_legacy"
|
||||||
_ "github.com/influxdata/telegraf/plugins/inputs/kapacitor"
|
_ "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/kubernetes"
|
||||||
_ "github.com/influxdata/telegraf/plugins/inputs/leofs"
|
_ "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/logparser"
|
||||||
_ "github.com/influxdata/telegraf/plugins/inputs/lustre2"
|
_ "github.com/influxdata/telegraf/plugins/inputs/lustre2"
|
||||||
_ "github.com/influxdata/telegraf/plugins/inputs/mailchimp"
|
_ "github.com/influxdata/telegraf/plugins/inputs/mailchimp"
|
||||||
_ "github.com/influxdata/telegraf/plugins/inputs/mcrouter"
|
_ "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/memcached"
|
||||||
_ "github.com/influxdata/telegraf/plugins/inputs/mesos"
|
_ "github.com/influxdata/telegraf/plugins/inputs/mesos"
|
||||||
_ "github.com/influxdata/telegraf/plugins/inputs/minecraft"
|
_ "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/mysql"
|
||||||
_ "github.com/influxdata/telegraf/plugins/inputs/nats"
|
_ "github.com/influxdata/telegraf/plugins/inputs/nats"
|
||||||
_ "github.com/influxdata/telegraf/plugins/inputs/nats_consumer"
|
_ "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/net_response"
|
||||||
_ "github.com/influxdata/telegraf/plugins/inputs/nginx"
|
_ "github.com/influxdata/telegraf/plugins/inputs/nginx"
|
||||||
_ "github.com/influxdata/telegraf/plugins/inputs/nginx_plus"
|
_ "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"
|
||||||
_ "github.com/influxdata/telegraf/plugins/inputs/postgresql_extensible"
|
_ "github.com/influxdata/telegraf/plugins/inputs/postgresql_extensible"
|
||||||
_ "github.com/influxdata/telegraf/plugins/inputs/powerdns"
|
_ "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/procstat"
|
||||||
_ "github.com/influxdata/telegraf/plugins/inputs/prometheus"
|
_ "github.com/influxdata/telegraf/plugins/inputs/prometheus"
|
||||||
_ "github.com/influxdata/telegraf/plugins/inputs/puppetagent"
|
_ "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/solr"
|
||||||
_ "github.com/influxdata/telegraf/plugins/inputs/sqlserver"
|
_ "github.com/influxdata/telegraf/plugins/inputs/sqlserver"
|
||||||
_ "github.com/influxdata/telegraf/plugins/inputs/statsd"
|
_ "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/syslog"
|
||||||
_ "github.com/influxdata/telegraf/plugins/inputs/sysstat"
|
_ "github.com/influxdata/telegraf/plugins/inputs/sysstat"
|
||||||
_ "github.com/influxdata/telegraf/plugins/inputs/system"
|
_ "github.com/influxdata/telegraf/plugins/inputs/system"
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package system
|
package cpu
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
@ -6,11 +6,12 @@ import (
|
||||||
|
|
||||||
"github.com/influxdata/telegraf"
|
"github.com/influxdata/telegraf"
|
||||||
"github.com/influxdata/telegraf/plugins/inputs"
|
"github.com/influxdata/telegraf/plugins/inputs"
|
||||||
|
"github.com/influxdata/telegraf/plugins/inputs/system"
|
||||||
"github.com/shirou/gopsutil/cpu"
|
"github.com/shirou/gopsutil/cpu"
|
||||||
)
|
)
|
||||||
|
|
||||||
type CPUStats struct {
|
type CPUStats struct {
|
||||||
ps PS
|
ps system.PS
|
||||||
lastStats map[string]cpu.TimesStat
|
lastStats map[string]cpu.TimesStat
|
||||||
|
|
||||||
PerCPU bool `toml:"percpu"`
|
PerCPU bool `toml:"percpu"`
|
||||||
|
@ -19,7 +20,7 @@ type CPUStats struct {
|
||||||
ReportActive bool `toml:"report_active"`
|
ReportActive bool `toml:"report_active"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewCPUStats(ps PS) *CPUStats {
|
func NewCPUStats(ps system.PS) *CPUStats {
|
||||||
return &CPUStats{
|
return &CPUStats{
|
||||||
ps: ps,
|
ps: ps,
|
||||||
CollectCPUTime: true,
|
CollectCPUTime: true,
|
||||||
|
@ -146,7 +147,7 @@ func init() {
|
||||||
return &CPUStats{
|
return &CPUStats{
|
||||||
PerCPU: true,
|
PerCPU: true,
|
||||||
TotalCPU: true,
|
TotalCPU: true,
|
||||||
ps: newSystemPS(),
|
ps: system.NewSystemPS(),
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
|
@ -1,9 +1,10 @@
|
||||||
package system
|
package cpu
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/influxdata/telegraf/plugins/inputs/system"
|
||||||
"github.com/influxdata/telegraf/testutil"
|
"github.com/influxdata/telegraf/testutil"
|
||||||
"github.com/shirou/gopsutil/cpu"
|
"github.com/shirou/gopsutil/cpu"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
|
@ -11,7 +12,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestCPUStats(t *testing.T) {
|
func TestCPUStats(t *testing.T) {
|
||||||
var mps MockPS
|
var mps system.MockPS
|
||||||
defer mps.AssertExpectations(t)
|
defer mps.AssertExpectations(t)
|
||||||
var acc testutil.Accumulator
|
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", 3.1, 0, cputags)
|
||||||
assertContainsTaggedFloat(t, &acc, "cpu", "time_guest_nice", 0.324, 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)
|
mps2.On("CPUTimes").Return([]cpu.TimesStat{cts2}, nil)
|
||||||
cs.ps = &mps2
|
cs.ps = &mps2
|
||||||
|
|
||||||
|
@ -153,8 +154,8 @@ func assertContainsTaggedFloat(
|
||||||
// TestCPUCountChange tests that no errors are encountered if the number of
|
// TestCPUCountChange tests that no errors are encountered if the number of
|
||||||
// CPUs increases as reported with LXC.
|
// CPUs increases as reported with LXC.
|
||||||
func TestCPUCountIncrease(t *testing.T) {
|
func TestCPUCountIncrease(t *testing.T) {
|
||||||
var mps MockPS
|
var mps system.MockPS
|
||||||
var mps2 MockPS
|
var mps2 system.MockPS
|
||||||
var acc testutil.Accumulator
|
var acc testutil.Accumulator
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
|
@ -188,7 +189,7 @@ func TestCPUCountIncrease(t *testing.T) {
|
||||||
// TestCPUTimesDecrease tests that telegraf continue to works after
|
// TestCPUTimesDecrease tests that telegraf continue to works after
|
||||||
// CPU times decrease, which seems to occur when Linux system is suspended.
|
// CPU times decrease, which seems to occur when Linux system is suspended.
|
||||||
func TestCPUTimesDecrease(t *testing.T) {
|
func TestCPUTimesDecrease(t *testing.T) {
|
||||||
var mps MockPS
|
var mps system.MockPS
|
||||||
defer mps.AssertExpectations(t)
|
defer mps.AssertExpectations(t)
|
||||||
var acc testutil.Accumulator
|
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_idle", 80, 0, cputags)
|
||||||
assertContainsTaggedFloat(t, &acc, "cpu", "time_iowait", 2, 0, cputags)
|
assertContainsTaggedFloat(t, &acc, "cpu", "time_iowait", 2, 0, cputags)
|
||||||
|
|
||||||
mps2 := MockPS{}
|
mps2 := system.MockPS{}
|
||||||
mps2.On("CPUTimes").Return([]cpu.TimesStat{cts2}, nil)
|
mps2.On("CPUTimes").Return([]cpu.TimesStat{cts2}, nil)
|
||||||
cs.ps = &mps2
|
cs.ps = &mps2
|
||||||
|
|
||||||
|
@ -238,7 +239,7 @@ func TestCPUTimesDecrease(t *testing.T) {
|
||||||
err = cs.Gather(&acc)
|
err = cs.Gather(&acc)
|
||||||
require.Error(t, err)
|
require.Error(t, err)
|
||||||
|
|
||||||
mps3 := MockPS{}
|
mps3 := system.MockPS{}
|
||||||
mps3.On("CPUTimes").Return([]cpu.TimesStat{cts3}, nil)
|
mps3.On("CPUTimes").Return([]cpu.TimesStat{cts3}, nil)
|
||||||
cs.ps = &mps3
|
cs.ps = &mps3
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package system
|
package disk
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
@ -6,10 +6,11 @@ import (
|
||||||
|
|
||||||
"github.com/influxdata/telegraf"
|
"github.com/influxdata/telegraf"
|
||||||
"github.com/influxdata/telegraf/plugins/inputs"
|
"github.com/influxdata/telegraf/plugins/inputs"
|
||||||
|
"github.com/influxdata/telegraf/plugins/inputs/system"
|
||||||
)
|
)
|
||||||
|
|
||||||
type DiskStats struct {
|
type DiskStats struct {
|
||||||
ps PS
|
ps system.PS
|
||||||
|
|
||||||
// Legacy support
|
// Legacy support
|
||||||
Mountpoints []string
|
Mountpoints []string
|
||||||
|
@ -105,7 +106,7 @@ func parseOptions(opts string) MountOptions {
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
ps := newSystemPS()
|
ps := system.NewSystemPS()
|
||||||
inputs.Add("disk", func() telegraf.Input {
|
inputs.Add("disk", func() telegraf.Input {
|
||||||
return &DiskStats{ps: ps}
|
return &DiskStats{ps: ps}
|
||||||
})
|
})
|
|
@ -1,9 +1,10 @@
|
||||||
package system
|
package disk
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"os"
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/influxdata/telegraf/plugins/inputs/system"
|
||||||
"github.com/influxdata/telegraf/testutil"
|
"github.com/influxdata/telegraf/testutil"
|
||||||
"github.com/shirou/gopsutil/disk"
|
"github.com/shirou/gopsutil/disk"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
|
@ -17,7 +18,7 @@ type MockFileInfo struct {
|
||||||
|
|
||||||
func TestDiskUsage(t *testing.T) {
|
func TestDiskUsage(t *testing.T) {
|
||||||
mck := &mock.Mock{}
|
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)
|
defer mps.AssertExpectations(t)
|
||||||
|
|
||||||
var acc testutil.Accumulator
|
var acc testutil.Accumulator
|
||||||
|
@ -229,7 +230,7 @@ func TestDiskUsageHostMountPrefix(t *testing.T) {
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
mck := &mock.Mock{}
|
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)
|
defer mps.AssertExpectations(t)
|
||||||
|
|
||||||
var acc testutil.Accumulator
|
var acc testutil.Accumulator
|
||||||
|
@ -252,7 +253,7 @@ func TestDiskUsageHostMountPrefix(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestDiskStats(t *testing.T) {
|
func TestDiskStats(t *testing.T) {
|
||||||
var mps MockPS
|
var mps system.MockPS
|
||||||
defer mps.AssertExpectations(t)
|
defer mps.AssertExpectations(t)
|
||||||
var acc testutil.Accumulator
|
var acc testutil.Accumulator
|
||||||
var err error
|
var err error
|
|
@ -1,4 +1,4 @@
|
||||||
package system
|
package diskio
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
@ -9,6 +9,7 @@ import (
|
||||||
"github.com/influxdata/telegraf"
|
"github.com/influxdata/telegraf"
|
||||||
"github.com/influxdata/telegraf/filter"
|
"github.com/influxdata/telegraf/filter"
|
||||||
"github.com/influxdata/telegraf/plugins/inputs"
|
"github.com/influxdata/telegraf/plugins/inputs"
|
||||||
|
"github.com/influxdata/telegraf/plugins/inputs/system"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
@ -16,7 +17,7 @@ var (
|
||||||
)
|
)
|
||||||
|
|
||||||
type DiskIO struct {
|
type DiskIO struct {
|
||||||
ps PS
|
ps system.PS
|
||||||
|
|
||||||
Devices []string
|
Devices []string
|
||||||
DeviceTags []string
|
DeviceTags []string
|
||||||
|
@ -189,7 +190,7 @@ func (s *DiskIO) diskTags(devName string) map[string]string {
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
ps := newSystemPS()
|
ps := system.NewSystemPS()
|
||||||
inputs.Add("diskio", func() telegraf.Input {
|
inputs.Add("diskio", func() telegraf.Input {
|
||||||
return &DiskIO{ps: ps, SkipSerialNumber: true}
|
return &DiskIO{ps: ps, SkipSerialNumber: true}
|
||||||
})
|
})
|
|
@ -1,4 +1,4 @@
|
||||||
package system
|
package diskio
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bufio"
|
"bufio"
|
|
@ -1,6 +1,6 @@
|
||||||
// +build linux
|
// +build linux
|
||||||
|
|
||||||
package system
|
package diskio
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io/ioutil"
|
"io/ioutil"
|
|
@ -1,6 +1,6 @@
|
||||||
// +build !linux
|
// +build !linux
|
||||||
|
|
||||||
package system
|
package diskio
|
||||||
|
|
||||||
type diskInfoCache struct{}
|
type diskInfoCache struct{}
|
||||||
|
|
|
@ -1,8 +1,9 @@
|
||||||
package system
|
package diskio
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/influxdata/telegraf/plugins/inputs/system"
|
||||||
"github.com/influxdata/telegraf/testutil"
|
"github.com/influxdata/telegraf/testutil"
|
||||||
"github.com/shirou/gopsutil/disk"
|
"github.com/shirou/gopsutil/disk"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
|
@ -96,7 +97,7 @@ func TestDiskIO(t *testing.T) {
|
||||||
}
|
}
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
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)
|
mps.On("DiskIO").Return(tt.result.stats, tt.result.err)
|
||||||
|
|
||||||
var acc testutil.Accumulator
|
var acc testutil.Accumulator
|
|
@ -1,6 +1,6 @@
|
||||||
// +build linux
|
// +build linux
|
||||||
|
|
||||||
package system
|
package kernel
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
|
@ -1,6 +1,6 @@
|
||||||
// +build !linux
|
// +build !linux
|
||||||
|
|
||||||
package system
|
package kernel
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/influxdata/telegraf"
|
"github.com/influxdata/telegraf"
|
|
@ -1,6 +1,6 @@
|
||||||
// +build linux
|
// +build linux
|
||||||
|
|
||||||
package system
|
package kernel
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
@ -168,7 +168,7 @@ const entropyStatFile_Partial = `1024`
|
||||||
const entropyStatFile_Invalid = ``
|
const entropyStatFile_Invalid = ``
|
||||||
|
|
||||||
func makeFakeStatFile(content []byte) string {
|
func makeFakeStatFile(content []byte) string {
|
||||||
tmpfile, err := ioutil.TempFile("", "kerneltest")
|
tmpfile, err := ioutil.TempFile("", "kernel_test")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
|
@ -1,6 +1,6 @@
|
||||||
// +build linux
|
// +build linux
|
||||||
|
|
||||||
package system
|
package kernel_vmstat
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
|
@ -0,0 +1,3 @@
|
||||||
|
// +build !linux
|
||||||
|
|
||||||
|
package kernel_vmstat
|
|
@ -1,6 +1,6 @@
|
||||||
// +build linux
|
// +build linux
|
||||||
|
|
||||||
package system
|
package kernel_vmstat
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
@ -13,7 +13,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestFullVmStatProcFile(t *testing.T) {
|
func TestFullVmStatProcFile(t *testing.T) {
|
||||||
tmpfile := makeFakeStatFile([]byte(vmStatFile_Full))
|
tmpfile := makeFakeVmStatFile([]byte(vmStatFile_Full))
|
||||||
defer os.Remove(tmpfile)
|
defer os.Remove(tmpfile)
|
||||||
|
|
||||||
k := KernelVmstat{
|
k := KernelVmstat{
|
||||||
|
@ -121,7 +121,7 @@ func TestFullVmStatProcFile(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestPartialVmStatProcFile(t *testing.T) {
|
func TestPartialVmStatProcFile(t *testing.T) {
|
||||||
tmpfile := makeFakeStatFile([]byte(vmStatFile_Partial))
|
tmpfile := makeFakeVmStatFile([]byte(vmStatFile_Partial))
|
||||||
defer os.Remove(tmpfile)
|
defer os.Remove(tmpfile)
|
||||||
|
|
||||||
k := KernelVmstat{
|
k := KernelVmstat{
|
||||||
|
@ -151,7 +151,7 @@ func TestPartialVmStatProcFile(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestInvalidVmStatProcFile1(t *testing.T) {
|
func TestInvalidVmStatProcFile1(t *testing.T) {
|
||||||
tmpfile := makeFakeStatFile([]byte(vmStatFile_Invalid))
|
tmpfile := makeFakeVmStatFile([]byte(vmStatFile_Invalid))
|
||||||
defer os.Remove(tmpfile)
|
defer os.Remove(tmpfile)
|
||||||
|
|
||||||
k := KernelVmstat{
|
k := KernelVmstat{
|
||||||
|
@ -164,7 +164,7 @@ func TestInvalidVmStatProcFile1(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestNoVmStatProcFile(t *testing.T) {
|
func TestNoVmStatProcFile(t *testing.T) {
|
||||||
tmpfile := makeFakeStatFile([]byte(vmStatFile_Invalid))
|
tmpfile := makeFakeVmStatFile([]byte(vmStatFile_Invalid))
|
||||||
os.Remove(tmpfile)
|
os.Remove(tmpfile)
|
||||||
|
|
||||||
k := KernelVmstat{
|
k := KernelVmstat{
|
|
@ -1,4 +1,4 @@
|
||||||
package system
|
package linux_sysctl_fs
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
|
@ -1,4 +1,4 @@
|
||||||
package system
|
package linux_sysctl_fs
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io/ioutil"
|
"io/ioutil"
|
|
@ -1,14 +1,15 @@
|
||||||
package system
|
package mem
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/influxdata/telegraf"
|
"github.com/influxdata/telegraf"
|
||||||
"github.com/influxdata/telegraf/plugins/inputs"
|
"github.com/influxdata/telegraf/plugins/inputs"
|
||||||
|
"github.com/influxdata/telegraf/plugins/inputs/system"
|
||||||
)
|
)
|
||||||
|
|
||||||
type MemStats struct {
|
type MemStats struct {
|
||||||
ps PS
|
ps system.PS
|
||||||
}
|
}
|
||||||
|
|
||||||
func (_ *MemStats) Description() string {
|
func (_ *MemStats) Description() string {
|
||||||
|
@ -43,7 +44,7 @@ func (s *MemStats) Gather(acc telegraf.Accumulator) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
ps := newSystemPS()
|
ps := system.NewSystemPS()
|
||||||
inputs.Add("mem", func() telegraf.Input {
|
inputs.Add("mem", func() telegraf.Input {
|
||||||
return &MemStats{ps: ps}
|
return &MemStats{ps: ps}
|
||||||
})
|
})
|
|
@ -1,15 +1,16 @@
|
||||||
package system
|
package mem
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/influxdata/telegraf/plugins/inputs/system"
|
||||||
"github.com/influxdata/telegraf/testutil"
|
"github.com/influxdata/telegraf/testutil"
|
||||||
"github.com/shirou/gopsutil/mem"
|
"github.com/shirou/gopsutil/mem"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestMemStats(t *testing.T) {
|
func TestMemStats(t *testing.T) {
|
||||||
var mps MockPS
|
var mps system.MockPS
|
||||||
var err error
|
var err error
|
||||||
defer mps.AssertExpectations(t)
|
defer mps.AssertExpectations(t)
|
||||||
var acc testutil.Accumulator
|
var acc testutil.Accumulator
|
|
@ -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
|
- established
|
||||||
- syn_sent
|
- syn_sent
|
||||||
|
@ -19,8 +27,6 @@ Supported TCP Connection states are follows.
|
||||||
- closing
|
- closing
|
||||||
- none
|
- none
|
||||||
|
|
||||||
|
|
||||||
# Measurements:
|
|
||||||
### TCP Connection State measurements:
|
### TCP Connection State measurements:
|
||||||
|
|
||||||
Meta:
|
Meta:
|
||||||
|
@ -49,4 +55,3 @@ Meta:
|
||||||
|
|
||||||
Measurement names:
|
Measurement names:
|
||||||
- udp_socket
|
- udp_socket
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package system
|
package net
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
@ -8,11 +8,12 @@ import (
|
||||||
"github.com/influxdata/telegraf"
|
"github.com/influxdata/telegraf"
|
||||||
"github.com/influxdata/telegraf/filter"
|
"github.com/influxdata/telegraf/filter"
|
||||||
"github.com/influxdata/telegraf/plugins/inputs"
|
"github.com/influxdata/telegraf/plugins/inputs"
|
||||||
|
"github.com/influxdata/telegraf/plugins/inputs/system"
|
||||||
)
|
)
|
||||||
|
|
||||||
type NetIOStats struct {
|
type NetIOStats struct {
|
||||||
filter filter.Filter
|
filter filter.Filter
|
||||||
ps PS
|
ps system.PS
|
||||||
|
|
||||||
skipChecks bool
|
skipChecks bool
|
||||||
IgnoreProtocolStats bool
|
IgnoreProtocolStats bool
|
||||||
|
@ -119,6 +120,6 @@ func (s *NetIOStats) Gather(acc telegraf.Accumulator) error {
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
inputs.Add("net", func() telegraf.Input {
|
inputs.Add("net", func() telegraf.Input {
|
||||||
return &NetIOStats{ps: newSystemPS()}
|
return &NetIOStats{ps: system.NewSystemPS()}
|
||||||
})
|
})
|
||||||
}
|
}
|
|
@ -1,16 +1,17 @@
|
||||||
package system
|
package net
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"syscall"
|
"syscall"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/influxdata/telegraf/plugins/inputs/system"
|
||||||
"github.com/influxdata/telegraf/testutil"
|
"github.com/influxdata/telegraf/testutil"
|
||||||
"github.com/shirou/gopsutil/net"
|
"github.com/shirou/gopsutil/net"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestNetStats(t *testing.T) {
|
func TestNetStats(t *testing.T) {
|
||||||
var mps MockPS
|
var mps system.MockPS
|
||||||
var err error
|
var err error
|
||||||
defer mps.AssertExpectations(t)
|
defer mps.AssertExpectations(t)
|
||||||
var acc testutil.Accumulator
|
var acc testutil.Accumulator
|
|
@ -1,4 +1,4 @@
|
||||||
package system
|
package net
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
@ -6,10 +6,11 @@ import (
|
||||||
|
|
||||||
"github.com/influxdata/telegraf"
|
"github.com/influxdata/telegraf"
|
||||||
"github.com/influxdata/telegraf/plugins/inputs"
|
"github.com/influxdata/telegraf/plugins/inputs"
|
||||||
|
"github.com/influxdata/telegraf/plugins/inputs/system"
|
||||||
)
|
)
|
||||||
|
|
||||||
type NetStats struct {
|
type NetStats struct {
|
||||||
ps PS
|
ps system.PS
|
||||||
}
|
}
|
||||||
|
|
||||||
func (_ *NetStats) Description() string {
|
func (_ *NetStats) Description() string {
|
||||||
|
@ -66,6 +67,6 @@ func (s *NetStats) Gather(acc telegraf.Accumulator) error {
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
inputs.Add("netstat", func() telegraf.Input {
|
inputs.Add("netstat", func() telegraf.Input {
|
||||||
return &NetStats{ps: newSystemPS()}
|
return &NetStats{ps: system.NewSystemPS()}
|
||||||
})
|
})
|
||||||
}
|
}
|
|
@ -1,6 +1,6 @@
|
||||||
// +build !windows
|
// +build !windows
|
||||||
|
|
||||||
package system
|
package processes
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
@ -16,6 +16,7 @@ import (
|
||||||
|
|
||||||
"github.com/influxdata/telegraf"
|
"github.com/influxdata/telegraf"
|
||||||
"github.com/influxdata/telegraf/plugins/inputs"
|
"github.com/influxdata/telegraf/plugins/inputs"
|
||||||
|
"github.com/influxdata/telegraf/plugins/inputs/linux_sysctl_fs"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Processes struct {
|
type Processes struct {
|
||||||
|
@ -133,7 +134,7 @@ func (p *Processes) gatherFromPS(fields map[string]interface{}) error {
|
||||||
|
|
||||||
// get process states from /proc/(pid)/stat files
|
// get process states from /proc/(pid)/stat files
|
||||||
func (p *Processes) gatherFromProc(fields map[string]interface{}) error {
|
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 {
|
if err != nil {
|
||||||
return err
|
return err
|
|
@ -1,4 +1,6 @@
|
||||||
package system
|
// +build !windows
|
||||||
|
|
||||||
|
package processes
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
|
@ -0,0 +1,3 @@
|
||||||
|
// +build windows
|
||||||
|
|
||||||
|
package processes
|
|
@ -1,14 +1,15 @@
|
||||||
package system
|
package swap
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/influxdata/telegraf"
|
"github.com/influxdata/telegraf"
|
||||||
"github.com/influxdata/telegraf/plugins/inputs"
|
"github.com/influxdata/telegraf/plugins/inputs"
|
||||||
|
"github.com/influxdata/telegraf/plugins/inputs/system"
|
||||||
)
|
)
|
||||||
|
|
||||||
type SwapStats struct {
|
type SwapStats struct {
|
||||||
ps PS
|
ps system.PS
|
||||||
}
|
}
|
||||||
|
|
||||||
func (_ *SwapStats) Description() string {
|
func (_ *SwapStats) Description() string {
|
||||||
|
@ -40,7 +41,7 @@ func (s *SwapStats) Gather(acc telegraf.Accumulator) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
ps := newSystemPS()
|
ps := system.NewSystemPS()
|
||||||
inputs.Add("swap", func() telegraf.Input {
|
inputs.Add("swap", func() telegraf.Input {
|
||||||
return &SwapStats{ps: ps}
|
return &SwapStats{ps: ps}
|
||||||
})
|
})
|
|
@ -1,15 +1,16 @@
|
||||||
package system
|
package swap
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/influxdata/telegraf/plugins/inputs/system"
|
||||||
"github.com/influxdata/telegraf/testutil"
|
"github.com/influxdata/telegraf/testutil"
|
||||||
"github.com/shirou/gopsutil/mem"
|
"github.com/shirou/gopsutil/mem"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestSwapStats(t *testing.T) {
|
func TestSwapStats(t *testing.T) {
|
||||||
var mps MockPS
|
var mps system.MockPS
|
||||||
var err error
|
var err error
|
||||||
defer mps.AssertExpectations(t)
|
defer mps.AssertExpectations(t)
|
||||||
var acc testutil.Accumulator
|
var acc testutil.Accumulator
|
|
@ -19,11 +19,11 @@ type MockPS struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type MockPSDisk struct {
|
type MockPSDisk struct {
|
||||||
*systemPS
|
*SystemPS
|
||||||
*mock.Mock
|
*mock.Mock
|
||||||
}
|
}
|
||||||
|
|
||||||
type mockDiskUsage struct {
|
type MockDiskUsage struct {
|
||||||
*mock.Mock
|
*mock.Mock
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -109,7 +109,7 @@ func (m *MockPS) NetConnections() ([]net.ConnectionStat, error) {
|
||||||
return r0, r1
|
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)
|
ret := m.Called(all)
|
||||||
|
|
||||||
r0 := ret.Get(0).([]disk.PartitionStat)
|
r0 := ret.Get(0).([]disk.PartitionStat)
|
||||||
|
@ -118,12 +118,12 @@ func (m *mockDiskUsage) Partitions(all bool) ([]disk.PartitionStat, error) {
|
||||||
return r0, r1
|
return r0, r1
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *mockDiskUsage) OSGetenv(key string) string {
|
func (m *MockDiskUsage) OSGetenv(key string) string {
|
||||||
ret := m.Called(key)
|
ret := m.Called(key)
|
||||||
return ret.Get(0).(string)
|
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)
|
ret := m.Called(name)
|
||||||
|
|
||||||
r0 := ret.Get(0).(os.FileInfo)
|
r0 := ret.Get(0).(os.FileInfo)
|
||||||
|
@ -132,7 +132,7 @@ func (m *mockDiskUsage) OSStat(name string) (os.FileInfo, error) {
|
||||||
return r0, r1
|
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)
|
ret := m.Called(path)
|
||||||
|
|
||||||
r0 := ret.Get(0).(*disk.UsageStat)
|
r0 := ret.Get(0).(*disk.UsageStat)
|
||||||
|
|
|
@ -39,17 +39,17 @@ func add(acc telegraf.Accumulator,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func newSystemPS() *systemPS {
|
func NewSystemPS() *SystemPS {
|
||||||
return &systemPS{&systemPSDisk{}}
|
return &SystemPS{&SystemPSDisk{}}
|
||||||
}
|
}
|
||||||
|
|
||||||
type systemPS struct {
|
type SystemPS struct {
|
||||||
PSDiskDeps
|
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
|
var cpuTimes []cpu.TimesStat
|
||||||
if perCPU {
|
if perCPU {
|
||||||
if perCPUTimes, err := cpu.Times(true); err == nil {
|
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
|
return cpuTimes, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *systemPS) DiskUsage(
|
func (s *SystemPS) DiskUsage(
|
||||||
mountPointFilter []string,
|
mountPointFilter []string,
|
||||||
fstypeExclude []string,
|
fstypeExclude []string,
|
||||||
) ([]*disk.UsageStat, []*disk.PartitionStat, error) {
|
) ([]*disk.UsageStat, []*disk.PartitionStat, error) {
|
||||||
|
@ -139,19 +139,19 @@ func (s *systemPS) DiskUsage(
|
||||||
return usage, partitions, nil
|
return usage, partitions, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *systemPS) NetProto() ([]net.ProtoCountersStat, error) {
|
func (s *SystemPS) NetProto() ([]net.ProtoCountersStat, error) {
|
||||||
return net.ProtoCounters(nil)
|
return net.ProtoCounters(nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *systemPS) NetIO() ([]net.IOCountersStat, error) {
|
func (s *SystemPS) NetIO() ([]net.IOCountersStat, error) {
|
||||||
return net.IOCounters(true)
|
return net.IOCounters(true)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *systemPS) NetConnections() ([]net.ConnectionStat, error) {
|
func (s *SystemPS) NetConnections() ([]net.ConnectionStat, error) {
|
||||||
return net.Connections("all")
|
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...)
|
m, err := disk.IOCounters(names...)
|
||||||
if err == internal.NotImplementedError {
|
if err == internal.NotImplementedError {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
|
@ -160,26 +160,26 @@ func (s *systemPS) DiskIO(names []string) (map[string]disk.IOCountersStat, error
|
||||||
return m, err
|
return m, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *systemPS) VMStat() (*mem.VirtualMemoryStat, error) {
|
func (s *SystemPS) VMStat() (*mem.VirtualMemoryStat, error) {
|
||||||
return mem.VirtualMemory()
|
return mem.VirtualMemory()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *systemPS) SwapStat() (*mem.SwapMemoryStat, error) {
|
func (s *SystemPS) SwapStat() (*mem.SwapMemoryStat, error) {
|
||||||
return mem.SwapMemory()
|
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)
|
return disk.Partitions(all)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *systemPSDisk) OSGetenv(key string) string {
|
func (s *SystemPSDisk) OSGetenv(key string) string {
|
||||||
return os.Getenv(key)
|
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)
|
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)
|
return disk.Usage(path)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue