chore: Fix linter findings for `revive:exported` in `plugins/inputs/system` (#16721)
This commit is contained in:
parent
73d092a566
commit
59234e6aa6
|
|
@ -1,40 +1,33 @@
|
||||||
package system
|
package psutil
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
"github.com/shirou/gopsutil/v4/cpu"
|
"github.com/shirou/gopsutil/v4/cpu"
|
||||||
"github.com/shirou/gopsutil/v4/disk"
|
"github.com/shirou/gopsutil/v4/disk"
|
||||||
"github.com/shirou/gopsutil/v4/load"
|
|
||||||
"github.com/shirou/gopsutil/v4/mem"
|
"github.com/shirou/gopsutil/v4/mem"
|
||||||
"github.com/shirou/gopsutil/v4/net"
|
"github.com/shirou/gopsutil/v4/net"
|
||||||
"github.com/shirou/gopsutil/v4/sensors"
|
|
||||||
"github.com/stretchr/testify/mock"
|
"github.com/stretchr/testify/mock"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// MockPS is a mock implementation of the PS interface for testing purposes.
|
||||||
type MockPS struct {
|
type MockPS struct {
|
||||||
mock.Mock
|
mock.Mock
|
||||||
PSDiskDeps
|
PSDiskDeps
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// MockPSDisk is a mock implementation of the PSDiskDeps interface for testing purposes.
|
||||||
type MockPSDisk struct {
|
type MockPSDisk struct {
|
||||||
*SystemPS
|
*SystemPS
|
||||||
*mock.Mock
|
*mock.Mock
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// MockDiskUsage is a mock implementation for disk usage operations.
|
||||||
type MockDiskUsage struct {
|
type MockDiskUsage struct {
|
||||||
*mock.Mock
|
*mock.Mock
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *MockPS) LoadAvg() (*load.AvgStat, error) {
|
// CPUTimes returns the CPU times statistics.
|
||||||
ret := m.Called()
|
|
||||||
|
|
||||||
r0 := ret.Get(0).(*load.AvgStat)
|
|
||||||
r1 := ret.Error(1)
|
|
||||||
|
|
||||||
return r0, r1
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *MockPS) CPUTimes(_, _ bool) ([]cpu.TimesStat, error) {
|
func (m *MockPS) CPUTimes(_, _ bool) ([]cpu.TimesStat, error) {
|
||||||
ret := m.Called()
|
ret := m.Called()
|
||||||
|
|
||||||
|
|
@ -44,6 +37,7 @@ func (m *MockPS) CPUTimes(_, _ bool) ([]cpu.TimesStat, error) {
|
||||||
return r0, r1
|
return r0, r1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// DiskUsage returns the disk usage statistics.
|
||||||
func (m *MockPS) DiskUsage(mountPointFilter, mountOptsExclude, fstypeExclude []string) ([]*disk.UsageStat, []*disk.PartitionStat, error) {
|
func (m *MockPS) DiskUsage(mountPointFilter, mountOptsExclude, fstypeExclude []string) ([]*disk.UsageStat, []*disk.PartitionStat, error) {
|
||||||
ret := m.Called(mountPointFilter, mountOptsExclude, fstypeExclude)
|
ret := m.Called(mountPointFilter, mountOptsExclude, fstypeExclude)
|
||||||
|
|
||||||
|
|
@ -54,6 +48,7 @@ func (m *MockPS) DiskUsage(mountPointFilter, mountOptsExclude, fstypeExclude []s
|
||||||
return r0, r1, r2
|
return r0, r1, r2
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NetIO returns network I/O statistics for every network interface installed on the system.
|
||||||
func (m *MockPS) NetIO() ([]net.IOCountersStat, error) {
|
func (m *MockPS) NetIO() ([]net.IOCountersStat, error) {
|
||||||
ret := m.Called()
|
ret := m.Called()
|
||||||
|
|
||||||
|
|
@ -63,6 +58,7 @@ func (m *MockPS) NetIO() ([]net.IOCountersStat, error) {
|
||||||
return r0, r1
|
return r0, r1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NetProto returns network statistics for the entire system.
|
||||||
func (m *MockPS) NetProto() ([]net.ProtoCountersStat, error) {
|
func (m *MockPS) NetProto() ([]net.ProtoCountersStat, error) {
|
||||||
ret := m.Called()
|
ret := m.Called()
|
||||||
|
|
||||||
|
|
@ -72,6 +68,7 @@ func (m *MockPS) NetProto() ([]net.ProtoCountersStat, error) {
|
||||||
return r0, r1
|
return r0, r1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// DiskIO returns the disk I/O statistics.
|
||||||
func (m *MockPS) DiskIO(_ []string) (map[string]disk.IOCountersStat, error) {
|
func (m *MockPS) DiskIO(_ []string) (map[string]disk.IOCountersStat, error) {
|
||||||
ret := m.Called()
|
ret := m.Called()
|
||||||
|
|
||||||
|
|
@ -81,6 +78,7 @@ func (m *MockPS) DiskIO(_ []string) (map[string]disk.IOCountersStat, error) {
|
||||||
return r0, r1
|
return r0, r1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// VMStat returns the virtual memory statistics.
|
||||||
func (m *MockPS) VMStat() (*mem.VirtualMemoryStat, error) {
|
func (m *MockPS) VMStat() (*mem.VirtualMemoryStat, error) {
|
||||||
ret := m.Called()
|
ret := m.Called()
|
||||||
|
|
||||||
|
|
@ -90,6 +88,7 @@ func (m *MockPS) VMStat() (*mem.VirtualMemoryStat, error) {
|
||||||
return r0, r1
|
return r0, r1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SwapStat returns the swap memory statistics.
|
||||||
func (m *MockPS) SwapStat() (*mem.SwapMemoryStat, error) {
|
func (m *MockPS) SwapStat() (*mem.SwapMemoryStat, error) {
|
||||||
ret := m.Called()
|
ret := m.Called()
|
||||||
|
|
||||||
|
|
@ -99,15 +98,7 @@ func (m *MockPS) SwapStat() (*mem.SwapMemoryStat, error) {
|
||||||
return r0, r1
|
return r0, r1
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *MockPS) Temperature() ([]sensors.TemperatureStat, error) {
|
// NetConnections returns a list of network connections opened.
|
||||||
ret := m.Called()
|
|
||||||
|
|
||||||
r0 := ret.Get(0).([]sensors.TemperatureStat)
|
|
||||||
r1 := ret.Error(1)
|
|
||||||
|
|
||||||
return r0, r1
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *MockPS) NetConnections() ([]net.ConnectionStat, error) {
|
func (m *MockPS) NetConnections() ([]net.ConnectionStat, error) {
|
||||||
ret := m.Called()
|
ret := m.Called()
|
||||||
|
|
||||||
|
|
@ -117,6 +108,7 @@ func (m *MockPS) NetConnections() ([]net.ConnectionStat, error) {
|
||||||
return r0, r1
|
return r0, r1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NetConntrack returns more detailed info about the conntrack table.
|
||||||
func (m *MockPS) NetConntrack(perCPU bool) ([]net.ConntrackStat, error) {
|
func (m *MockPS) NetConntrack(perCPU bool) ([]net.ConntrackStat, error) {
|
||||||
ret := m.Called(perCPU)
|
ret := m.Called(perCPU)
|
||||||
|
|
||||||
|
|
@ -126,6 +118,7 @@ func (m *MockPS) NetConntrack(perCPU bool) ([]net.ConntrackStat, error) {
|
||||||
return r0, r1
|
return r0, r1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Partitions returns the disk partition statistics.
|
||||||
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)
|
||||||
|
|
||||||
|
|
@ -135,11 +128,13 @@ func (m *MockDiskUsage) Partitions(all bool) ([]disk.PartitionStat, error) {
|
||||||
return r0, r1
|
return r0, r1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// OSGetenv returns the value of the environment variable named by the key.
|
||||||
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)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// OSStat returns the FileInfo structure describing the named file.
|
||||||
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)
|
||||||
|
|
||||||
|
|
@ -149,6 +144,7 @@ func (m *MockDiskUsage) OSStat(name string) (os.FileInfo, error) {
|
||||||
return r0, r1
|
return r0, r1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// PSDiskUsage returns a file system usage for the specified path.
|
||||||
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)
|
||||||
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
package system
|
package psutil
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
|
|
@ -15,36 +15,55 @@ import (
|
||||||
"github.com/influxdata/telegraf/internal"
|
"github.com/influxdata/telegraf/internal"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// PS is an interface that defines methods for gathering system statistics.
|
||||||
type PS interface {
|
type PS interface {
|
||||||
|
// CPUTimes returns the CPU times statistics.
|
||||||
CPUTimes(perCPU, totalCPU bool) ([]cpu.TimesStat, error)
|
CPUTimes(perCPU, totalCPU bool) ([]cpu.TimesStat, error)
|
||||||
|
// DiskUsage returns the disk usage statistics.
|
||||||
DiskUsage(mountPointFilter []string, mountOptsExclude []string, fstypeExclude []string) ([]*disk.UsageStat, []*disk.PartitionStat, error)
|
DiskUsage(mountPointFilter []string, mountOptsExclude []string, fstypeExclude []string) ([]*disk.UsageStat, []*disk.PartitionStat, error)
|
||||||
|
// NetIO returns network I/O statistics for every network interface installed on the system.
|
||||||
NetIO() ([]net.IOCountersStat, error)
|
NetIO() ([]net.IOCountersStat, error)
|
||||||
|
// NetProto returns network statistics for the entire system.
|
||||||
NetProto() ([]net.ProtoCountersStat, error)
|
NetProto() ([]net.ProtoCountersStat, error)
|
||||||
|
// DiskIO returns the disk I/O statistics.
|
||||||
DiskIO(names []string) (map[string]disk.IOCountersStat, error)
|
DiskIO(names []string) (map[string]disk.IOCountersStat, error)
|
||||||
|
// VMStat returns the virtual memory statistics.
|
||||||
VMStat() (*mem.VirtualMemoryStat, error)
|
VMStat() (*mem.VirtualMemoryStat, error)
|
||||||
|
// SwapStat returns the swap memory statistics.
|
||||||
SwapStat() (*mem.SwapMemoryStat, error)
|
SwapStat() (*mem.SwapMemoryStat, error)
|
||||||
|
// NetConnections returns a list of network connections opened.
|
||||||
NetConnections() ([]net.ConnectionStat, error)
|
NetConnections() ([]net.ConnectionStat, error)
|
||||||
|
// NetConntrack returns more detailed info about the conntrack table.
|
||||||
NetConntrack(perCPU bool) ([]net.ConntrackStat, error)
|
NetConntrack(perCPU bool) ([]net.ConntrackStat, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// PSDiskDeps is an interface that defines methods for gathering disk statistics.
|
||||||
type PSDiskDeps interface {
|
type PSDiskDeps interface {
|
||||||
|
// Partitions returns the disk partition statistics.
|
||||||
Partitions(all bool) ([]disk.PartitionStat, error)
|
Partitions(all bool) ([]disk.PartitionStat, error)
|
||||||
|
// OSGetenv returns the value of the environment variable named by the key.
|
||||||
OSGetenv(key string) string
|
OSGetenv(key string) string
|
||||||
|
// OSStat returns the FileInfo structure describing the named file.
|
||||||
OSStat(name string) (os.FileInfo, error)
|
OSStat(name string) (os.FileInfo, error)
|
||||||
|
// PSDiskUsage returns a file system usage for the specified path.
|
||||||
PSDiskUsage(path string) (*disk.UsageStat, error)
|
PSDiskUsage(path string) (*disk.UsageStat, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewSystemPS() *SystemPS {
|
// SystemPS is a struct that implements the PS interface.
|
||||||
return &SystemPS{PSDiskDeps: &SystemPSDisk{}}
|
|
||||||
}
|
|
||||||
|
|
||||||
type SystemPS struct {
|
type SystemPS struct {
|
||||||
PSDiskDeps
|
PSDiskDeps
|
||||||
Log telegraf.Logger `toml:"-"`
|
Log telegraf.Logger `toml:"-"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SystemPSDisk is a struct that implements the PSDiskDeps interface.
|
||||||
type SystemPSDisk struct{}
|
type SystemPSDisk struct{}
|
||||||
|
|
||||||
|
// NewSystemPS creates a new instance of SystemPS.
|
||||||
|
func NewSystemPS() *SystemPS {
|
||||||
|
return &SystemPS{PSDiskDeps: &SystemPSDisk{}}
|
||||||
|
}
|
||||||
|
|
||||||
|
// CPUTimes returns the CPU times statistics.
|
||||||
func (*SystemPS) CPUTimes(perCPU, totalCPU bool) ([]cpu.TimesStat, error) {
|
func (*SystemPS) CPUTimes(perCPU, totalCPU bool) ([]cpu.TimesStat, error) {
|
||||||
var cpuTimes []cpu.TimesStat
|
var cpuTimes []cpu.TimesStat
|
||||||
if perCPU {
|
if perCPU {
|
||||||
|
|
@ -64,31 +83,7 @@ func (*SystemPS) CPUTimes(perCPU, totalCPU bool) ([]cpu.TimesStat, error) {
|
||||||
return cpuTimes, nil
|
return cpuTimes, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
type set struct {
|
// DiskUsage returns the disk usage statistics.
|
||||||
m map[string]struct{}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *set) empty() bool {
|
|
||||||
return len(s.m) == 0
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *set) add(key string) {
|
|
||||||
s.m[key] = struct{}{}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *set) has(key string) bool {
|
|
||||||
var ok bool
|
|
||||||
_, ok = s.m[key]
|
|
||||||
return ok
|
|
||||||
}
|
|
||||||
|
|
||||||
func newSet() *set {
|
|
||||||
s := &set{
|
|
||||||
m: make(map[string]struct{}),
|
|
||||||
}
|
|
||||||
return s
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *SystemPS) DiskUsage(mountPointFilter, mountOptsExclude, fstypeExclude []string) ([]*disk.UsageStat, []*disk.PartitionStat, error) {
|
func (s *SystemPS) DiskUsage(mountPointFilter, mountOptsExclude, fstypeExclude []string) ([]*disk.UsageStat, []*disk.PartitionStat, error) {
|
||||||
parts, err := s.Partitions(true)
|
parts, err := s.Partitions(true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
@ -175,22 +170,27 @@ partitionRange:
|
||||||
return usage, partitions, nil
|
return usage, partitions, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NetProto returns network statistics for the entire system.
|
||||||
func (*SystemPS) NetProto() ([]net.ProtoCountersStat, error) {
|
func (*SystemPS) NetProto() ([]net.ProtoCountersStat, error) {
|
||||||
return net.ProtoCounters(nil)
|
return net.ProtoCounters(nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NetIO returns network I/O statistics for every network interface installed on the system.
|
||||||
func (*SystemPS) NetIO() ([]net.IOCountersStat, error) {
|
func (*SystemPS) NetIO() ([]net.IOCountersStat, error) {
|
||||||
return net.IOCounters(true)
|
return net.IOCounters(true)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NetConnections returns a list of network connections opened.
|
||||||
func (*SystemPS) NetConnections() ([]net.ConnectionStat, error) {
|
func (*SystemPS) NetConnections() ([]net.ConnectionStat, error) {
|
||||||
return net.Connections("all")
|
return net.Connections("all")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NetConntrack returns more detailed info about the conntrack table.
|
||||||
func (*SystemPS) NetConntrack(perCPU bool) ([]net.ConntrackStat, error) {
|
func (*SystemPS) NetConntrack(perCPU bool) ([]net.ConntrackStat, error) {
|
||||||
return net.ConntrackStats(perCPU)
|
return net.ConntrackStats(perCPU)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// DiskIO returns the disk I/O statistics.
|
||||||
func (*SystemPS) DiskIO(names []string) (map[string]disk.IOCountersStat, error) {
|
func (*SystemPS) DiskIO(names []string) (map[string]disk.IOCountersStat, error) {
|
||||||
m, err := disk.IOCounters(names...)
|
m, err := disk.IOCounters(names...)
|
||||||
if errors.Is(err, internal.ErrNotImplemented) {
|
if errors.Is(err, internal.ErrNotImplemented) {
|
||||||
|
|
@ -200,26 +200,57 @@ func (*SystemPS) DiskIO(names []string) (map[string]disk.IOCountersStat, error)
|
||||||
return m, err
|
return m, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// VMStat returns the virtual memory statistics.
|
||||||
func (*SystemPS) VMStat() (*mem.VirtualMemoryStat, error) {
|
func (*SystemPS) VMStat() (*mem.VirtualMemoryStat, error) {
|
||||||
return mem.VirtualMemory()
|
return mem.VirtualMemory()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SwapStat returns the swap memory statistics.
|
||||||
func (*SystemPS) SwapStat() (*mem.SwapMemoryStat, error) {
|
func (*SystemPS) SwapStat() (*mem.SwapMemoryStat, error) {
|
||||||
return mem.SwapMemory()
|
return mem.SwapMemory()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Partitions returns the disk partition statistics.
|
||||||
func (*SystemPSDisk) Partitions(all bool) ([]disk.PartitionStat, error) {
|
func (*SystemPSDisk) Partitions(all bool) ([]disk.PartitionStat, error) {
|
||||||
return disk.Partitions(all)
|
return disk.Partitions(all)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// OSGetenv returns the value of the environment variable named by the key.
|
||||||
func (*SystemPSDisk) OSGetenv(key string) string {
|
func (*SystemPSDisk) OSGetenv(key string) string {
|
||||||
return os.Getenv(key)
|
return os.Getenv(key)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// OSStat returns the FileInfo structure describing the named file.
|
||||||
func (*SystemPSDisk) OSStat(name string) (os.FileInfo, error) {
|
func (*SystemPSDisk) OSStat(name string) (os.FileInfo, error) {
|
||||||
return os.Stat(name)
|
return os.Stat(name)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// PSDiskUsage returns a file system usage for the specified path.
|
||||||
func (*SystemPSDisk) PSDiskUsage(path string) (*disk.UsageStat, error) {
|
func (*SystemPSDisk) PSDiskUsage(path string) (*disk.UsageStat, error) {
|
||||||
return disk.Usage(path)
|
return disk.Usage(path)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type set struct {
|
||||||
|
m map[string]struct{}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *set) empty() bool {
|
||||||
|
return len(s.m) == 0
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *set) add(key string) {
|
||||||
|
s.m[key] = struct{}{}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *set) has(key string) bool {
|
||||||
|
var ok bool
|
||||||
|
_, ok = s.m[key]
|
||||||
|
return ok
|
||||||
|
}
|
||||||
|
|
||||||
|
func newSet() *set {
|
||||||
|
s := &set{
|
||||||
|
m: make(map[string]struct{}),
|
||||||
|
}
|
||||||
|
return s
|
||||||
|
}
|
||||||
|
|
@ -14,8 +14,8 @@ import (
|
||||||
|
|
||||||
"github.com/influxdata/telegraf"
|
"github.com/influxdata/telegraf"
|
||||||
"github.com/influxdata/telegraf/internal/choice"
|
"github.com/influxdata/telegraf/internal/choice"
|
||||||
|
"github.com/influxdata/telegraf/plugins/common/psutil"
|
||||||
"github.com/influxdata/telegraf/plugins/inputs"
|
"github.com/influxdata/telegraf/plugins/inputs"
|
||||||
"github.com/influxdata/telegraf/plugins/inputs/system"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
//go:embed sample.conf
|
//go:embed sample.conf
|
||||||
|
|
@ -43,7 +43,7 @@ type Conntrack struct {
|
||||||
Collect []string `toml:"collect"`
|
Collect []string `toml:"collect"`
|
||||||
Dirs []string `toml:"dirs"`
|
Dirs []string `toml:"dirs"`
|
||||||
Files []string `toml:"files"`
|
Files []string `toml:"files"`
|
||||||
ps system.PS
|
ps psutil.PS
|
||||||
}
|
}
|
||||||
|
|
||||||
func (*Conntrack) SampleConfig() string {
|
func (*Conntrack) SampleConfig() string {
|
||||||
|
|
@ -158,7 +158,7 @@ func (c *Conntrack) setDefaults() {
|
||||||
func init() {
|
func init() {
|
||||||
inputs.Add(inputName, func() telegraf.Input {
|
inputs.Add(inputName, func() telegraf.Input {
|
||||||
return &Conntrack{
|
return &Conntrack{
|
||||||
ps: system.NewSystemPS(),
|
ps: psutil.NewSystemPS(),
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@ import (
|
||||||
"github.com/shirou/gopsutil/v4/net"
|
"github.com/shirou/gopsutil/v4/net"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
|
|
||||||
"github.com/influxdata/telegraf/plugins/inputs/system"
|
"github.com/influxdata/telegraf/plugins/common/psutil"
|
||||||
"github.com/influxdata/telegraf/testutil"
|
"github.com/influxdata/telegraf/testutil"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -95,7 +95,7 @@ func TestConfigsUsed(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestCollectStats(t *testing.T) {
|
func TestCollectStats(t *testing.T) {
|
||||||
var mps system.MockPS
|
var mps psutil.MockPS
|
||||||
defer mps.AssertExpectations(t)
|
defer mps.AssertExpectations(t)
|
||||||
var acc testutil.Accumulator
|
var acc testutil.Accumulator
|
||||||
|
|
||||||
|
|
@ -163,7 +163,7 @@ func TestCollectStats(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestCollectStatsPerCpu(t *testing.T) {
|
func TestCollectStatsPerCpu(t *testing.T) {
|
||||||
var mps system.MockPS
|
var mps psutil.MockPS
|
||||||
defer mps.AssertExpectations(t)
|
defer mps.AssertExpectations(t)
|
||||||
var acc testutil.Accumulator
|
var acc testutil.Accumulator
|
||||||
|
|
||||||
|
|
@ -329,7 +329,7 @@ func TestCollectStatsPerCpu(t *testing.T) {
|
||||||
func TestCollectPsSystemInit(t *testing.T) {
|
func TestCollectPsSystemInit(t *testing.T) {
|
||||||
var acc testutil.Accumulator
|
var acc testutil.Accumulator
|
||||||
cs := &Conntrack{
|
cs := &Conntrack{
|
||||||
ps: system.NewSystemPS(),
|
ps: psutil.NewSystemPS(),
|
||||||
Collect: []string{"all"},
|
Collect: []string{"all"},
|
||||||
}
|
}
|
||||||
require.NoError(t, cs.Init())
|
require.NoError(t, cs.Init())
|
||||||
|
|
|
||||||
|
|
@ -10,15 +10,15 @@ import (
|
||||||
"github.com/shirou/gopsutil/v4/cpu"
|
"github.com/shirou/gopsutil/v4/cpu"
|
||||||
|
|
||||||
"github.com/influxdata/telegraf"
|
"github.com/influxdata/telegraf"
|
||||||
|
"github.com/influxdata/telegraf/plugins/common/psutil"
|
||||||
"github.com/influxdata/telegraf/plugins/inputs"
|
"github.com/influxdata/telegraf/plugins/inputs"
|
||||||
"github.com/influxdata/telegraf/plugins/inputs/system"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
//go:embed sample.conf
|
//go:embed sample.conf
|
||||||
var sampleConfig string
|
var sampleConfig string
|
||||||
|
|
||||||
type CPUStats struct {
|
type CPUStats struct {
|
||||||
ps system.PS
|
ps psutil.PS
|
||||||
lastStats map[string]cpu.TimesStat
|
lastStats map[string]cpu.TimesStat
|
||||||
cpuInfo map[string]cpu.InfoStat
|
cpuInfo map[string]cpu.InfoStat
|
||||||
coreID bool
|
coreID bool
|
||||||
|
|
@ -161,7 +161,7 @@ func init() {
|
||||||
return &CPUStats{
|
return &CPUStats{
|
||||||
PerCPU: true,
|
PerCPU: true,
|
||||||
TotalCPU: true,
|
TotalCPU: true,
|
||||||
ps: system.NewSystemPS(),
|
ps: psutil.NewSystemPS(),
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,11 +6,11 @@ import (
|
||||||
"github.com/shirou/gopsutil/v4/cpu"
|
"github.com/shirou/gopsutil/v4/cpu"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
|
|
||||||
"github.com/influxdata/telegraf/plugins/inputs/system"
|
"github.com/influxdata/telegraf/plugins/common/psutil"
|
||||||
"github.com/influxdata/telegraf/testutil"
|
"github.com/influxdata/telegraf/testutil"
|
||||||
)
|
)
|
||||||
|
|
||||||
func newCPUStats(ps system.PS) *CPUStats {
|
func newCPUStats(ps psutil.PS) *CPUStats {
|
||||||
return &CPUStats{
|
return &CPUStats{
|
||||||
ps: ps,
|
ps: ps,
|
||||||
CollectCPUTime: true,
|
CollectCPUTime: true,
|
||||||
|
|
@ -19,7 +19,7 @@ func newCPUStats(ps system.PS) *CPUStats {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestCPUStats(t *testing.T) {
|
func TestCPUStats(t *testing.T) {
|
||||||
var mps system.MockPS
|
var mps psutil.MockPS
|
||||||
defer mps.AssertExpectations(t)
|
defer mps.AssertExpectations(t)
|
||||||
var acc testutil.Accumulator
|
var acc testutil.Accumulator
|
||||||
|
|
||||||
|
|
@ -72,7 +72,7 @@ func TestCPUStats(t *testing.T) {
|
||||||
assertContainsTaggedFloat(t, &acc, "time_guest", 3.1, 0)
|
assertContainsTaggedFloat(t, &acc, "time_guest", 3.1, 0)
|
||||||
assertContainsTaggedFloat(t, &acc, "time_guest_nice", 0.324, 0)
|
assertContainsTaggedFloat(t, &acc, "time_guest_nice", 0.324, 0)
|
||||||
|
|
||||||
mps2 := system.MockPS{}
|
mps2 := psutil.MockPS{}
|
||||||
mps2.On("CPUTimes").Return([]cpu.TimesStat{cts2}, nil)
|
mps2.On("CPUTimes").Return([]cpu.TimesStat{cts2}, nil)
|
||||||
cs.ps = &mps2
|
cs.ps = &mps2
|
||||||
|
|
||||||
|
|
@ -151,8 +151,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 system.MockPS
|
var mps psutil.MockPS
|
||||||
var mps2 system.MockPS
|
var mps2 psutil.MockPS
|
||||||
var acc testutil.Accumulator
|
var acc testutil.Accumulator
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
|
|
@ -186,7 +186,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 system.MockPS
|
var mps psutil.MockPS
|
||||||
defer mps.AssertExpectations(t)
|
defer mps.AssertExpectations(t)
|
||||||
var acc testutil.Accumulator
|
var acc testutil.Accumulator
|
||||||
|
|
||||||
|
|
@ -224,7 +224,7 @@ func TestCPUTimesDecrease(t *testing.T) {
|
||||||
assertContainsTaggedFloat(t, &acc, "time_idle", 80, 0)
|
assertContainsTaggedFloat(t, &acc, "time_idle", 80, 0)
|
||||||
assertContainsTaggedFloat(t, &acc, "time_iowait", 2, 0)
|
assertContainsTaggedFloat(t, &acc, "time_iowait", 2, 0)
|
||||||
|
|
||||||
mps2 := system.MockPS{}
|
mps2 := psutil.MockPS{}
|
||||||
mps2.On("CPUTimes").Return([]cpu.TimesStat{cts2}, nil)
|
mps2.On("CPUTimes").Return([]cpu.TimesStat{cts2}, nil)
|
||||||
cs.ps = &mps2
|
cs.ps = &mps2
|
||||||
|
|
||||||
|
|
@ -232,7 +232,7 @@ func TestCPUTimesDecrease(t *testing.T) {
|
||||||
err = cs.Gather(&acc)
|
err = cs.Gather(&acc)
|
||||||
require.Error(t, err)
|
require.Error(t, err)
|
||||||
|
|
||||||
mps3 := system.MockPS{}
|
mps3 := psutil.MockPS{}
|
||||||
mps3.On("CPUTimes").Return([]cpu.TimesStat{cts3}, nil)
|
mps3.On("CPUTimes").Return([]cpu.TimesStat{cts3}, nil)
|
||||||
cs.ps = &mps3
|
cs.ps = &mps3
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -9,8 +9,8 @@ import (
|
||||||
"github.com/shirou/gopsutil/v4/disk"
|
"github.com/shirou/gopsutil/v4/disk"
|
||||||
|
|
||||||
"github.com/influxdata/telegraf"
|
"github.com/influxdata/telegraf"
|
||||||
|
"github.com/influxdata/telegraf/plugins/common/psutil"
|
||||||
"github.com/influxdata/telegraf/plugins/inputs"
|
"github.com/influxdata/telegraf/plugins/inputs"
|
||||||
"github.com/influxdata/telegraf/plugins/inputs/system"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
//go:embed sample.conf
|
//go:embed sample.conf
|
||||||
|
|
@ -22,7 +22,7 @@ type Disk struct {
|
||||||
IgnoreMountOpts []string `toml:"ignore_mount_opts"`
|
IgnoreMountOpts []string `toml:"ignore_mount_opts"`
|
||||||
Log telegraf.Logger `toml:"-"`
|
Log telegraf.Logger `toml:"-"`
|
||||||
|
|
||||||
ps system.PS
|
ps psutil.PS
|
||||||
}
|
}
|
||||||
|
|
||||||
func (*Disk) SampleConfig() string {
|
func (*Disk) SampleConfig() string {
|
||||||
|
|
@ -30,7 +30,7 @@ func (*Disk) SampleConfig() string {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ds *Disk) Init() error {
|
func (ds *Disk) Init() error {
|
||||||
ps := system.NewSystemPS()
|
ps := psutil.NewSystemPS()
|
||||||
ps.Log = ds.Log
|
ps.Log = ds.Log
|
||||||
ds.ps = ps
|
ds.ps = ps
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -14,13 +14,13 @@ import (
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
|
|
||||||
"github.com/influxdata/telegraf"
|
"github.com/influxdata/telegraf"
|
||||||
"github.com/influxdata/telegraf/plugins/inputs/system"
|
"github.com/influxdata/telegraf/plugins/common/psutil"
|
||||||
"github.com/influxdata/telegraf/testutil"
|
"github.com/influxdata/telegraf/testutil"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestDiskUsage(t *testing.T) {
|
func TestDiskUsage(t *testing.T) {
|
||||||
mck := &mock.Mock{}
|
mck := &mock.Mock{}
|
||||||
mps := system.MockPSDisk{SystemPS: &system.SystemPS{PSDiskDeps: &system.MockDiskUsage{Mock: mck}}, Mock: mck}
|
mps := psutil.MockPSDisk{SystemPS: &psutil.SystemPS{PSDiskDeps: &psutil.MockDiskUsage{Mock: mck}}, Mock: mck}
|
||||||
defer mps.AssertExpectations(t)
|
defer mps.AssertExpectations(t)
|
||||||
|
|
||||||
var acc testutil.Accumulator
|
var acc testutil.Accumulator
|
||||||
|
|
@ -278,7 +278,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 := system.MockPSDisk{SystemPS: &system.SystemPS{PSDiskDeps: &system.MockDiskUsage{Mock: mck}}, Mock: mck}
|
mps := psutil.MockPSDisk{SystemPS: &psutil.SystemPS{PSDiskDeps: &psutil.MockDiskUsage{Mock: mck}}, Mock: mck}
|
||||||
defer mps.AssertExpectations(t)
|
defer mps.AssertExpectations(t)
|
||||||
|
|
||||||
var acc testutil.Accumulator
|
var acc testutil.Accumulator
|
||||||
|
|
@ -301,7 +301,7 @@ func TestDiskUsageHostMountPrefix(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestDiskStats(t *testing.T) {
|
func TestDiskStats(t *testing.T) {
|
||||||
var mps system.MockPS
|
var mps psutil.MockPS
|
||||||
defer mps.AssertExpectations(t)
|
defer mps.AssertExpectations(t)
|
||||||
var acc testutil.Accumulator
|
var acc testutil.Accumulator
|
||||||
var err error
|
var err error
|
||||||
|
|
@ -631,7 +631,7 @@ func TestDiskUsageIssues(t *testing.T) {
|
||||||
|
|
||||||
// Mock the disk usage
|
// Mock the disk usage
|
||||||
mck := &mock.Mock{}
|
mck := &mock.Mock{}
|
||||||
mps := system.MockPSDisk{SystemPS: &system.SystemPS{PSDiskDeps: &system.MockDiskUsage{Mock: mck}}, Mock: mck}
|
mps := psutil.MockPSDisk{SystemPS: &psutil.SystemPS{PSDiskDeps: &psutil.MockDiskUsage{Mock: mck}}, Mock: mck}
|
||||||
defer mps.AssertExpectations(t)
|
defer mps.AssertExpectations(t)
|
||||||
|
|
||||||
mps.On("Partitions", true).Return(partitions, nil)
|
mps.On("Partitions", true).Return(partitions, nil)
|
||||||
|
|
|
||||||
|
|
@ -12,8 +12,8 @@ import (
|
||||||
|
|
||||||
"github.com/influxdata/telegraf"
|
"github.com/influxdata/telegraf"
|
||||||
"github.com/influxdata/telegraf/filter"
|
"github.com/influxdata/telegraf/filter"
|
||||||
|
"github.com/influxdata/telegraf/plugins/common/psutil"
|
||||||
"github.com/influxdata/telegraf/plugins/inputs"
|
"github.com/influxdata/telegraf/plugins/inputs"
|
||||||
"github.com/influxdata/telegraf/plugins/inputs/system"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
//go:embed sample.conf
|
//go:embed sample.conf
|
||||||
|
|
@ -30,7 +30,7 @@ type DiskIO struct {
|
||||||
SkipSerialNumber bool `toml:"skip_serial_number"`
|
SkipSerialNumber bool `toml:"skip_serial_number"`
|
||||||
Log telegraf.Logger `toml:"-"`
|
Log telegraf.Logger `toml:"-"`
|
||||||
|
|
||||||
ps system.PS
|
ps psutil.PS
|
||||||
infoCache map[string]diskInfoCache
|
infoCache map[string]diskInfoCache
|
||||||
deviceFilter filter.Filter
|
deviceFilter filter.Filter
|
||||||
warnDiskName map[string]bool
|
warnDiskName map[string]bool
|
||||||
|
|
@ -218,7 +218,7 @@ func (d *DiskIO) diskTags(devName string) map[string]string {
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
ps := system.NewSystemPS()
|
ps := psutil.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}
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@ import (
|
||||||
"github.com/shirou/gopsutil/v4/disk"
|
"github.com/shirou/gopsutil/v4/disk"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
|
|
||||||
"github.com/influxdata/telegraf/plugins/inputs/system"
|
"github.com/influxdata/telegraf/plugins/common/psutil"
|
||||||
"github.com/influxdata/telegraf/testutil"
|
"github.com/influxdata/telegraf/testutil"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -103,7 +103,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 system.MockPS
|
var mps psutil.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
|
||||||
|
|
@ -163,7 +163,7 @@ func TestDiskIOUtil(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
var acc testutil.Accumulator
|
var acc testutil.Accumulator
|
||||||
var mps system.MockPS
|
var mps psutil.MockPS
|
||||||
mps.On("DiskIO").Return(cts, nil)
|
mps.On("DiskIO").Return(cts, nil)
|
||||||
diskio := &DiskIO{
|
diskio := &DiskIO{
|
||||||
Log: testutil.Logger{},
|
Log: testutil.Logger{},
|
||||||
|
|
@ -176,7 +176,7 @@ func TestDiskIOUtil(t *testing.T) {
|
||||||
// sleep
|
// sleep
|
||||||
time.Sleep(1 * time.Second)
|
time.Sleep(1 * time.Second)
|
||||||
// gather twice
|
// gather twice
|
||||||
mps2 := system.MockPS{}
|
mps2 := psutil.MockPS{}
|
||||||
mps2.On("DiskIO").Return(cts2, nil)
|
mps2.On("DiskIO").Return(cts2, nil)
|
||||||
diskio.ps = &mps2
|
diskio.ps = &mps2
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -7,15 +7,15 @@ import (
|
||||||
"runtime"
|
"runtime"
|
||||||
|
|
||||||
"github.com/influxdata/telegraf"
|
"github.com/influxdata/telegraf"
|
||||||
|
"github.com/influxdata/telegraf/plugins/common/psutil"
|
||||||
"github.com/influxdata/telegraf/plugins/inputs"
|
"github.com/influxdata/telegraf/plugins/inputs"
|
||||||
"github.com/influxdata/telegraf/plugins/inputs/system"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
//go:embed sample.conf
|
//go:embed sample.conf
|
||||||
var sampleConfig string
|
var sampleConfig string
|
||||||
|
|
||||||
type Mem struct {
|
type Mem struct {
|
||||||
ps system.PS
|
ps psutil.PS
|
||||||
platform string
|
platform string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -100,7 +100,7 @@ func (ms *Mem) Gather(acc telegraf.Accumulator) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
ps := system.NewSystemPS()
|
ps := psutil.NewSystemPS()
|
||||||
inputs.Add("mem", func() telegraf.Input {
|
inputs.Add("mem", func() telegraf.Input {
|
||||||
return &Mem{ps: ps}
|
return &Mem{ps: ps}
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -8,12 +8,12 @@ import (
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
|
|
||||||
"github.com/influxdata/telegraf"
|
"github.com/influxdata/telegraf"
|
||||||
"github.com/influxdata/telegraf/plugins/inputs/system"
|
"github.com/influxdata/telegraf/plugins/common/psutil"
|
||||||
"github.com/influxdata/telegraf/testutil"
|
"github.com/influxdata/telegraf/testutil"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestMemStats(t *testing.T) {
|
func TestMemStats(t *testing.T) {
|
||||||
var mps system.MockPS
|
var mps psutil.MockPS
|
||||||
var err error
|
var err error
|
||||||
defer mps.AssertExpectations(t)
|
defer mps.AssertExpectations(t)
|
||||||
var acc testutil.Accumulator
|
var acc testutil.Accumulator
|
||||||
|
|
|
||||||
|
|
@ -14,8 +14,8 @@ import (
|
||||||
"github.com/influxdata/telegraf/config"
|
"github.com/influxdata/telegraf/config"
|
||||||
"github.com/influxdata/telegraf/filter"
|
"github.com/influxdata/telegraf/filter"
|
||||||
"github.com/influxdata/telegraf/internal"
|
"github.com/influxdata/telegraf/internal"
|
||||||
|
"github.com/influxdata/telegraf/plugins/common/psutil"
|
||||||
"github.com/influxdata/telegraf/plugins/inputs"
|
"github.com/influxdata/telegraf/plugins/inputs"
|
||||||
"github.com/influxdata/telegraf/plugins/inputs/system"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
//go:embed sample.conf
|
//go:embed sample.conf
|
||||||
|
|
@ -26,7 +26,7 @@ type Net struct {
|
||||||
IgnoreProtocolStats bool `toml:"ignore_protocol_stats"`
|
IgnoreProtocolStats bool `toml:"ignore_protocol_stats"`
|
||||||
|
|
||||||
filter filter.Filter
|
filter filter.Filter
|
||||||
ps system.PS
|
ps psutil.PS
|
||||||
skipChecks bool
|
skipChecks bool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -158,6 +158,6 @@ func getInterfaceSpeed(ioName string) int64 {
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
inputs.Add("net", func() telegraf.Input {
|
inputs.Add("net", func() telegraf.Input {
|
||||||
return &Net{ps: system.NewSystemPS()}
|
return &Net{ps: psutil.NewSystemPS()}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -10,12 +10,12 @@ import (
|
||||||
|
|
||||||
"github.com/influxdata/telegraf"
|
"github.com/influxdata/telegraf"
|
||||||
"github.com/influxdata/telegraf/metric"
|
"github.com/influxdata/telegraf/metric"
|
||||||
"github.com/influxdata/telegraf/plugins/inputs/system"
|
"github.com/influxdata/telegraf/plugins/common/psutil"
|
||||||
"github.com/influxdata/telegraf/testutil"
|
"github.com/influxdata/telegraf/testutil"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestNetIOStats(t *testing.T) {
|
func TestNetIOStats(t *testing.T) {
|
||||||
var mps system.MockPS
|
var mps psutil.MockPS
|
||||||
defer mps.AssertExpectations(t)
|
defer mps.AssertExpectations(t)
|
||||||
|
|
||||||
netio := net.IOCountersStat{
|
netio := net.IOCountersStat{
|
||||||
|
|
@ -82,7 +82,7 @@ func TestNetIOStats(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestNetIOStatsSpeedUnsupported(t *testing.T) {
|
func TestNetIOStatsSpeedUnsupported(t *testing.T) {
|
||||||
var mps system.MockPS
|
var mps psutil.MockPS
|
||||||
defer mps.AssertExpectations(t)
|
defer mps.AssertExpectations(t)
|
||||||
|
|
||||||
netio := net.IOCountersStat{
|
netio := net.IOCountersStat{
|
||||||
|
|
@ -149,7 +149,7 @@ func TestNetIOStatsSpeedUnsupported(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestNetIOStatsNoSpeedFile(t *testing.T) {
|
func TestNetIOStatsNoSpeedFile(t *testing.T) {
|
||||||
var mps system.MockPS
|
var mps psutil.MockPS
|
||||||
defer mps.AssertExpectations(t)
|
defer mps.AssertExpectations(t)
|
||||||
|
|
||||||
netio := net.IOCountersStat{
|
netio := net.IOCountersStat{
|
||||||
|
|
|
||||||
|
|
@ -7,15 +7,15 @@ import (
|
||||||
"syscall"
|
"syscall"
|
||||||
|
|
||||||
"github.com/influxdata/telegraf"
|
"github.com/influxdata/telegraf"
|
||||||
|
"github.com/influxdata/telegraf/plugins/common/psutil"
|
||||||
"github.com/influxdata/telegraf/plugins/inputs"
|
"github.com/influxdata/telegraf/plugins/inputs"
|
||||||
"github.com/influxdata/telegraf/plugins/inputs/system"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
//go:embed sample.conf
|
//go:embed sample.conf
|
||||||
var sampleConfig string
|
var sampleConfig string
|
||||||
|
|
||||||
type NetStat struct {
|
type NetStat struct {
|
||||||
ps system.PS
|
ps psutil.PS
|
||||||
}
|
}
|
||||||
|
|
||||||
func (*NetStat) SampleConfig() string {
|
func (*NetStat) SampleConfig() string {
|
||||||
|
|
@ -66,6 +66,6 @@ func (ns *NetStat) Gather(acc telegraf.Accumulator) error {
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
inputs.Add("netstat", func() telegraf.Input {
|
inputs.Add("netstat", func() telegraf.Input {
|
||||||
return &NetStat{ps: system.NewSystemPS()}
|
return &NetStat{ps: psutil.NewSystemPS()}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -10,12 +10,12 @@ import (
|
||||||
|
|
||||||
"github.com/influxdata/telegraf"
|
"github.com/influxdata/telegraf"
|
||||||
"github.com/influxdata/telegraf/metric"
|
"github.com/influxdata/telegraf/metric"
|
||||||
"github.com/influxdata/telegraf/plugins/inputs/system"
|
"github.com/influxdata/telegraf/plugins/common/psutil"
|
||||||
"github.com/influxdata/telegraf/testutil"
|
"github.com/influxdata/telegraf/testutil"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestNetStats(t *testing.T) {
|
func TestNetStats(t *testing.T) {
|
||||||
var mps system.MockPS
|
var mps psutil.MockPS
|
||||||
defer mps.AssertExpectations(t)
|
defer mps.AssertExpectations(t)
|
||||||
mps.On("NetConnections").Return([]net.ConnectionStat{
|
mps.On("NetConnections").Return([]net.ConnectionStat{
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -6,15 +6,15 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/influxdata/telegraf"
|
"github.com/influxdata/telegraf"
|
||||||
|
"github.com/influxdata/telegraf/plugins/common/psutil"
|
||||||
"github.com/influxdata/telegraf/plugins/inputs"
|
"github.com/influxdata/telegraf/plugins/inputs"
|
||||||
"github.com/influxdata/telegraf/plugins/inputs/system"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
//go:embed sample.conf
|
//go:embed sample.conf
|
||||||
var sampleConfig string
|
var sampleConfig string
|
||||||
|
|
||||||
type Swap struct {
|
type Swap struct {
|
||||||
ps system.PS
|
ps psutil.PS
|
||||||
}
|
}
|
||||||
|
|
||||||
func (*Swap) SampleConfig() string {
|
func (*Swap) SampleConfig() string {
|
||||||
|
|
@ -44,7 +44,7 @@ func (ss *Swap) Gather(acc telegraf.Accumulator) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
ps := system.NewSystemPS()
|
ps := psutil.NewSystemPS()
|
||||||
inputs.Add("swap", func() telegraf.Input {
|
inputs.Add("swap", func() telegraf.Input {
|
||||||
return &Swap{ps: ps}
|
return &Swap{ps: ps}
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -6,12 +6,12 @@ import (
|
||||||
"github.com/shirou/gopsutil/v4/mem"
|
"github.com/shirou/gopsutil/v4/mem"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
|
|
||||||
"github.com/influxdata/telegraf/plugins/inputs/system"
|
"github.com/influxdata/telegraf/plugins/common/psutil"
|
||||||
"github.com/influxdata/telegraf/testutil"
|
"github.com/influxdata/telegraf/testutil"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestSwapStats(t *testing.T) {
|
func TestSwapStats(t *testing.T) {
|
||||||
var mps system.MockPS
|
var mps psutil.MockPS
|
||||||
var err error
|
var err error
|
||||||
defer mps.AssertExpectations(t)
|
defer mps.AssertExpectations(t)
|
||||||
var acc testutil.Accumulator
|
var acc testutil.Accumulator
|
||||||
|
|
|
||||||
|
|
@ -21,15 +21,15 @@ import (
|
||||||
//go:embed sample.conf
|
//go:embed sample.conf
|
||||||
var sampleConfig string
|
var sampleConfig string
|
||||||
|
|
||||||
type SystemStats struct {
|
type System struct {
|
||||||
Log telegraf.Logger
|
Log telegraf.Logger `toml:"-"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (*SystemStats) SampleConfig() string {
|
func (*System) SampleConfig() string {
|
||||||
return sampleConfig
|
return sampleConfig
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *SystemStats) Gather(acc telegraf.Accumulator) error {
|
func (s *System) Gather(acc telegraf.Accumulator) error {
|
||||||
loadavg, err := load.Avg()
|
loadavg, err := load.Avg()
|
||||||
if err != nil && !strings.Contains(err.Error(), "not implemented") {
|
if err != nil && !strings.Contains(err.Error(), "not implemented") {
|
||||||
return err
|
return err
|
||||||
|
|
@ -112,6 +112,6 @@ func formatUptime(uptime uint64) string {
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
inputs.Add("system", func() telegraf.Input {
|
inputs.Add("system", func() telegraf.Input {
|
||||||
return &SystemStats{}
|
return &System{}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue