forked from influxdata/telegraf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
trig.go
45 lines (33 loc) · 813 Bytes
/
trig.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
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} })
}