Create public models for telegraf metrics, accumlator, plugins
This will basically make the root directory a place for storing the major telegraf interfaces, which will make telegraf's godoc looks quite a bit nicer. And make it easier for contributors to lookup the few data types that they actually care about. closes #564
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/influxdata/telegraf"
|
||||
"github.com/influxdata/telegraf/plugins/inputs"
|
||||
"github.com/shirou/gopsutil/cpu"
|
||||
)
|
||||
@@ -39,7 +40,7 @@ func (_ *CPUStats) SampleConfig() string {
|
||||
return sampleConfig
|
||||
}
|
||||
|
||||
func (s *CPUStats) Gather(acc inputs.Accumulator) error {
|
||||
func (s *CPUStats) Gather(acc telegraf.Accumulator) error {
|
||||
times, err := s.ps.CPUTimes(s.PerCPU, s.TotalCPU)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error getting CPU info: %s", err)
|
||||
@@ -111,7 +112,7 @@ func totalCpuTime(t cpu.CPUTimesStat) float64 {
|
||||
}
|
||||
|
||||
func init() {
|
||||
inputs.Add("cpu", func() inputs.Input {
|
||||
inputs.Add("cpu", func() telegraf.Input {
|
||||
return &CPUStats{ps: &systemPS{}}
|
||||
})
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package system
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/influxdata/telegraf"
|
||||
"github.com/influxdata/telegraf/plugins/inputs"
|
||||
)
|
||||
|
||||
@@ -29,7 +30,7 @@ func (_ *DiskStats) SampleConfig() string {
|
||||
return diskSampleConfig
|
||||
}
|
||||
|
||||
func (s *DiskStats) Gather(acc inputs.Accumulator) error {
|
||||
func (s *DiskStats) Gather(acc telegraf.Accumulator) error {
|
||||
// Legacy support:
|
||||
if len(s.Mountpoints) != 0 {
|
||||
s.MountPoints = s.Mountpoints
|
||||
@@ -90,7 +91,7 @@ func (_ *DiskIOStats) SampleConfig() string {
|
||||
return diskIoSampleConfig
|
||||
}
|
||||
|
||||
func (s *DiskIOStats) Gather(acc inputs.Accumulator) error {
|
||||
func (s *DiskIOStats) Gather(acc telegraf.Accumulator) error {
|
||||
diskio, err := s.ps.DiskIO()
|
||||
if err != nil {
|
||||
return fmt.Errorf("error getting disk io info: %s", err)
|
||||
@@ -136,11 +137,11 @@ func (s *DiskIOStats) Gather(acc inputs.Accumulator) error {
|
||||
}
|
||||
|
||||
func init() {
|
||||
inputs.Add("disk", func() inputs.Input {
|
||||
inputs.Add("disk", func() telegraf.Input {
|
||||
return &DiskStats{ps: &systemPS{}}
|
||||
})
|
||||
|
||||
inputs.Add("diskio", func() inputs.Input {
|
||||
inputs.Add("diskio", func() telegraf.Input {
|
||||
return &DiskIOStats{ps: &systemPS{}}
|
||||
})
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package system
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/influxdata/telegraf"
|
||||
"github.com/influxdata/telegraf/plugins/inputs"
|
||||
)
|
||||
|
||||
@@ -16,7 +17,7 @@ func (_ *MemStats) Description() string {
|
||||
|
||||
func (_ *MemStats) SampleConfig() string { return "" }
|
||||
|
||||
func (s *MemStats) Gather(acc inputs.Accumulator) error {
|
||||
func (s *MemStats) Gather(acc telegraf.Accumulator) error {
|
||||
vm, err := s.ps.VMStat()
|
||||
if err != nil {
|
||||
return fmt.Errorf("error getting virtual memory info: %s", err)
|
||||
@@ -47,7 +48,7 @@ func (_ *SwapStats) Description() string {
|
||||
|
||||
func (_ *SwapStats) SampleConfig() string { return "" }
|
||||
|
||||
func (s *SwapStats) Gather(acc inputs.Accumulator) error {
|
||||
func (s *SwapStats) Gather(acc telegraf.Accumulator) error {
|
||||
swap, err := s.ps.SwapStat()
|
||||
if err != nil {
|
||||
return fmt.Errorf("error getting swap memory info: %s", err)
|
||||
@@ -67,11 +68,11 @@ func (s *SwapStats) Gather(acc inputs.Accumulator) error {
|
||||
}
|
||||
|
||||
func init() {
|
||||
inputs.Add("mem", func() inputs.Input {
|
||||
inputs.Add("mem", func() telegraf.Input {
|
||||
return &MemStats{ps: &systemPS{}}
|
||||
})
|
||||
|
||||
inputs.Add("swap", func() inputs.Input {
|
||||
inputs.Add("swap", func() telegraf.Input {
|
||||
return &SwapStats{ps: &systemPS{}}
|
||||
})
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
"net"
|
||||
"strings"
|
||||
|
||||
"github.com/influxdata/telegraf"
|
||||
"github.com/influxdata/telegraf/plugins/inputs"
|
||||
)
|
||||
|
||||
@@ -31,7 +32,7 @@ func (_ *NetIOStats) SampleConfig() string {
|
||||
return netSampleConfig
|
||||
}
|
||||
|
||||
func (s *NetIOStats) Gather(acc inputs.Accumulator) error {
|
||||
func (s *NetIOStats) Gather(acc telegraf.Accumulator) error {
|
||||
netio, err := s.ps.NetIO()
|
||||
if err != nil {
|
||||
return fmt.Errorf("error getting net io info: %s", err)
|
||||
@@ -103,7 +104,7 @@ func (s *NetIOStats) Gather(acc inputs.Accumulator) error {
|
||||
}
|
||||
|
||||
func init() {
|
||||
inputs.Add("net", func() inputs.Input {
|
||||
inputs.Add("net", func() telegraf.Input {
|
||||
return &NetIOStats{ps: &systemPS{}}
|
||||
})
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"fmt"
|
||||
"syscall"
|
||||
|
||||
"github.com/influxdata/telegraf"
|
||||
"github.com/influxdata/telegraf/plugins/inputs"
|
||||
)
|
||||
|
||||
@@ -21,7 +22,7 @@ func (_ *NetStats) SampleConfig() string {
|
||||
return tcpstatSampleConfig
|
||||
}
|
||||
|
||||
func (s *NetStats) Gather(acc inputs.Accumulator) error {
|
||||
func (s *NetStats) Gather(acc telegraf.Accumulator) error {
|
||||
netconns, err := s.ps.NetConnections()
|
||||
if err != nil {
|
||||
return fmt.Errorf("error getting net connections info: %s", err)
|
||||
@@ -64,7 +65,7 @@ func (s *NetStats) Gather(acc inputs.Accumulator) error {
|
||||
}
|
||||
|
||||
func init() {
|
||||
inputs.Add("netstat", func() inputs.Input {
|
||||
inputs.Add("netstat", func() telegraf.Input {
|
||||
return &NetStats{ps: &systemPS{}}
|
||||
})
|
||||
}
|
||||
|
||||
@@ -3,8 +3,8 @@ package system
|
||||
import (
|
||||
"os"
|
||||
|
||||
"github.com/influxdata/telegraf"
|
||||
"github.com/influxdata/telegraf/internal"
|
||||
"github.com/influxdata/telegraf/plugins/inputs"
|
||||
|
||||
"github.com/shirou/gopsutil/cpu"
|
||||
"github.com/shirou/gopsutil/disk"
|
||||
@@ -23,7 +23,7 @@ type PS interface {
|
||||
NetConnections() ([]net.NetConnectionStat, error)
|
||||
}
|
||||
|
||||
func add(acc inputs.Accumulator,
|
||||
func add(acc telegraf.Accumulator,
|
||||
name string, val float64, tags map[string]string) {
|
||||
if val >= 0 {
|
||||
acc.Add(name, val, tags)
|
||||
|
||||
@@ -8,6 +8,7 @@ import (
|
||||
"github.com/shirou/gopsutil/host"
|
||||
"github.com/shirou/gopsutil/load"
|
||||
|
||||
"github.com/influxdata/telegraf"
|
||||
"github.com/influxdata/telegraf/plugins/inputs"
|
||||
)
|
||||
|
||||
@@ -19,7 +20,7 @@ func (_ *SystemStats) Description() string {
|
||||
|
||||
func (_ *SystemStats) SampleConfig() string { return "" }
|
||||
|
||||
func (_ *SystemStats) Gather(acc inputs.Accumulator) error {
|
||||
func (_ *SystemStats) Gather(acc telegraf.Accumulator) error {
|
||||
loadavg, err := load.LoadAvg()
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -68,7 +69,7 @@ func format_uptime(uptime uint64) string {
|
||||
}
|
||||
|
||||
func init() {
|
||||
inputs.Add("system", func() inputs.Input {
|
||||
inputs.Add("system", func() telegraf.Input {
|
||||
return &SystemStats{}
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user