@@ -10,7 +10,6 @@ import (
|
||||
"github.com/influxdb/telegraf/plugins/system/ps/cpu"
|
||||
"github.com/influxdb/telegraf/plugins/system/ps/disk"
|
||||
"github.com/influxdb/telegraf/plugins/system/ps/docker"
|
||||
"github.com/influxdb/telegraf/plugins/system/ps/load"
|
||||
"github.com/influxdb/telegraf/plugins/system/ps/mem"
|
||||
"github.com/influxdb/telegraf/plugins/system/ps/net"
|
||||
)
|
||||
@@ -24,7 +23,6 @@ type DockerContainerStat struct {
|
||||
}
|
||||
|
||||
type PS interface {
|
||||
LoadAvg() (*load.LoadAvgStat, error)
|
||||
CPUTimes(perCPU, totalCPU bool) ([]cpu.CPUTimesStat, error)
|
||||
DiskUsage() ([]*disk.DiskUsageStat, error)
|
||||
NetIO() ([]net.NetIOCountersStat, error)
|
||||
@@ -45,10 +43,6 @@ type systemPS struct {
|
||||
dockerClient *dc.Client
|
||||
}
|
||||
|
||||
func (s *systemPS) LoadAvg() (*load.LoadAvgStat, error) {
|
||||
return load.LoadAvg()
|
||||
}
|
||||
|
||||
func (s *systemPS) CPUTimes(perCPU, totalCPU bool) ([]cpu.CPUTimesStat, error) {
|
||||
var cpuTimes []cpu.CPUTimesStat
|
||||
if perCPU {
|
||||
|
||||
@@ -1,39 +1,48 @@
|
||||
package system
|
||||
|
||||
import "github.com/influxdb/telegraf/plugins"
|
||||
import (
|
||||
"github.com/cloudfoundry/gosigar"
|
||||
|
||||
type SystemStats struct {
|
||||
ps PS
|
||||
}
|
||||
"github.com/influxdb/telegraf/plugins"
|
||||
)
|
||||
|
||||
type SystemStats struct{}
|
||||
|
||||
func (_ *SystemStats) Description() string {
|
||||
return "Read metrics about system load"
|
||||
return "Read metrics about system load & uptime"
|
||||
}
|
||||
|
||||
func (_ *SystemStats) SampleConfig() string { return "" }
|
||||
|
||||
func (s *SystemStats) add(acc plugins.Accumulator,
|
||||
func (_ *SystemStats) add(acc plugins.Accumulator,
|
||||
name string, val float64, tags map[string]string) {
|
||||
if val >= 0 {
|
||||
acc.Add(name, val, tags)
|
||||
}
|
||||
}
|
||||
|
||||
func (s *SystemStats) Gather(acc plugins.Accumulator) error {
|
||||
lv, err := s.ps.LoadAvg()
|
||||
if err != nil {
|
||||
func (_ *SystemStats) Gather(acc plugins.Accumulator) error {
|
||||
loadavg := sigar.LoadAverage{}
|
||||
if err := loadavg.Get(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
acc.Add("load1", lv.Load1, nil)
|
||||
acc.Add("load5", lv.Load5, nil)
|
||||
acc.Add("load15", lv.Load15, nil)
|
||||
uptime := sigar.Uptime{}
|
||||
if err := uptime.Get(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
acc.Add("load1", loadavg.One, nil)
|
||||
acc.Add("load5", loadavg.Five, nil)
|
||||
acc.Add("load15", loadavg.Fifteen, nil)
|
||||
acc.Add("uptime", uptime.Length, nil)
|
||||
acc.Add("uptime_format", uptime.Format(), nil)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func init() {
|
||||
plugins.Add("system", func() plugins.Plugin {
|
||||
return &SystemStats{ps: &systemPS{}}
|
||||
return &SystemStats{}
|
||||
})
|
||||
}
|
||||
|
||||
@@ -7,7 +7,6 @@ import (
|
||||
|
||||
"github.com/influxdb/telegraf/plugins/system/ps/cpu"
|
||||
"github.com/influxdb/telegraf/plugins/system/ps/disk"
|
||||
"github.com/influxdb/telegraf/plugins/system/ps/load"
|
||||
"github.com/influxdb/telegraf/plugins/system/ps/mem"
|
||||
"github.com/influxdb/telegraf/plugins/system/ps/net"
|
||||
"github.com/influxdb/telegraf/testutil"
|
||||
@@ -22,14 +21,6 @@ func TestSystemStats_GenerateStats(t *testing.T) {
|
||||
|
||||
var acc testutil.Accumulator
|
||||
|
||||
lv := &load.LoadAvgStat{
|
||||
Load1: 0.3,
|
||||
Load5: 1.5,
|
||||
Load15: 0.8,
|
||||
}
|
||||
|
||||
mps.On("LoadAvg").Return(lv, nil)
|
||||
|
||||
cts := cpu.CPUTimesStat{
|
||||
CPU: "cpu0",
|
||||
User: 3.1,
|
||||
@@ -128,15 +119,6 @@ func TestSystemStats_GenerateStats(t *testing.T) {
|
||||
|
||||
mps.On("SwapStat").Return(sms, nil)
|
||||
|
||||
ss := &SystemStats{ps: &mps}
|
||||
|
||||
err := ss.Gather(&acc)
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.True(t, acc.CheckValue("load1", 0.3))
|
||||
assert.True(t, acc.CheckValue("load5", 1.5))
|
||||
assert.True(t, acc.CheckValue("load15", 0.8))
|
||||
|
||||
cs := NewCPUStats(&mps)
|
||||
|
||||
cputags := map[string]string{
|
||||
@@ -144,7 +126,7 @@ func TestSystemStats_GenerateStats(t *testing.T) {
|
||||
}
|
||||
|
||||
preCPUPoints := len(acc.Points)
|
||||
err = cs.Gather(&acc)
|
||||
err := cs.Gather(&acc)
|
||||
require.NoError(t, err)
|
||||
numCPUPoints := len(acc.Points) - preCPUPoints
|
||||
|
||||
|
||||
Reference in New Issue
Block a user