Skip to content

Commit

Permalink
feat(inputs.mock): Add sine phase
Browse files Browse the repository at this point in the history
  • Loading branch information
LarsStegman committed Oct 7, 2024
1 parent 40d7961 commit eb9f4ff
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 1 deletion.
1 change: 1 addition & 0 deletions plugins/inputs/mock/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ See the [CONFIGURATION.md][CONFIGURATION.md] for more details.
# name = "wave"
# amplitude = 1.0
# period = 0.5
# phase = 20.0
# base_line = 0.0
# [[inputs.mock.step]]
# name = "plus_one"
Expand Down
3 changes: 2 additions & 1 deletion plugins/inputs/mock/mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ type sineWave struct {
Name string `toml:"name"`
Amplitude float64 `toml:"amplitude"`
Period float64 `toml:"period"`
Phase float64 `toml:"phase"`
BaseLine float64 `toml:"base_line"`
}

Expand Down Expand Up @@ -118,7 +119,7 @@ func (m *Mock) generateRandomFloat64(fields map[string]interface{}) {
// Create sine waves
func (m *Mock) generateSineWave(fields map[string]interface{}) {
for _, field := range m.SineWave {
fields[field.Name] = math.Sin(float64(m.counter)*field.Period*math.Pi)*field.Amplitude + field.BaseLine
fields[field.Name] = math.Sin((float64(m.counter)+field.Phase)*field.Period*math.Pi)*field.Amplitude + field.BaseLine
}
}

Expand Down
1 change: 1 addition & 0 deletions plugins/inputs/mock/sample.conf
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
# name = "wave"
# amplitude = 1.0
# period = 0.5
# phase = 20.0
# base_line = 0.0
# [[inputs.mock.step]]
# name = "plus_one"
Expand Down

0 comments on commit eb9f4ff

Please sign in to comment.