1
0
Fork 0

Adding upstream version 1.34.4.

Signed-off-by: Daniel Baumann <daniel@debian.org>
This commit is contained in:
Daniel Baumann 2025-05-24 07:26:29 +02:00
parent e393c3af3f
commit 4978089aab
Signed by: daniel
GPG key ID: FBB4F0E80A80222F
4963 changed files with 677545 additions and 0 deletions

View file

@ -0,0 +1,36 @@
# Trig Input Plugin
The `trig` plugin is for demonstration purposes and inserts sine and cosine
## Global configuration options <!-- @/docs/includes/plugin_config.md -->
In addition to the plugin-specific configuration settings, plugins support
additional global and plugin configuration settings. These settings are used to
modify metrics, tags, and field or create aliases and configure ordering, etc.
See the [CONFIGURATION.md][CONFIGURATION.md] for more details.
[CONFIGURATION.md]: ../../../docs/CONFIGURATION.md#plugins
## Configuration
```toml @sample.conf
# Inserts sine and cosine waves for demonstration purposes
[[inputs.trig]]
## Set the amplitude
amplitude = 10.0
```
## Metrics
- trig
- fields:
- cosine (float)
- sine (float)
## Example Output
```text
trig,host=MBP15-SWANG.local cosine=10,sine=0 1632338680000000000
trig,host=MBP15-SWANG.local sine=5.877852522924732,cosine=8.090169943749473 1632338690000000000
trig,host=MBP15-SWANG.local sine=9.510565162951535,cosine=3.0901699437494745 1632338700000000000
```

View file

@ -0,0 +1,4 @@
# Inserts sine and cosine waves for demonstration purposes
[[inputs.trig]]
## Set the amplitude
amplitude = 10.0

View file

@ -0,0 +1,42 @@
//go:generate ../../../tools/readme_config_includer/generator
package trig
import (
_ "embed"
"math"
"github.com/influxdata/telegraf"
"github.com/influxdata/telegraf/plugins/inputs"
)
//go:embed sample.conf
var sampleConfig string
type Trig struct {
Amplitude float64 `toml:"amplitude"`
x float64
}
func (*Trig) SampleConfig() string {
return sampleConfig
}
func (s *Trig) Gather(acc telegraf.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() telegraf.Input { return &Trig{x: 0.0} })
}

View file

@ -0,0 +1,31 @@
package trig
import (
"math"
"testing"
"github.com/stretchr/testify/require"
"github.com/influxdata/telegraf/testutil"
)
func TestTrig(t *testing.T) {
s := &Trig{
Amplitude: 10.0,
}
for i := 0.0; i < 10.0; i++ {
var acc testutil.Accumulator
sine := math.Sin((i*math.Pi)/5.0) * s.Amplitude
cosine := math.Cos((i*math.Pi)/5.0) * s.Amplitude
require.NoError(t, s.Gather(&acc))
fields := make(map[string]interface{})
fields["sine"] = sine
fields["cosine"] = cosine
acc.AssertContainsFields(t, "trig", fields)
}
}