From eb9f4ff7f8d38ef949b15115478800c5e13b066f Mon Sep 17 00:00:00 2001 From: Lars Stegman Date: Mon, 7 Oct 2024 16:09:19 +0200 Subject: [PATCH] feat(inputs.mock): Add sine phase --- plugins/inputs/mock/README.md | 1 + plugins/inputs/mock/mock.go | 3 ++- plugins/inputs/mock/sample.conf | 1 + 3 files changed, 4 insertions(+), 1 deletion(-) diff --git a/plugins/inputs/mock/README.md b/plugins/inputs/mock/README.md index f7bad4f45c52e..cc420cdcabf85 100644 --- a/plugins/inputs/mock/README.md +++ b/plugins/inputs/mock/README.md @@ -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" diff --git a/plugins/inputs/mock/mock.go b/plugins/inputs/mock/mock.go index 0c4f9ec6af125..94e94175272ad 100644 --- a/plugins/inputs/mock/mock.go +++ b/plugins/inputs/mock/mock.go @@ -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"` } @@ -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 } } diff --git a/plugins/inputs/mock/sample.conf b/plugins/inputs/mock/sample.conf index da06a5b6efcd4..b08cbc507452f 100644 --- a/plugins/inputs/mock/sample.conf +++ b/plugins/inputs/mock/sample.conf @@ -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"