renaming plugins -> inputs
This commit is contained in:
45
plugins/inputs/trig/trig.go
Normal file
45
plugins/inputs/trig/trig.go
Normal file
@@ -0,0 +1,45 @@
|
||||
package trig
|
||||
|
||||
import (
|
||||
"math"
|
||||
|
||||
"github.com/influxdb/telegraf/plugins/inputs"
|
||||
)
|
||||
|
||||
type Trig struct {
|
||||
x float64
|
||||
Amplitude float64
|
||||
}
|
||||
|
||||
var TrigConfig = `
|
||||
# Set the amplitude
|
||||
amplitude = 10.0
|
||||
`
|
||||
|
||||
func (s *Trig) SampleConfig() string {
|
||||
return TrigConfig
|
||||
}
|
||||
|
||||
func (s *Trig) Description() string {
|
||||
return "Inserts sine and cosine waves for demonstration purposes"
|
||||
}
|
||||
|
||||
func (s *Trig) Gather(acc inputs.Accumulator) error {
|
||||
sinner := math.Sin((s.x*math.Pi)/5.0) * s.Amplitude
|
||||
cosinner := math.Cos((s.x*math.Pi)/5.0) * s.Amplitude
|
||||
|
||||
fields := make(map[string]interface{})
|
||||
fields["sine"] = sinner
|
||||
fields["cosine"] = cosinner
|
||||
|
||||
tags := make(map[string]string)
|
||||
|
||||
s.x += 1.0
|
||||
acc.AddFields("trig", fields, tags)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func init() {
|
||||
inputs.Add("Trig", func() inputs.Input { return &Trig{x: 0.0} })
|
||||
}
|
||||
30
plugins/inputs/trig/trig_test.go
Normal file
30
plugins/inputs/trig/trig_test.go
Normal file
@@ -0,0 +1,30 @@
|
||||
package trig
|
||||
|
||||
import (
|
||||
"math"
|
||||
"testing"
|
||||
|
||||
"github.com/influxdb/telegraf/testutil"
|
||||
)
|
||||
|
||||
func TestTrig(t *testing.T) {
|
||||
s := &Trig{
|
||||
Amplitude: 10.0,
|
||||
}
|
||||
|
||||
for i := 0.0; i < 10.0; i++ {
|
||||
|
||||
var acc testutil.Accumulator
|
||||
|
||||
sine := math.Sin((i*math.Pi)/5.0) * s.Amplitude
|
||||
cosine := math.Cos((i*math.Pi)/5.0) * s.Amplitude
|
||||
|
||||
s.Gather(&acc)
|
||||
|
||||
fields := make(map[string]interface{})
|
||||
fields["sine"] = sine
|
||||
fields["cosine"] = cosine
|
||||
|
||||
acc.AssertContainsFields(t, "trig", fields)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user