diff --git a/plugins/outputs/all/amon.go b/plugins/outputs/all/amon.go deleted file mode 100644 index b9e9335faf147..0000000000000 --- a/plugins/outputs/all/amon.go +++ /dev/null @@ -1,5 +0,0 @@ -//go:build !custom || outputs || outputs.amon - -package all - -import _ "github.com/influxdata/telegraf/plugins/outputs/amon" // register plugin diff --git a/plugins/outputs/amon/README.md b/plugins/outputs/amon/README.md deleted file mode 100644 index ba766b3f10b7f..0000000000000 --- a/plugins/outputs/amon/README.md +++ /dev/null @@ -1,45 +0,0 @@ -# Amon Output Plugin - -This plugin writes metrics to [Amon monitoring platform][amon]. It requires a -`serverkey` and `amoninstance` URL which can be obtained from the -[website][amon_monitoring] for your account. - -> [!IMPORTANT] -> If point values being sent cannot be converted to a `float64`, the metric is -> skipped. - -⭐ Telegraf v0.2.1 -🚩 Telegraf v1.37.0 -🔥 Telegraf v1.40.0 -🏷️ datastore -💻 all - -[amon]: https://www.amon.cx -[amon_monitoring]:https://www.amon.cx/docs/monitoring/ - -## Global configuration options - -Plugins support additional global and plugin configuration settings for tasks -such as modifying metrics, tags, and fields, creating aliases, and configuring -plugin ordering. See [CONFIGURATION.md][CONFIGURATION.md] for more details. - -[CONFIGURATION.md]: ../../../docs/CONFIGURATION.md#plugins - -## Configuration - -```toml @sample.conf -# Configuration for Amon Server to send metrics to. -[[outputs.amon]] - ## Amon Server Key - server_key = "my-server-key" # required. - - ## Amon Instance URL - amon_instance = "https://youramoninstance" # required - - ## Connection timeout. - # timeout = "5s" -``` - -## Conversions - -Metrics are grouped by converting any `_` characters to `.` in the point name diff --git a/plugins/outputs/amon/amon.go b/plugins/outputs/amon/amon.go deleted file mode 100644 index f4603b79ea524..0000000000000 --- a/plugins/outputs/amon/amon.go +++ /dev/null @@ -1,151 +0,0 @@ -//go:generate ../../../tools/readme_config_includer/generator -package amon - -import ( - "bytes" - _ "embed" - "encoding/json" - "errors" - "fmt" - "net/http" - "strings" - "time" - - "github.com/influxdata/telegraf" - "github.com/influxdata/telegraf/config" - "github.com/influxdata/telegraf/plugins/outputs" -) - -//go:embed sample.conf -var sampleConfig string - -type Amon struct { - ServerKey string `toml:"server_key"` - AmonInstance string `toml:"amon_instance"` - Timeout config.Duration `toml:"timeout"` - Log telegraf.Logger `toml:"-"` - - client *http.Client -} - -type TimeSeries struct { - Series []*Metric `json:"series"` -} - -type Metric struct { - Metric string `json:"metric"` - Points [1]Point `json:"metrics"` -} - -type Point [2]float64 - -func (*Amon) SampleConfig() string { - return sampleConfig -} - -func (a *Amon) Connect() error { - if a.ServerKey == "" || a.AmonInstance == "" { - return errors.New("serverkey and amon_instance are required fields for amon output") - } - a.client = &http.Client{ - Transport: &http.Transport{ - Proxy: http.ProxyFromEnvironment, - }, - Timeout: time.Duration(a.Timeout), - } - return nil -} - -func (a *Amon) Write(metrics []telegraf.Metric) error { - if len(metrics) == 0 { - return nil - } - - metricCounter := 0 - tempSeries := make([]*Metric, 0, len(metrics)) - for _, m := range metrics { - mname := strings.ReplaceAll(m.Name(), "_", ".") - if amonPts, err := buildMetrics(m); err == nil { - for fieldName, amonPt := range amonPts { - metric := &Metric{ - Metric: mname + "_" + strings.ReplaceAll(fieldName, "_", "."), - } - metric.Points[0] = amonPt - tempSeries = append(tempSeries, metric) - metricCounter++ - } - } else { - a.Log.Infof("Unable to build Metric for %s, skipping", m.Name()) - } - } - - ts := TimeSeries{} - ts.Series = make([]*Metric, metricCounter) - copy(ts.Series, tempSeries[0:]) - tsBytes, err := json.Marshal(ts) - if err != nil { - return fmt.Errorf("unable to marshal TimeSeries: %w", err) - } - req, err := http.NewRequest("POST", a.authenticatedURL(), bytes.NewBuffer(tsBytes)) - if err != nil { - return fmt.Errorf("unable to create http.Request: %w", err) - } - req.Header.Add("Content-Type", "application/json") - - resp, err := a.client.Do(req) - if err != nil { - return fmt.Errorf("error POSTing metrics: %w", err) - } - defer resp.Body.Close() - - if resp.StatusCode < 200 || resp.StatusCode > 209 { - return fmt.Errorf("received bad status code, %d", resp.StatusCode) - } - - return nil -} - -func (a *Amon) authenticatedURL() string { - return fmt.Sprintf("%s/api/system/%s", a.AmonInstance, a.ServerKey) -} - -func buildMetrics(m telegraf.Metric) (map[string]Point, error) { - ms := make(map[string]Point) - for k, v := range m.Fields() { - var p Point - if err := p.setValue(v); err != nil { - return ms, fmt.Errorf("unable to extract value from Fields: %w", err) - } - p[0] = float64(m.Time().Unix()) - ms[k] = p - } - return ms, nil -} - -func (p *Point) setValue(v interface{}) error { - switch d := v.(type) { - case int: - p[1] = float64(d) - case int32: - p[1] = float64(d) - case int64: - p[1] = float64(d) - case float32: - p[1] = float64(d) - case float64: - p[1] = d - default: - return errors.New("undeterminable type") - } - return nil -} - -func (*Amon) Close() error { - return nil -} - -func init() { - outputs.Add("amon", func() telegraf.Output { - return &Amon{} - }) -} diff --git a/plugins/outputs/amon/amon_test.go b/plugins/outputs/amon/amon_test.go deleted file mode 100644 index 21c7fc1edaf89..0000000000000 --- a/plugins/outputs/amon/amon_test.go +++ /dev/null @@ -1,89 +0,0 @@ -package amon - -import ( - "errors" - "reflect" - "testing" - "time" - - "github.com/influxdata/telegraf" - "github.com/influxdata/telegraf/testutil" -) - -func TestBuildPoint(t *testing.T) { - var tagtests = []struct { - ptIn telegraf.Metric - outPt Point - err error - }{ - { - testutil.TestMetric(float64(0.0), "testpt"), - Point{ - float64(time.Date(2009, time.November, 10, 23, 0, 0, 0, time.UTC).Unix()), - 0.0, - }, - nil, - }, - { - testutil.TestMetric(float64(1.0), "testpt"), - Point{ - float64(time.Date(2009, time.November, 10, 23, 0, 0, 0, time.UTC).Unix()), - 1.0, - }, - nil, - }, - { - testutil.TestMetric(int(10), "testpt"), - Point{ - float64(time.Date(2009, time.November, 10, 23, 0, 0, 0, time.UTC).Unix()), - 10.0, - }, - nil, - }, - { - testutil.TestMetric(int32(112345), "testpt"), - Point{ - float64(time.Date(2009, time.November, 10, 23, 0, 0, 0, time.UTC).Unix()), - 112345.0, - }, - nil, - }, - { - testutil.TestMetric(int64(112345), "testpt"), - Point{ - float64(time.Date(2009, time.November, 10, 23, 0, 0, 0, time.UTC).Unix()), - 112345.0, - }, - nil, - }, - { - testutil.TestMetric(float32(11234.5), "testpt"), - Point{ - float64(time.Date(2009, time.November, 10, 23, 0, 0, 0, time.UTC).Unix()), - 11234.5, - }, - nil, - }, - { - testutil.TestMetric("11234.5", "testpt"), - Point{ - float64(time.Date(2009, time.November, 10, 23, 0, 0, 0, time.UTC).Unix()), - 11234.5, - }, - errors.New("unable to extract value from Fields, undeterminable type"), - }, - } - for _, tt := range tagtests { - pt, err := buildMetrics(tt.ptIn) - if err != nil && tt.err == nil { - t.Errorf("%s: unexpected error, %+v\n", tt.ptIn.Name(), err) - } - if tt.err != nil && err == nil { - t.Errorf("%s: expected an error (%s) but none returned", tt.ptIn.Name(), tt.err.Error()) - } - if !reflect.DeepEqual(pt["value"], tt.outPt) && tt.err == nil { - t.Errorf("%s: \nexpected %+v\ngot %+v\n", - tt.ptIn.Name(), tt.outPt, pt["value"]) - } - } -} diff --git a/plugins/outputs/amon/sample.conf b/plugins/outputs/amon/sample.conf deleted file mode 100644 index 6e8e6ef91eb47..0000000000000 --- a/plugins/outputs/amon/sample.conf +++ /dev/null @@ -1,10 +0,0 @@ -# Configuration for Amon Server to send metrics to. -[[outputs.amon]] - ## Amon Server Key - server_key = "my-server-key" # required. - - ## Amon Instance URL - amon_instance = "https://youramoninstance" # required - - ## Connection timeout. - # timeout = "5s"