2015-12-01 00:36:40 +00:00
|
|
|
package trig
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2015-12-01 00:40:47 +00:00
|
|
|
"math"
|
2015-12-01 00:36:40 +00:00
|
|
|
|
|
|
|
"github.com/influxdb/telegraf/plugins"
|
|
|
|
)
|
|
|
|
|
|
|
|
type Trig struct {
|
2015-12-01 00:40:47 +00:00
|
|
|
x float64
|
2015-12-01 00:36:40 +00:00
|
|
|
Amplitude float64
|
|
|
|
}
|
|
|
|
|
|
|
|
var TrigConfig = `
|
|
|
|
# Set the amplitude
|
|
|
|
amplitude = 10.0
|
|
|
|
`
|
|
|
|
|
|
|
|
func (s *Trig) SampleConfig() string {
|
|
|
|
return TrigConfig
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *Trig) Description() string {
|
|
|
|
return "Insert trig data"
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *Trig) Gather(acc plugins.Accumulator) error {
|
2015-12-01 00:40:47 +00:00
|
|
|
sinner := math.Sin((s.x*math.Pi)/5.0) * s.Amplitude
|
|
|
|
cosinner := math.Cos((s.x*math.Pi)/5.0) * s.Amplitude
|
2015-12-01 00:36:40 +00:00
|
|
|
|
|
|
|
fields := make(map[string]interface{})
|
|
|
|
fields["sine"] = sinner
|
|
|
|
fields["cosine"] = cosinner
|
|
|
|
|
|
|
|
tags := make(map[string]string)
|
|
|
|
|
|
|
|
s.x += 1.0
|
2015-12-01 00:40:47 +00:00
|
|
|
acc.AddFields("trig", fields, tags)
|
2015-12-01 00:36:40 +00:00
|
|
|
|
2015-12-01 00:40:47 +00:00
|
|
|
fmt.Printf("%#v\n", fields)
|
2015-12-01 00:36:40 +00:00
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
|
2015-12-01 00:40:47 +00:00
|
|
|
plugins.Add("Trig", func() plugins.Plugin { return &Trig{x: 0.0} })
|
|
|
|
}
|