Skip to content

Commit

Permalink
chore: Embed sample configurations into README for inputs (#11136)
Browse files Browse the repository at this point in the history
  • Loading branch information
srebhan authored May 24, 2022
1 parent a840006 commit 56eb914
Show file tree
Hide file tree
Showing 677 changed files with 3,164 additions and 2,422 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
/telegraf
/telegraf.exe
/telegraf.gz
/tools/readme_config_includer/generator
/vendor
.DS_Store
process.yml
Expand Down
17 changes: 14 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -115,13 +115,22 @@ versioninfo:
go run scripts/generate_versioninfo/main.go; \
go generate cmd/telegraf/telegraf_windows.go; \

.PHONY: build_generator
build_generator:
go build -o ./tools/readme_config_includer/generator ./tools/readme_config_includer/generator.go

insert_config_to_readme_%: build_generator
go generate -run="readme_config_includer/generator$$" ./plugins/$*/...

generate_plugins_%: build_generator
go generate -run="plugindata/main.go$$" ./plugins/$*/...

.PHONY: generate
generate:
go generate -run="plugindata/main.go$$" ./plugins/inputs/... ./plugins/outputs/... ./plugins/processors/... ./plugins/aggregators/...
generate: insert_config_to_readme_inputs generate_plugins_outputs generate_plugins_processors generate_plugins_aggregators

.PHONY: generate-clean
generate-clean:
go generate -run="plugindata/main.go --clean" ./plugins/inputs/... ./plugins/outputs/... ./plugins/processors/... ./plugins/aggregators/...
go generate -run="plugindata/main.go --clean" ./plugins/outputs/... ./plugins/processors/... ./plugins/aggregators/...

.PHONY: build
build:
Expand Down Expand Up @@ -223,6 +232,8 @@ clean:
rm -f telegraf
rm -f telegraf.exe
rm -rf build
rm -rf tools/readme_config_includer/generator
rm -rf tools/readme_config_includer/generator.exe

.PHONY: docker-image
docker-image:
Expand Down
2 changes: 1 addition & 1 deletion docs/CONFIGURATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -539,7 +539,7 @@ The inverse of `tagpass`. If a match is found the metric is discarded. This
is tested on metrics after they have passed the `tagpass` test.

> NOTE: Due to the way TOML is parsed, `tagpass` and `tagdrop` parameters must be
defined at the *_end_* of the plugin definition, otherwise subsequent plugin config
defined at the **end** of the plugin definition, otherwise subsequent plugin config
options will be interpreted as part of the tagpass/tagdrop tables.

### Modifiers
Expand Down
2 changes: 1 addition & 1 deletion plugins/inputs/activemq/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ This plugin gather queues, topics & subscribers metrics using ActiveMQ Console A

## Configuration

```toml
```toml @sample.conf
# Gather ActiveMQ metrics
[[inputs.activemq]]
## ActiveMQ WebConsole URL
Expand Down
10 changes: 10 additions & 0 deletions plugins/inputs/activemq/activemq.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
//go:generate ../../../tools/readme_config_includer/generator
package activemq

import (
_ "embed"
"encoding/xml"
"fmt"
"io"
Expand All @@ -17,6 +19,10 @@ import (
"github.com/influxdata/telegraf/plugins/inputs"
)

// DO NOT REMOVE THE NEXT TWO LINES! This is required to embedd the sampleConfig data.
//go:embed sample.conf
var sampleConfig string

type ActiveMQ struct {
Server string `toml:"server" deprecated:"1.11.0;use 'url' instead"`
Port int `toml:"port" deprecated:"1.11.0;use 'url' instead"`
Expand Down Expand Up @@ -98,6 +104,10 @@ func (a *ActiveMQ) createHTTPClient() (*http.Client, error) {
return client, nil
}

func (*ActiveMQ) SampleConfig() string {
return sampleConfig
}

func (a *ActiveMQ) Init() error {
if a.ResponseTimeout < config.Duration(time.Second) {
a.ResponseTimeout = config.Duration(time.Second * 5)
Expand Down
8 changes: 0 additions & 8 deletions plugins/inputs/activemq/activemq_sample_config.go

This file was deleted.

2 changes: 1 addition & 1 deletion plugins/inputs/aerospike/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ All metrics are attempted to be cast to integers, then booleans, then strings.

## Configuration

```toml
```toml @sample.conf
# Read stats from aerospike server(s)
[[inputs.aerospike]]
## Aerospike servers to connect to (with port)
Expand Down
10 changes: 10 additions & 0 deletions plugins/inputs/aerospike/aerospike.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
//go:generate ../../../tools/readme_config_includer/generator
package aerospike

import (
"crypto/tls"
_ "embed"
"fmt"
"math"
"strconv"
Expand All @@ -16,6 +18,10 @@ import (
"github.com/influxdata/telegraf/plugins/inputs"
)

// DO NOT REMOVE THE NEXT TWO LINES! This is required to embedd the sampleConfig data.
//go:embed sample.conf
var sampleConfig string

type Aerospike struct {
Servers []string `toml:"servers"`

Expand Down Expand Up @@ -50,6 +56,10 @@ var protectedHexFields = map[string]bool{
"paxos_principal": true,
}

func (*Aerospike) SampleConfig() string {
return sampleConfig
}

func (a *Aerospike) Gather(acc telegraf.Accumulator) error {
if !a.initialized {
tlsConfig, err := a.ClientConfig.TLSConfig()
Expand Down
8 changes: 0 additions & 8 deletions plugins/inputs/aerospike/aerospike_sample_config.go

This file was deleted.

2 changes: 1 addition & 1 deletion plugins/inputs/aliyuncms/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ In the following order the plugin will attempt to authenticate.

## Configuration

```toml
```toml @sample.conf
# Pull Metric Statistics from Aliyun CMS
[[inputs.aliyuncms]]
## Aliyun Credentials
Expand Down
15 changes: 13 additions & 2 deletions plugins/inputs/aliyuncms/aliyuncms.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
//go:generate ../../../tools/readme_config_includer/generator
package aliyuncms

import (
_ "embed"
"encoding/json"
"fmt"
"strconv"
Expand All @@ -11,15 +13,20 @@ import (
"github.com/aliyun/alibaba-cloud-sdk-go/sdk"
"github.com/aliyun/alibaba-cloud-sdk-go/sdk/auth/credentials/providers"
"github.com/aliyun/alibaba-cloud-sdk-go/services/cms"
"github.com/jmespath/go-jmespath"
"github.com/pkg/errors"

"github.com/influxdata/telegraf"
"github.com/influxdata/telegraf/config"
"github.com/influxdata/telegraf/internal"
"github.com/influxdata/telegraf/internal/limiter"
"github.com/influxdata/telegraf/plugins/inputs"
"github.com/jmespath/go-jmespath"
"github.com/pkg/errors"
)

// DO NOT REMOVE THE NEXT TWO LINES! This is required to embedd the sampleConfig data.
//go:embed sample.conf
var sampleConfig string

type (
// AliyunCMS is aliyun cms config info.
AliyunCMS struct {
Expand Down Expand Up @@ -103,6 +110,10 @@ var aliyunRegionList = []string{
"me-east-1",
}

func (*AliyunCMS) SampleConfig() string {
return sampleConfig
}

// Init perform checks of plugin inputs and initialize internals
func (s *AliyunCMS) Init() error {
if s.Project == "" {
Expand Down
8 changes: 0 additions & 8 deletions plugins/inputs/aliyuncms/aliyuncms_sample_config.go

This file was deleted.

2 changes: 1 addition & 1 deletion plugins/inputs/amd_rocm_smi/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ This plugin uses a query on the [`rocm-smi`](https://github.com/RadeonOpenComput

## Configuration

```toml
```toml @sample.conf
# Query statistics from AMD Graphics cards using rocm-smi binary
[[inputs.amd_rocm_smi]]
## Optional: path to rocm-smi binary, defaults to $PATH via exec.LookPath
Expand Down
10 changes: 10 additions & 0 deletions plugins/inputs/amd_rocm_smi/amd_rocm_smi.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
//go:generate ../../../tools/readme_config_includer/generator
package amd_rocm_smi

import (
_ "embed"
"encoding/json"
"fmt"
"os"
Expand All @@ -15,13 +17,21 @@ import (
"github.com/influxdata/telegraf/plugins/inputs"
)

// DO NOT REMOVE THE NEXT TWO LINES! This is required to embedd the sampleConfig data.
//go:embed sample.conf
var sampleConfig string

const measurement = "amd_rocm_smi"

type ROCmSMI struct {
BinPath string
Timeout config.Duration
}

func (*ROCmSMI) SampleConfig() string {
return sampleConfig
}

// Gather implements the telegraf interface
func (rsmi *ROCmSMI) Gather(acc telegraf.Accumulator) error {
if _, err := os.Stat(rsmi.BinPath); os.IsNotExist(err) {
Expand Down
8 changes: 0 additions & 8 deletions plugins/inputs/amd_rocm_smi/amd_rocm_smi_sample_config.go

This file was deleted.

2 changes: 1 addition & 1 deletion plugins/inputs/amqp_consumer/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ For an introduction to AMQP see:

The following defaults are known to work with RabbitMQ:

```toml
```toml @sample.conf
# AMQP consumer plugin
[[inputs.amqp_consumer]]
## Brokers to consume from. If multiple brokers are specified a random broker
Expand Down
10 changes: 10 additions & 0 deletions plugins/inputs/amqp_consumer/amqp_consumer.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
//go:generate ../../../tools/readme_config_includer/generator
package amqp_consumer

import (
"context"
_ "embed"
"errors"
"fmt"
"math/rand"
Expand All @@ -18,6 +20,10 @@ import (
"github.com/influxdata/telegraf/plugins/parsers"
)

// DO NOT REMOVE THE NEXT TWO LINES! This is required to embedd the sampleConfig data.
//go:embed sample.conf
var sampleConfig string

const (
defaultMaxUndeliveredMessages = 1000
)
Expand Down Expand Up @@ -88,6 +94,10 @@ const (
DefaultPrefetchCount = 50
)

func (*AMQPConsumer) SampleConfig() string {
return sampleConfig
}

func (a *AMQPConsumer) SetParser(parser parsers.Parser) {
a.parser = parser
}
Expand Down
8 changes: 0 additions & 8 deletions plugins/inputs/amqp_consumer/amqp_consumer_sample_config.go

This file was deleted.

2 changes: 1 addition & 1 deletion plugins/inputs/apache/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Typically, the `mod_status` module is configured to expose a page at the `/serve

## Configuration

```toml
```toml @sample.conf
# Read Apache status information (mod_status)
[[inputs.apache]]
## An array of URLs to gather from, must be directed at the machine
Expand Down
10 changes: 10 additions & 0 deletions plugins/inputs/apache/apache.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
//go:generate ../../../tools/readme_config_includer/generator
package apache

import (
"bufio"
_ "embed"
"fmt"
"net"
"net/http"
Expand All @@ -17,6 +19,10 @@ import (
"github.com/influxdata/telegraf/plugins/inputs"
)

// DO NOT REMOVE THE NEXT TWO LINES! This is required to embedd the sampleConfig data.
//go:embed sample.conf
var sampleConfig string

type Apache struct {
Urls []string
Username string
Expand All @@ -27,6 +33,10 @@ type Apache struct {
client *http.Client
}

func (*Apache) SampleConfig() string {
return sampleConfig
}

func (n *Apache) Gather(acc telegraf.Accumulator) error {
var wg sync.WaitGroup

Expand Down
8 changes: 0 additions & 8 deletions plugins/inputs/apache/apache_sample_config.go

This file was deleted.

2 changes: 1 addition & 1 deletion plugins/inputs/apcupsd/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ apcupsd should be installed and it's daemon should be running.

## Configuration

```toml
```toml @sample.conf
# Monitor APC UPSes connected to apcupsd
[[inputs.apcupsd]]
# A list of running apcupsd server to connect to.
Expand Down
Loading

0 comments on commit 56eb914

Please sign in to comment.