2015-12-01 00:29:55 +00:00
|
|
|
package trig
|
|
|
|
|
|
|
|
import (
|
|
|
|
"math"
|
|
|
|
|
2016-01-27 21:21:36 +00:00
|
|
|
"github.com/influxdata/telegraf"
|
2016-01-20 18:57:35 +00:00
|
|
|
"github.com/influxdata/telegraf/plugins/inputs"
|
2015-12-01 00:29:55 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type Trig struct {
|
|
|
|
x float64
|
|
|
|
Amplitude float64
|
|
|
|
}
|
|
|
|
|
|
|
|
var TrigConfig = `
|
2016-02-09 05:57:26 +00:00
|
|
|
### Set the amplitude
|
2015-12-01 00:29:55 +00:00
|
|
|
amplitude = 10.0
|
|
|
|
`
|
|
|
|
|
|
|
|
func (s *Trig) SampleConfig() string {
|
|
|
|
return TrigConfig
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *Trig) Description() string {
|
|
|
|
return "Inserts sine and cosine waves for demonstration purposes"
|
|
|
|
}
|
|
|
|
|
2016-01-27 21:21:36 +00:00
|
|
|
func (s *Trig) Gather(acc telegraf.Accumulator) error {
|
2015-12-01 00:29:55 +00:00
|
|
|
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() {
|
2016-02-09 05:57:26 +00:00
|
|
|
inputs.Add("trig", func() telegraf.Input { return &Trig{x: 0.0} })
|
2015-12-01 00:29:55 +00:00
|
|
|
}
|