diff --git a/.gitignore b/.gitignore index ec7f96954a8ed..d78b6c1c190e7 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,7 @@ /telegraf /telegraf.exe /telegraf.gz +/tools/readme_config_includer/generator /vendor .DS_Store process.yml diff --git a/Makefile b/Makefile index 7962c6a5633c4..e3bf473f92524 100644 --- a/Makefile +++ b/Makefile @@ -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: @@ -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: diff --git a/docs/CONFIGURATION.md b/docs/CONFIGURATION.md index 147316424c492..06644d12bbe56 100644 --- a/docs/CONFIGURATION.md +++ b/docs/CONFIGURATION.md @@ -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 diff --git a/plugins/inputs/activemq/README.md b/plugins/inputs/activemq/README.md index d02dc94537f94..a9541e99f5c54 100644 --- a/plugins/inputs/activemq/README.md +++ b/plugins/inputs/activemq/README.md @@ -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 diff --git a/plugins/inputs/activemq/activemq.go b/plugins/inputs/activemq/activemq.go index f439769094e07..4dcfb48d9cc28 100644 --- a/plugins/inputs/activemq/activemq.go +++ b/plugins/inputs/activemq/activemq.go @@ -1,6 +1,8 @@ +//go:generate ../../../tools/readme_config_includer/generator package activemq import ( + _ "embed" "encoding/xml" "fmt" "io" @@ -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"` @@ -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) diff --git a/plugins/inputs/activemq/activemq_sample_config.go b/plugins/inputs/activemq/activemq_sample_config.go deleted file mode 100644 index 9170d43a9feee..0000000000000 --- a/plugins/inputs/activemq/activemq_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package activemq - -func (a *ActiveMQ) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/inputs/aerospike/README.md b/plugins/inputs/aerospike/README.md index 922dfeab8b870..f84cb5e022c35 100644 --- a/plugins/inputs/aerospike/README.md +++ b/plugins/inputs/aerospike/README.md @@ -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) diff --git a/plugins/inputs/aerospike/aerospike.go b/plugins/inputs/aerospike/aerospike.go index 50c1f2306beab..6fc29a2823953 100644 --- a/plugins/inputs/aerospike/aerospike.go +++ b/plugins/inputs/aerospike/aerospike.go @@ -1,7 +1,9 @@ +//go:generate ../../../tools/readme_config_includer/generator package aerospike import ( "crypto/tls" + _ "embed" "fmt" "math" "strconv" @@ -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"` @@ -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() diff --git a/plugins/inputs/aerospike/aerospike_sample_config.go b/plugins/inputs/aerospike/aerospike_sample_config.go deleted file mode 100644 index 1c42b63b4ada6..0000000000000 --- a/plugins/inputs/aerospike/aerospike_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package aerospike - -func (a *Aerospike) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/inputs/aliyuncms/README.md b/plugins/inputs/aliyuncms/README.md index 03e6a27484516..1480c0ebc9812 100644 --- a/plugins/inputs/aliyuncms/README.md +++ b/plugins/inputs/aliyuncms/README.md @@ -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 diff --git a/plugins/inputs/aliyuncms/aliyuncms.go b/plugins/inputs/aliyuncms/aliyuncms.go index 9dfd8dd3284a5..14bab434467c0 100644 --- a/plugins/inputs/aliyuncms/aliyuncms.go +++ b/plugins/inputs/aliyuncms/aliyuncms.go @@ -1,6 +1,8 @@ +//go:generate ../../../tools/readme_config_includer/generator package aliyuncms import ( + _ "embed" "encoding/json" "fmt" "strconv" @@ -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 { @@ -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 == "" { diff --git a/plugins/inputs/aliyuncms/aliyuncms_sample_config.go b/plugins/inputs/aliyuncms/aliyuncms_sample_config.go deleted file mode 100644 index 53fff350e4022..0000000000000 --- a/plugins/inputs/aliyuncms/aliyuncms_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package aliyuncms - -func (s *AliyunCMS) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/inputs/amd_rocm_smi/README.md b/plugins/inputs/amd_rocm_smi/README.md index 392cb94e00704..776ee8502fc77 100644 --- a/plugins/inputs/amd_rocm_smi/README.md +++ b/plugins/inputs/amd_rocm_smi/README.md @@ -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 diff --git a/plugins/inputs/amd_rocm_smi/amd_rocm_smi.go b/plugins/inputs/amd_rocm_smi/amd_rocm_smi.go index f613a7017ac83..9e26cf07b9440 100644 --- a/plugins/inputs/amd_rocm_smi/amd_rocm_smi.go +++ b/plugins/inputs/amd_rocm_smi/amd_rocm_smi.go @@ -1,6 +1,8 @@ +//go:generate ../../../tools/readme_config_includer/generator package amd_rocm_smi import ( + _ "embed" "encoding/json" "fmt" "os" @@ -15,6 +17,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 + const measurement = "amd_rocm_smi" type ROCmSMI struct { @@ -22,6 +28,10 @@ type ROCmSMI struct { 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) { diff --git a/plugins/inputs/amd_rocm_smi/amd_rocm_smi_sample_config.go b/plugins/inputs/amd_rocm_smi/amd_rocm_smi_sample_config.go deleted file mode 100644 index 2508f6004c0d8..0000000000000 --- a/plugins/inputs/amd_rocm_smi/amd_rocm_smi_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package amd_rocm_smi - -func (rsmi *ROCmSMI) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/inputs/amqp_consumer/README.md b/plugins/inputs/amqp_consumer/README.md index c3455b0255372..11f9680ef1357 100644 --- a/plugins/inputs/amqp_consumer/README.md +++ b/plugins/inputs/amqp_consumer/README.md @@ -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 diff --git a/plugins/inputs/amqp_consumer/amqp_consumer.go b/plugins/inputs/amqp_consumer/amqp_consumer.go index 7d4ef02d80ad5..127b57ac23ce1 100644 --- a/plugins/inputs/amqp_consumer/amqp_consumer.go +++ b/plugins/inputs/amqp_consumer/amqp_consumer.go @@ -1,7 +1,9 @@ +//go:generate ../../../tools/readme_config_includer/generator package amqp_consumer import ( "context" + _ "embed" "errors" "fmt" "math/rand" @@ -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 ) @@ -88,6 +94,10 @@ const ( DefaultPrefetchCount = 50 ) +func (*AMQPConsumer) SampleConfig() string { + return sampleConfig +} + func (a *AMQPConsumer) SetParser(parser parsers.Parser) { a.parser = parser } diff --git a/plugins/inputs/amqp_consumer/amqp_consumer_sample_config.go b/plugins/inputs/amqp_consumer/amqp_consumer_sample_config.go deleted file mode 100644 index d92caaf7d006c..0000000000000 --- a/plugins/inputs/amqp_consumer/amqp_consumer_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package amqp_consumer - -func (a *AMQPConsumer) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/inputs/apache/README.md b/plugins/inputs/apache/README.md index 710d8cbca7d5e..8c24992035841 100644 --- a/plugins/inputs/apache/README.md +++ b/plugins/inputs/apache/README.md @@ -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 diff --git a/plugins/inputs/apache/apache.go b/plugins/inputs/apache/apache.go index d03d22c324b43..43b4c3c0b7d3d 100644 --- a/plugins/inputs/apache/apache.go +++ b/plugins/inputs/apache/apache.go @@ -1,7 +1,9 @@ +//go:generate ../../../tools/readme_config_includer/generator package apache import ( "bufio" + _ "embed" "fmt" "net" "net/http" @@ -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 @@ -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 diff --git a/plugins/inputs/apache/apache_sample_config.go b/plugins/inputs/apache/apache_sample_config.go deleted file mode 100644 index 4de4091fd3793..0000000000000 --- a/plugins/inputs/apache/apache_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package apache - -func (n *Apache) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/inputs/apcupsd/README.md b/plugins/inputs/apcupsd/README.md index f02dc05524395..d97325d7b06d0 100644 --- a/plugins/inputs/apcupsd/README.md +++ b/plugins/inputs/apcupsd/README.md @@ -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. diff --git a/plugins/inputs/apcupsd/apcupsd.go b/plugins/inputs/apcupsd/apcupsd.go index bd90103dd29e7..7620540e8267e 100644 --- a/plugins/inputs/apcupsd/apcupsd.go +++ b/plugins/inputs/apcupsd/apcupsd.go @@ -1,7 +1,9 @@ +//go:generate ../../../tools/readme_config_includer/generator package apcupsd import ( "context" + _ "embed" "net/url" "strconv" "strings" @@ -14,6 +16,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 + const defaultAddress = "tcp://127.0.0.1:3551" var defaultTimeout = config.Duration(5 * time.Second) @@ -23,6 +29,10 @@ type ApcUpsd struct { Timeout config.Duration } +func (*ApcUpsd) SampleConfig() string { + return sampleConfig +} + func (h *ApcUpsd) Gather(acc telegraf.Accumulator) error { ctx := context.Background() diff --git a/plugins/inputs/apcupsd/apcupsd_sample_config.go b/plugins/inputs/apcupsd/apcupsd_sample_config.go deleted file mode 100644 index 7d8df9f417726..0000000000000 --- a/plugins/inputs/apcupsd/apcupsd_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package apcupsd - -func (*ApcUpsd) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/inputs/aurora/README.md b/plugins/inputs/aurora/README.md index 0519c97b36381..58ab5fda64534 100644 --- a/plugins/inputs/aurora/README.md +++ b/plugins/inputs/aurora/README.md @@ -6,7 +6,7 @@ For monitoring recommendations reference [Monitoring your Aurora cluster](https: ## Configuration -```toml +```toml @sample.conf # Gather metrics from Apache Aurora schedulers [[inputs.aurora]] ## Schedulers are the base addresses of your Aurora Schedulers diff --git a/plugins/inputs/aurora/aurora.go b/plugins/inputs/aurora/aurora.go index e32a00de6f890..0d033ea27bb4b 100644 --- a/plugins/inputs/aurora/aurora.go +++ b/plugins/inputs/aurora/aurora.go @@ -1,7 +1,9 @@ +//go:generate ../../../tools/readme_config_includer/generator package aurora import ( "context" + _ "embed" "encoding/json" "fmt" "net/http" @@ -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 RoleType int const ( @@ -54,6 +60,10 @@ type Aurora struct { urls []*url.URL } +func (*Aurora) SampleConfig() string { + return sampleConfig +} + func (a *Aurora) Gather(acc telegraf.Accumulator) error { if a.client == nil { err := a.initialize() diff --git a/plugins/inputs/aurora/aurora_sample_config.go b/plugins/inputs/aurora/aurora_sample_config.go deleted file mode 100644 index daeb8151646de..0000000000000 --- a/plugins/inputs/aurora/aurora_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package aurora - -func (a *Aurora) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/inputs/azure_storage_queue/README.md b/plugins/inputs/azure_storage_queue/README.md index ded9910640553..8427e71b4c464 100644 --- a/plugins/inputs/azure_storage_queue/README.md +++ b/plugins/inputs/azure_storage_queue/README.md @@ -4,7 +4,7 @@ This plugin gathers sizes of Azure Storage Queues. ## Configuration -```toml +```toml @sample.conf # Gather Azure Storage Queue metrics [[inputs.azure_storage_queue]] ## Required Azure Storage Account name diff --git a/plugins/inputs/azure_storage_queue/azure_storage_queue.go b/plugins/inputs/azure_storage_queue/azure_storage_queue.go index e582b4213dccc..a6668e9984d50 100644 --- a/plugins/inputs/azure_storage_queue/azure_storage_queue.go +++ b/plugins/inputs/azure_storage_queue/azure_storage_queue.go @@ -1,17 +1,24 @@ +//go:generate ../../../tools/readme_config_includer/generator package azure_storage_queue import ( "context" + _ "embed" "errors" "net/url" "strings" "time" "github.com/Azure/azure-storage-queue-go/azqueue" + "github.com/influxdata/telegraf" "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 AzureStorageQueue struct { StorageAccountName string `toml:"account_name"` StorageAccountKey string `toml:"account_key"` @@ -21,6 +28,10 @@ type AzureStorageQueue struct { serviceURL *azqueue.ServiceURL } +func (*AzureStorageQueue) SampleConfig() string { + return sampleConfig +} + func (a *AzureStorageQueue) Init() error { if a.StorageAccountName == "" { return errors.New("account_name must be configured") diff --git a/plugins/inputs/azure_storage_queue/azure_storage_queue_sample_config.go b/plugins/inputs/azure_storage_queue/azure_storage_queue_sample_config.go deleted file mode 100644 index 3e3b123c03c03..0000000000000 --- a/plugins/inputs/azure_storage_queue/azure_storage_queue_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package azure_storage_queue - -func (a *AzureStorageQueue) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/inputs/bcache/README.md b/plugins/inputs/bcache/README.md index 0ab326e2dcd81..ae5fcdc807aff 100644 --- a/plugins/inputs/bcache/README.md +++ b/plugins/inputs/bcache/README.md @@ -55,7 +55,7 @@ cache_readaheads Using this configuration: -```toml +```toml @sample.conf # Read metrics of bcache from stats_total and dirty_data [[inputs.bcache]] ## Bcache sets path diff --git a/plugins/inputs/bcache/bcache.go b/plugins/inputs/bcache/bcache.go index e46100d17370e..ba3589e4f594d 100644 --- a/plugins/inputs/bcache/bcache.go +++ b/plugins/inputs/bcache/bcache.go @@ -1,3 +1,4 @@ +//go:generate ../../../tools/readme_config_includer/generator //go:build !windows // +build !windows @@ -6,6 +7,7 @@ package bcache import ( + _ "embed" "errors" "fmt" "os" @@ -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 Bcache struct { BcachePath string BcacheDevs []string @@ -94,6 +100,10 @@ func (b *Bcache) gatherBcache(bdev string, acc telegraf.Accumulator) error { return nil } +func (*Bcache) SampleConfig() string { + return sampleConfig +} + func (b *Bcache) Gather(acc telegraf.Accumulator) error { bcacheDevsChecked := make(map[string]bool) var restrictDevs bool diff --git a/plugins/inputs/bcache/bcache_sample_config.go b/plugins/inputs/bcache/bcache_sample_config.go deleted file mode 100644 index 396a4815ad6c2..0000000000000 --- a/plugins/inputs/bcache/bcache_sample_config.go +++ /dev/null @@ -1,11 +0,0 @@ -//go:build !windows -// +build !windows - -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package bcache - -func (b *Bcache) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/inputs/beanstalkd/README.md b/plugins/inputs/beanstalkd/README.md index feebca634d451..b548b15065783 100644 --- a/plugins/inputs/beanstalkd/README.md +++ b/plugins/inputs/beanstalkd/README.md @@ -4,7 +4,7 @@ The `beanstalkd` plugin collects server stats as well as tube stats (reported by ## Configuration -```toml +```toml @sample.conf # Collects Beanstalkd server and tubes stats [[inputs.beanstalkd]] ## Server to collect data from diff --git a/plugins/inputs/beanstalkd/beanstalkd.go b/plugins/inputs/beanstalkd/beanstalkd.go index 9d67b70b8bbe3..3748e3209bfa0 100644 --- a/plugins/inputs/beanstalkd/beanstalkd.go +++ b/plugins/inputs/beanstalkd/beanstalkd.go @@ -1,21 +1,32 @@ +//go:generate ../../../tools/readme_config_includer/generator package beanstalkd import ( + _ "embed" "fmt" "io" "net/textproto" "sync" + "gopkg.in/yaml.v2" + "github.com/influxdata/telegraf" "github.com/influxdata/telegraf/plugins/inputs" - "gopkg.in/yaml.v2" ) +// DO NOT REMOVE THE NEXT TWO LINES! This is required to embedd the sampleConfig data. +//go:embed sample.conf +var sampleConfig string + type Beanstalkd struct { Server string `toml:"server"` Tubes []string `toml:"tubes"` } +func (*Beanstalkd) SampleConfig() string { + return sampleConfig +} + func (b *Beanstalkd) Gather(acc telegraf.Accumulator) error { connection, err := textproto.Dial("tcp", b.Server) if err != nil { diff --git a/plugins/inputs/beanstalkd/beanstalkd_sample_config.go b/plugins/inputs/beanstalkd/beanstalkd_sample_config.go deleted file mode 100644 index d1a8201977828..0000000000000 --- a/plugins/inputs/beanstalkd/beanstalkd_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package beanstalkd - -func (b *Beanstalkd) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/inputs/beat/README.md b/plugins/inputs/beat/README.md index ecf6f5edbca7b..a3a5fdc49de0a 100644 --- a/plugins/inputs/beat/README.md +++ b/plugins/inputs/beat/README.md @@ -5,7 +5,7 @@ known to work with Filebeat and Kafkabeat. ## Configuration -```toml +```toml @sample.conf # Read metrics exposed by Beat [[inputs.beat]] ## An URL from which to read Beat-formatted JSON diff --git a/plugins/inputs/beat/beat.go b/plugins/inputs/beat/beat.go index b76ff0a4bc311..77a37d8830f33 100644 --- a/plugins/inputs/beat/beat.go +++ b/plugins/inputs/beat/beat.go @@ -1,6 +1,8 @@ +//go:generate ../../../tools/readme_config_includer/generator package beat import ( + _ "embed" "encoding/json" "fmt" "net/http" @@ -15,6 +17,10 @@ import ( jsonparser "github.com/influxdata/telegraf/plugins/parsers/json" ) +// DO NOT REMOVE THE NEXT TWO LINES! This is required to embedd the sampleConfig data. +//go:embed sample.conf +var sampleConfig string + const suffixInfo = "/" const suffixStats = "/stats" @@ -59,6 +65,10 @@ func NewBeat() *Beat { } } +func (*Beat) SampleConfig() string { + return sampleConfig +} + func (beat *Beat) Init() error { availableStats := []string{"beat", "libbeat", "system", "filebeat"} diff --git a/plugins/inputs/beat/beat_sample_config.go b/plugins/inputs/beat/beat_sample_config.go deleted file mode 100644 index 000752ff3b692..0000000000000 --- a/plugins/inputs/beat/beat_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package beat - -func (beat *Beat) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/inputs/bind/README.md b/plugins/inputs/bind/README.md index eb22427d20ce9..10e6630e0ba12 100644 --- a/plugins/inputs/bind/README.md +++ b/plugins/inputs/bind/README.md @@ -16,7 +16,7 @@ not enable support for JSON statistics in their BIND packages. ## Configuration -```toml +```toml @sample.conf # Read BIND nameserver XML statistics [[inputs.bind]] ## An array of BIND XML statistics URI to gather stats. diff --git a/plugins/inputs/bind/bind.go b/plugins/inputs/bind/bind.go index d0428356664bd..72b230682f323 100644 --- a/plugins/inputs/bind/bind.go +++ b/plugins/inputs/bind/bind.go @@ -1,6 +1,8 @@ +//go:generate ../../../tools/readme_config_includer/generator package bind import ( + _ "embed" "fmt" "net/http" "net/url" @@ -12,6 +14,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 Bind struct { Urls []string GatherMemoryContexts bool @@ -21,6 +27,10 @@ type Bind struct { client http.Client } +func (*Bind) SampleConfig() string { + return sampleConfig +} + func (b *Bind) Init() error { b.client = http.Client{ Timeout: time.Duration(b.Timeout), diff --git a/plugins/inputs/bind/bind_sample_config.go b/plugins/inputs/bind/bind_sample_config.go deleted file mode 100644 index 278c9d70972dd..0000000000000 --- a/plugins/inputs/bind/bind_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package bind - -func (b *Bind) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/inputs/bond/README.md b/plugins/inputs/bond/README.md index 55ec3b812f0fe..30bc25e9a1860 100644 --- a/plugins/inputs/bond/README.md +++ b/plugins/inputs/bond/README.md @@ -6,7 +6,7 @@ The plugin collects these metrics from `/proc/net/bonding/*` files. ## Configuration -```toml +```toml @sample.conf # Collect bond interface status, slaves statuses and failures count [[inputs.bond]] ## Sets 'proc' directory path diff --git a/plugins/inputs/bond/bond.go b/plugins/inputs/bond/bond.go index ed009904a2a08..f51c62a497d5d 100644 --- a/plugins/inputs/bond/bond.go +++ b/plugins/inputs/bond/bond.go @@ -1,7 +1,9 @@ +//go:generate ../../../tools/readme_config_includer/generator package bond import ( "bufio" + _ "embed" "fmt" "os" "path/filepath" @@ -12,6 +14,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 + // default host proc path const defaultHostProc = "/proc" const defaultHostSys = "/sys" @@ -34,6 +40,10 @@ type sysFiles struct { ADPortsFile string } +func (*Bond) SampleConfig() string { + return sampleConfig +} + func (bond *Bond) Gather(acc telegraf.Accumulator) error { // load proc path, get default value if config value and env variable are empty bond.loadPaths() diff --git a/plugins/inputs/bond/bond_sample_config.go b/plugins/inputs/bond/bond_sample_config.go deleted file mode 100644 index 66d1d23bba173..0000000000000 --- a/plugins/inputs/bond/bond_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package bond - -func (bond *Bond) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/inputs/burrow/README.md b/plugins/inputs/burrow/README.md index 5eef05f8e1065..619596f39c822 100644 --- a/plugins/inputs/burrow/README.md +++ b/plugins/inputs/burrow/README.md @@ -7,7 +7,7 @@ Supported Burrow version: `1.x` ## Configuration -```toml +```toml @sample.conf # Collect Kafka topics and consumers status from Burrow HTTP API. [[inputs.burrow]] ## Burrow API endpoints in format "schema://host:port". diff --git a/plugins/inputs/burrow/burrow.go b/plugins/inputs/burrow/burrow.go index 96c16c663d3ff..da4e931d4ec93 100644 --- a/plugins/inputs/burrow/burrow.go +++ b/plugins/inputs/burrow/burrow.go @@ -1,6 +1,8 @@ +//go:generate ../../../tools/readme_config_includer/generator package burrow import ( + _ "embed" "encoding/json" "fmt" "net" @@ -18,6 +20,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 + const ( defaultBurrowPrefix = "/v3/kafka" defaultConcurrentConnections = 20 @@ -92,6 +98,10 @@ func init() { }) } +func (*burrow) SampleConfig() string { + return sampleConfig +} + func (b *burrow) Gather(acc telegraf.Accumulator) error { var wg sync.WaitGroup diff --git a/plugins/inputs/burrow/burrow_sample_config.go b/plugins/inputs/burrow/burrow_sample_config.go deleted file mode 100644 index 988d4ce9e2b6d..0000000000000 --- a/plugins/inputs/burrow/burrow_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package burrow - -func (b *burrow) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/inputs/cassandra/README.md b/plugins/inputs/cassandra/README.md index 210d7e9983cab..24c66b916d392 100644 --- a/plugins/inputs/cassandra/README.md +++ b/plugins/inputs/cassandra/README.md @@ -20,7 +20,7 @@ Cassandra plugin produces one or more measurements for each metric configured, a ## Configuration -```toml +```toml @sample.conf # Read Cassandra metrics through Jolokia [[inputs.cassandra]] ## DEPRECATED: The cassandra plugin has been deprecated. Please use the diff --git a/plugins/inputs/cassandra/cassandra.go b/plugins/inputs/cassandra/cassandra.go index e73a4425e5e55..460d046d362d5 100644 --- a/plugins/inputs/cassandra/cassandra.go +++ b/plugins/inputs/cassandra/cassandra.go @@ -1,6 +1,8 @@ +//go:generate ../../../tools/readme_config_includer/generator package cassandra import ( + _ "embed" "encoding/json" "errors" "fmt" @@ -13,6 +15,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 JolokiaClient interface { MakeRequest(req *http.Request) (*http.Response, error) } @@ -228,6 +234,10 @@ func parseServerTokens(server string) map[string]string { return serverTokens } +func (*Cassandra) SampleConfig() string { + return sampleConfig +} + func (c *Cassandra) Start(_ telegraf.Accumulator) error { c.Log.Warn("DEPRECATED: The cassandra plugin has been deprecated. " + "Please use the jolokia2 plugin instead. " + diff --git a/plugins/inputs/cassandra/cassandra_sample_config.go b/plugins/inputs/cassandra/cassandra_sample_config.go deleted file mode 100644 index b06286ad46822..0000000000000 --- a/plugins/inputs/cassandra/cassandra_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package cassandra - -func (c *Cassandra) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/inputs/ceph/README.md b/plugins/inputs/ceph/README.md index 3d1745884b171..160e0a9ab1d8b 100644 --- a/plugins/inputs/ceph/README.md +++ b/plugins/inputs/ceph/README.md @@ -43,7 +43,7 @@ the cluster. The currently supported commands are: ## Configuration -```toml +```toml @sample.conf # Collects performance metrics from the MON, OSD, MDS and RGW nodes in a Ceph storage cluster. [[inputs.ceph]] ## This is the recommended interval to poll. Too frequent and you will lose diff --git a/plugins/inputs/ceph/ceph.go b/plugins/inputs/ceph/ceph.go index 99440bdf9ae15..5dbbb57cf6d27 100644 --- a/plugins/inputs/ceph/ceph.go +++ b/plugins/inputs/ceph/ceph.go @@ -1,7 +1,9 @@ +//go:generate ../../../tools/readme_config_includer/generator package ceph import ( "bytes" + _ "embed" "encoding/json" "fmt" "os" @@ -13,6 +15,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 + const ( measurement = "ceph" typeMon = "monitor" @@ -42,6 +48,10 @@ type Ceph struct { Log telegraf.Logger `toml:"-"` } +func (*Ceph) SampleConfig() string { + return sampleConfig +} + func (c *Ceph) Gather(acc telegraf.Accumulator) error { if c.GatherAdminSocketStats { if err := c.gatherAdminSocketStats(acc); err != nil { @@ -110,21 +120,21 @@ func (c *Ceph) gatherClusterStats(acc telegraf.Accumulator) error { } func init() { - c := Ceph{ - CephBinary: "/usr/bin/ceph", - OsdPrefix: osdPrefix, - MonPrefix: monPrefix, - MdsPrefix: mdsPrefix, - RgwPrefix: rgwPrefix, - SocketDir: "/var/run/ceph", - SocketSuffix: sockSuffix, - CephUser: "client.admin", - CephConfig: "/etc/ceph/ceph.conf", - GatherAdminSocketStats: true, - GatherClusterStats: false, - } - - inputs.Add(measurement, func() telegraf.Input { return &c }) + inputs.Add(measurement, func() telegraf.Input { + return &Ceph{ + CephBinary: "/usr/bin/ceph", + OsdPrefix: osdPrefix, + MonPrefix: monPrefix, + MdsPrefix: mdsPrefix, + RgwPrefix: rgwPrefix, + SocketDir: "/var/run/ceph", + SocketSuffix: sockSuffix, + CephUser: "client.admin", + CephConfig: "/etc/ceph/ceph.conf", + GatherAdminSocketStats: true, + GatherClusterStats: false, + } + }) } var perfDump = func(binary string, socket *socket) (string, error) { diff --git a/plugins/inputs/ceph/ceph_sample_config.go b/plugins/inputs/ceph/ceph_sample_config.go deleted file mode 100644 index 61cbd1092a0c3..0000000000000 --- a/plugins/inputs/ceph/ceph_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package ceph - -func (c *Ceph) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/inputs/cgroup/README.md b/plugins/inputs/cgroup/README.md index 377a926193b8e..7b682891f3a52 100644 --- a/plugins/inputs/cgroup/README.md +++ b/plugins/inputs/cgroup/README.md @@ -40,7 +40,7 @@ All measurements have the `path` tag. ## Configuration -```toml +```toml @sample.conf # Read specific statistics per cgroup [[inputs.cgroup]] ## Directories in which to look for files, globs are supported. diff --git a/plugins/inputs/cgroup/cgroup.go b/plugins/inputs/cgroup/cgroup.go index d67315186d200..167f6b1f3e010 100644 --- a/plugins/inputs/cgroup/cgroup.go +++ b/plugins/inputs/cgroup/cgroup.go @@ -1,15 +1,26 @@ +//go:generate ../../../tools/readme_config_includer/generator package cgroup import ( + _ "embed" + "github.com/influxdata/telegraf" "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 CGroup struct { Paths []string `toml:"paths"` Files []string `toml:"files"` } +func (*CGroup) SampleConfig() string { + return sampleConfig +} + func init() { inputs.Add("cgroup", func() telegraf.Input { return &CGroup{} }) } diff --git a/plugins/inputs/cgroup/cgroup_sample_config.go b/plugins/inputs/cgroup/cgroup_sample_config.go deleted file mode 100644 index db6f84f228c9d..0000000000000 --- a/plugins/inputs/cgroup/cgroup_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package cgroup - -func (g *CGroup) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/inputs/chrony/README.md b/plugins/inputs/chrony/README.md index ebb7ba65c6d49..70a0f645c0f88 100644 --- a/plugins/inputs/chrony/README.md +++ b/plugins/inputs/chrony/README.md @@ -53,7 +53,7 @@ Delete second or Not synchronised. ## Configuration -```toml +```toml @sample.conf # Get standard chrony metrics, requires chronyc executable. [[inputs.chrony]] ## If true, chronyc tries to perform a DNS lookup for the time server. diff --git a/plugins/inputs/chrony/chrony.go b/plugins/inputs/chrony/chrony.go index 1fbb4e2881692..80949f963b02e 100644 --- a/plugins/inputs/chrony/chrony.go +++ b/plugins/inputs/chrony/chrony.go @@ -1,6 +1,8 @@ +//go:generate ../../../tools/readme_config_includer/generator package chrony import ( + _ "embed" "errors" "fmt" "os/exec" @@ -13,6 +15,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 + var ( execCommand = exec.Command // execCommand is used to mock commands in tests. ) @@ -22,6 +28,10 @@ type Chrony struct { path string } +func (*Chrony) SampleConfig() string { + return sampleConfig +} + func (c *Chrony) Init() error { var err error c.path, err = exec.LookPath("chronyc") diff --git a/plugins/inputs/chrony/chrony_sample_config.go b/plugins/inputs/chrony/chrony_sample_config.go deleted file mode 100644 index e0fc79ee73dab..0000000000000 --- a/plugins/inputs/chrony/chrony_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package chrony - -func (*Chrony) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/inputs/cisco_telemetry_mdt/README.md b/plugins/inputs/cisco_telemetry_mdt/README.md index 23a5ecf299b5a..66e9d60fe16d2 100644 --- a/plugins/inputs/cisco_telemetry_mdt/README.md +++ b/plugins/inputs/cisco_telemetry_mdt/README.md @@ -11,7 +11,7 @@ The TCP dialout transport is supported on IOS XR (32-bit and 64-bit) 6.1.x and l ## Configuration -```toml +```toml @sample.conf # Cisco model-driven telemetry (MDT) input plugin for IOS XR, IOS XE and NX-OS platforms [[inputs.cisco_telemetry_mdt]] ## Telemetry transport can be "tcp" or "grpc". TLS is only supported when diff --git a/plugins/inputs/cisco_telemetry_mdt/cisco_telemetry_mdt.go b/plugins/inputs/cisco_telemetry_mdt/cisco_telemetry_mdt.go index 547237bd98d4a..5a861a76406c0 100644 --- a/plugins/inputs/cisco_telemetry_mdt/cisco_telemetry_mdt.go +++ b/plugins/inputs/cisco_telemetry_mdt/cisco_telemetry_mdt.go @@ -1,7 +1,9 @@ +//go:generate ../../../tools/readme_config_includer/generator package cisco_telemetry_mdt import ( "bytes" + _ "embed" "encoding/binary" "encoding/json" "fmt" @@ -17,7 +19,7 @@ import ( telemetry "github.com/cisco-ie/nx-telemetry-proto/telemetry_bis" "google.golang.org/grpc" "google.golang.org/grpc/credentials" - _ "google.golang.org/grpc/encoding/gzip" // Register GRPC gzip decoder to support compressed telemetry + _ "google.golang.org/grpc/encoding/gzip" // Required to allow gzip encoding "google.golang.org/grpc/peer" "google.golang.org/protobuf/proto" @@ -27,6 +29,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 + const ( // Maximum telemetry payload size (in bytes) to accept for GRPC dialout transport tcpMaxMsgLen uint32 = 1024 * 1024 @@ -74,6 +80,10 @@ type NxPayloadXfromStructure struct { } `json:"prop"` } +func (*CiscoTelemetryMDT) SampleConfig() string { + return sampleConfig +} + // Start the Cisco MDT service func (c *CiscoTelemetryMDT) Start(acc telegraf.Accumulator) error { var err error diff --git a/plugins/inputs/cisco_telemetry_mdt/cisco_telemetry_mdt_sample_config.go b/plugins/inputs/cisco_telemetry_mdt/cisco_telemetry_mdt_sample_config.go deleted file mode 100644 index fb474a50751c4..0000000000000 --- a/plugins/inputs/cisco_telemetry_mdt/cisco_telemetry_mdt_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package cisco_telemetry_mdt - -func (c *CiscoTelemetryMDT) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/inputs/clickhouse/README.md b/plugins/inputs/clickhouse/README.md index b7bbe85c0de5c..1e85a859e0836 100644 --- a/plugins/inputs/clickhouse/README.md +++ b/plugins/inputs/clickhouse/README.md @@ -4,7 +4,7 @@ This plugin gathers the statistic data from [ClickHouse](https://github.com/Clic ## Configuration -```toml +```toml @sample.conf # Read metrics from one or many ClickHouse servers [[inputs.clickhouse]] ## Username for authorization on ClickHouse server diff --git a/plugins/inputs/clickhouse/clickhouse.go b/plugins/inputs/clickhouse/clickhouse.go index 7973476e9a990..92c2299cac295 100644 --- a/plugins/inputs/clickhouse/clickhouse.go +++ b/plugins/inputs/clickhouse/clickhouse.go @@ -1,7 +1,9 @@ +//go:generate ../../../tools/readme_config_includer/generator package clickhouse import ( "bytes" + _ "embed" "encoding/json" "fmt" "io" @@ -19,6 +21,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 + var defaultTimeout = 5 * time.Second type connect struct { @@ -53,6 +59,10 @@ type ClickHouse struct { tls.ClientConfig } +func (*ClickHouse) SampleConfig() string { + return sampleConfig +} + // Start ClickHouse input service func (ch *ClickHouse) Start(telegraf.Accumulator) error { timeout := defaultTimeout diff --git a/plugins/inputs/clickhouse/clickhouse_sample_config.go b/plugins/inputs/clickhouse/clickhouse_sample_config.go deleted file mode 100644 index d6e2a4cce1259..0000000000000 --- a/plugins/inputs/clickhouse/clickhouse_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package clickhouse - -func (*ClickHouse) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/inputs/cloud_pubsub/README.md b/plugins/inputs/cloud_pubsub/README.md index ea688faef386c..c57cab77bf9e6 100644 --- a/plugins/inputs/cloud_pubsub/README.md +++ b/plugins/inputs/cloud_pubsub/README.md @@ -5,7 +5,7 @@ and creates metrics using one of the supported [input data formats][]. ## Configuration -```toml +```toml @sample.conf # Read metrics from Google PubSub [[inputs.cloud_pubsub]] ## Required. Name of Google Cloud Platform (GCP) Project that owns diff --git a/plugins/inputs/cloud_pubsub/cloud_pubsub.go b/plugins/inputs/cloud_pubsub/cloud_pubsub.go index 1593eaaf0a42f..1f825dd8779d6 100644 --- a/plugins/inputs/cloud_pubsub/cloud_pubsub.go +++ b/plugins/inputs/cloud_pubsub/cloud_pubsub.go @@ -1,23 +1,29 @@ +//go:generate ../../../tools/readme_config_includer/generator package cloud_pubsub import ( "context" + _ "embed" + "encoding/base64" "fmt" "sync" - - "encoding/base64" "time" "cloud.google.com/go/pubsub" + "golang.org/x/oauth2/google" + "google.golang.org/api/option" + "github.com/influxdata/telegraf" "github.com/influxdata/telegraf/config" "github.com/influxdata/telegraf/internal" "github.com/influxdata/telegraf/plugins/inputs" "github.com/influxdata/telegraf/plugins/parsers" - "golang.org/x/oauth2/google" - "google.golang.org/api/option" ) +// DO NOT REMOVE THE NEXT TWO LINES! This is required to embedd the sampleConfig data. +//go:embed sample.conf +var sampleConfig string + type empty struct{} type semaphore chan empty @@ -59,6 +65,10 @@ type PubSub struct { sem semaphore } +func (*PubSub) SampleConfig() string { + return sampleConfig +} + // Gather does nothing for this service input. func (ps *PubSub) Gather(_ telegraf.Accumulator) error { return nil diff --git a/plugins/inputs/cloud_pubsub/cloud_pubsub_sample_config.go b/plugins/inputs/cloud_pubsub/cloud_pubsub_sample_config.go deleted file mode 100644 index c07b8e983ab39..0000000000000 --- a/plugins/inputs/cloud_pubsub/cloud_pubsub_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package cloud_pubsub - -func (ps *PubSub) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/inputs/cloud_pubsub_push/README.md b/plugins/inputs/cloud_pubsub_push/README.md index b67259e37fdde..8f41fa6afae23 100644 --- a/plugins/inputs/cloud_pubsub_push/README.md +++ b/plugins/inputs/cloud_pubsub_push/README.md @@ -13,7 +13,7 @@ Enable mutually authenticated TLS and authorize client connections by signing ce This is a sample configuration for the plugin. -```toml +```toml @sample.conf # Google Cloud Pub/Sub Push HTTP listener [[inputs.cloud_pubsub_push]] ## Address and port to host HTTP listener on diff --git a/plugins/inputs/cloud_pubsub_push/cloud_pubsub_push.go b/plugins/inputs/cloud_pubsub_push/cloud_pubsub_push.go index 65018276d75f8..de4b7fc584dc6 100644 --- a/plugins/inputs/cloud_pubsub_push/cloud_pubsub_push.go +++ b/plugins/inputs/cloud_pubsub_push/cloud_pubsub_push.go @@ -1,8 +1,10 @@ +//go:generate ../../../tools/readme_config_includer/generator package cloud_pubsub_push import ( "context" "crypto/subtle" + _ "embed" "encoding/base64" "encoding/json" "io" @@ -17,6 +19,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 + // defaultMaxBodySize is the default maximum request body size, in bytes. // if the request body is over this size, we will return an HTTP 413 error. // 500 MB @@ -61,6 +67,10 @@ type Payload struct { Subscription string `json:"subscription"` } +func (*PubSubPush) SampleConfig() string { + return sampleConfig +} + func (p *PubSubPush) Gather(_ telegraf.Accumulator) error { return nil } diff --git a/plugins/inputs/cloud_pubsub_push/cloud_pubsub_push_sample_config.go b/plugins/inputs/cloud_pubsub_push/cloud_pubsub_push_sample_config.go deleted file mode 100644 index ecb01a20f23ce..0000000000000 --- a/plugins/inputs/cloud_pubsub_push/cloud_pubsub_push_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package cloud_pubsub_push - -func (p *PubSubPush) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/inputs/cloudwatch/README.md b/plugins/inputs/cloudwatch/README.md index 4a9eb0348e385..de64ec64cd76a 100644 --- a/plugins/inputs/cloudwatch/README.md +++ b/plugins/inputs/cloudwatch/README.md @@ -16,7 +16,7 @@ API endpoint. In the following order the plugin will attempt to authenticate. ## Configuration -```toml +```toml @sample.conf # Pull Metric Statistics from Amazon CloudWatch [[inputs.cloudwatch]] ## Amazon Region diff --git a/plugins/inputs/cloudwatch/cloudwatch.go b/plugins/inputs/cloudwatch/cloudwatch.go index 4a87b1606e718..d02fc845112b0 100644 --- a/plugins/inputs/cloudwatch/cloudwatch.go +++ b/plugins/inputs/cloudwatch/cloudwatch.go @@ -1,7 +1,9 @@ +//go:generate ../../../tools/readme_config_includer/generator package cloudwatch import ( "context" + _ "embed" "fmt" "net" "net/http" @@ -25,6 +27,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 + const ( StatisticAverage = "Average" StatisticMaximum = "Maximum" @@ -90,6 +96,10 @@ type cloudwatchClient interface { GetMetricData(context.Context, *cwClient.GetMetricDataInput, ...func(*cwClient.Options)) (*cwClient.GetMetricDataOutput, error) } +func (*CloudWatch) SampleConfig() string { + return sampleConfig +} + func (c *CloudWatch) Init() error { if len(c.Namespace) != 0 { c.Namespaces = append(c.Namespaces, c.Namespace) diff --git a/plugins/inputs/cloudwatch/cloudwatch_sample_config.go b/plugins/inputs/cloudwatch/cloudwatch_sample_config.go deleted file mode 100644 index 2e9c84c4678cb..0000000000000 --- a/plugins/inputs/cloudwatch/cloudwatch_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package cloudwatch - -func (c *CloudWatch) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/inputs/conntrack/README.md b/plugins/inputs/conntrack/README.md index 4e5bf627cd84b..ea4df03e94192 100644 --- a/plugins/inputs/conntrack/README.md +++ b/plugins/inputs/conntrack/README.md @@ -20,7 +20,7 @@ For more information on conntrack-tools, see the ## Configuration -```toml +```toml @sample.conf # Collects conntrack stats from the configured directories and files. [[inputs.conntrack]] ## The following defaults would work with multiple versions of conntrack. diff --git a/plugins/inputs/conntrack/conntrack.go b/plugins/inputs/conntrack/conntrack.go index abbc0fc55762d..acd5b189f485a 100644 --- a/plugins/inputs/conntrack/conntrack.go +++ b/plugins/inputs/conntrack/conntrack.go @@ -1,20 +1,25 @@ +//go:generate ../../../tools/readme_config_includer/generator //go:build linux // +build linux package conntrack import ( + _ "embed" "fmt" "os" + "path/filepath" "strconv" "strings" - "path/filepath" - "github.com/influxdata/telegraf" "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 Conntrack struct { Path string Dirs []string @@ -47,6 +52,10 @@ func (c *Conntrack) setDefaults() { } } +func (*Conntrack) SampleConfig() string { + return sampleConfig +} + func (c *Conntrack) Gather(acc telegraf.Accumulator) error { c.setDefaults() diff --git a/plugins/inputs/conntrack/conntrack_sample_config.go b/plugins/inputs/conntrack/conntrack_sample_config.go deleted file mode 100644 index f308c11d58037..0000000000000 --- a/plugins/inputs/conntrack/conntrack_sample_config.go +++ /dev/null @@ -1,11 +0,0 @@ -//go:build linux -// +build linux - -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package conntrack - -func (c *Conntrack) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/inputs/consul/README.md b/plugins/inputs/consul/README.md index 609a8dfb8840f..e491c3ae1bd56 100644 --- a/plugins/inputs/consul/README.md +++ b/plugins/inputs/consul/README.md @@ -8,7 +8,7 @@ report those stats already using StatsD protocol if needed. ## Configuration -```toml +```toml @sample.conf # Gather health check statuses from services registered in Consul [[inputs.consul]] ## Consul server address diff --git a/plugins/inputs/consul/consul.go b/plugins/inputs/consul/consul.go index 135526d85a1da..d2bfa58954ff1 100644 --- a/plugins/inputs/consul/consul.go +++ b/plugins/inputs/consul/consul.go @@ -1,15 +1,22 @@ +//go:generate ../../../tools/readme_config_includer/generator package consul import ( + _ "embed" "net/http" "strings" "github.com/hashicorp/consul/api" + "github.com/influxdata/telegraf" "github.com/influxdata/telegraf/plugins/common/tls" "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 Consul struct { Address string Scheme string @@ -27,6 +34,10 @@ type Consul struct { client *api.Client } +func (*Consul) SampleConfig() string { + return sampleConfig +} + func (c *Consul) Init() error { if c.MetricVersion != 2 { c.Log.Warnf("Use of deprecated configuration: 'metric_version = 1'; please update to 'metric_version = 2'") diff --git a/plugins/inputs/consul/consul_sample_config.go b/plugins/inputs/consul/consul_sample_config.go deleted file mode 100644 index 38c4c2210b317..0000000000000 --- a/plugins/inputs/consul/consul_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package consul - -func (c *Consul) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/inputs/consul_agent/README.md b/plugins/inputs/consul_agent/README.md index 58f5ad530d1c3..67838bc120aed 100644 --- a/plugins/inputs/consul_agent/README.md +++ b/plugins/inputs/consul_agent/README.md @@ -6,7 +6,7 @@ This plugin grabs metrics from a Consul agent. Telegraf may be present in every ## Configuration -```toml +```toml @sample.conf # Read metrics from the Consul Agent API [[inputs.consul_agent]] ## URL for the Consul agent diff --git a/plugins/inputs/consul_agent/consul_agent.go b/plugins/inputs/consul_agent/consul_agent.go index 85065d2779fbf..465461b1446c3 100644 --- a/plugins/inputs/consul_agent/consul_agent.go +++ b/plugins/inputs/consul_agent/consul_agent.go @@ -1,6 +1,8 @@ +//go:generate ../../../tools/readme_config_includer/generator package consul_agent import ( + _ "embed" "encoding/json" "errors" "fmt" @@ -15,6 +17,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 + // consul_agent configuration object type ConsulAgent struct { URL string `toml:"url"` @@ -39,6 +45,10 @@ func init() { }) } +func (*ConsulAgent) SampleConfig() string { + return sampleConfig +} + func (n *ConsulAgent) Init() error { if n.URL == "" { n.URL = "http://127.0.0.1:8500" diff --git a/plugins/inputs/consul_agent/consul_agent_sample_config.go b/plugins/inputs/consul_agent/consul_agent_sample_config.go deleted file mode 100644 index 1c4cf1e381877..0000000000000 --- a/plugins/inputs/consul_agent/consul_agent_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package consul_agent - -func (n *ConsulAgent) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/inputs/couchbase/README.md b/plugins/inputs/couchbase/README.md index be39100c7d203..419f02f7c17bd 100644 --- a/plugins/inputs/couchbase/README.md +++ b/plugins/inputs/couchbase/README.md @@ -5,7 +5,7 @@ This plugin gets metrics for each Couchbase node, as well as detailed metrics fo ## Configuration -```toml +```toml @sample.conf # Read per-node and per-bucket metrics from Couchbase [[inputs.couchbase]] ## specify servers via a url matching: diff --git a/plugins/inputs/couchbase/couchbase.go b/plugins/inputs/couchbase/couchbase.go index 46dc2261ba255..4580bfed263c4 100644 --- a/plugins/inputs/couchbase/couchbase.go +++ b/plugins/inputs/couchbase/couchbase.go @@ -1,6 +1,8 @@ +//go:generate ../../../tools/readme_config_includer/generator package couchbase import ( + _ "embed" "encoding/json" "net/http" "regexp" @@ -15,6 +17,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 Couchbase struct { Servers []string @@ -28,6 +34,10 @@ type Couchbase struct { var regexpURI = regexp.MustCompile(`(\S+://)?(\S+\:\S+@)`) +func (*Couchbase) SampleConfig() string { + return sampleConfig +} + // Reads stats from all configured clusters. Accumulates stats. // Returns one of the errors encountered while gathering stats (if any). func (cb *Couchbase) Gather(acc telegraf.Accumulator) error { diff --git a/plugins/inputs/couchbase/couchbase_sample_config.go b/plugins/inputs/couchbase/couchbase_sample_config.go deleted file mode 100644 index 984cffdcc136a..0000000000000 --- a/plugins/inputs/couchbase/couchbase_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package couchbase - -func (cb *Couchbase) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/inputs/couchdb/README.md b/plugins/inputs/couchdb/README.md index 5e1b3c6df76b1..4bb0ae8b78db1 100644 --- a/plugins/inputs/couchdb/README.md +++ b/plugins/inputs/couchdb/README.md @@ -4,7 +4,7 @@ The CouchDB plugin gathers metrics of CouchDB using [_stats] endpoint. ## Configuration -```toml +```toml @sample.conf # Read CouchDB Stats from one or more servers [[inputs.couchdb]] ## Works with CouchDB stats endpoints out of the box diff --git a/plugins/inputs/couchdb/couchdb.go b/plugins/inputs/couchdb/couchdb.go index b2f30a4cf8e95..2296eb90575a8 100644 --- a/plugins/inputs/couchdb/couchdb.go +++ b/plugins/inputs/couchdb/couchdb.go @@ -1,6 +1,8 @@ +//go:generate ../../../tools/readme_config_includer/generator package couchdb import ( + _ "embed" "encoding/json" "fmt" "net/http" @@ -11,6 +13,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 ( metaData struct { Current *float64 `json:"current"` @@ -88,6 +94,10 @@ type ( } ) +func (*CouchDB) SampleConfig() string { + return sampleConfig +} + func (c *CouchDB) Gather(accumulator telegraf.Accumulator) error { var wg sync.WaitGroup for _, u := range c.Hosts { diff --git a/plugins/inputs/couchdb/couchdb_sample_config.go b/plugins/inputs/couchdb/couchdb_sample_config.go deleted file mode 100644 index 64cde4bbed34c..0000000000000 --- a/plugins/inputs/couchdb/couchdb_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package couchdb - -func (*CouchDB) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/inputs/cpu/README.md b/plugins/inputs/cpu/README.md index e21a26149f791..a5c1e64a2ef9e 100644 --- a/plugins/inputs/cpu/README.md +++ b/plugins/inputs/cpu/README.md @@ -4,7 +4,7 @@ The `cpu` plugin gather metrics on the system CPUs. ## Configuration -```toml +```toml @sample.conf # Read metrics about cpu usage [[inputs.cpu]] ## Whether to report per-cpu stats or not diff --git a/plugins/inputs/cpu/cpu.go b/plugins/inputs/cpu/cpu.go index 9a01de5a04bda..1ec06b80cd834 100644 --- a/plugins/inputs/cpu/cpu.go +++ b/plugins/inputs/cpu/cpu.go @@ -1,6 +1,8 @@ +//go:generate ../../../tools/readme_config_includer/generator package cpu import ( + _ "embed" "fmt" "time" @@ -11,6 +13,10 @@ import ( "github.com/influxdata/telegraf/plugins/inputs/system" ) +// DO NOT REMOVE THE NEXT TWO LINES! This is required to embedd the sampleConfig data. +//go:embed sample.conf +var sampleConfig string + type CPUStats struct { ps system.PS lastStats map[string]cpuUtil.TimesStat @@ -35,6 +41,10 @@ func NewCPUStats(ps system.PS) *CPUStats { } } +func (*CPUStats) SampleConfig() string { + return sampleConfig +} + func (c *CPUStats) Gather(acc telegraf.Accumulator) error { times, err := c.ps.CPUTimes(c.PerCPU, c.TotalCPU) if err != nil { diff --git a/plugins/inputs/cpu/cpu_sample_config.go b/plugins/inputs/cpu/cpu_sample_config.go deleted file mode 100644 index e195f9d83c68a..0000000000000 --- a/plugins/inputs/cpu/cpu_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package cpu - -func (c *CPUStats) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/inputs/cpu/sample.conf b/plugins/inputs/cpu/sample.conf index 7b7f603946016..b0254b95de8ca 100644 --- a/plugins/inputs/cpu/sample.conf +++ b/plugins/inputs/cpu/sample.conf @@ -8,3 +8,5 @@ collect_cpu_time = false ## If true, compute and report the sum of all non-idle CPU states report_active = false + ## If true and the info is available then add core_id and physical_id tags + core_tags = false diff --git a/plugins/inputs/csgo/README.md b/plugins/inputs/csgo/README.md index e6fded0fb27ec..17c045c718f2c 100644 --- a/plugins/inputs/csgo/README.md +++ b/plugins/inputs/csgo/README.md @@ -4,7 +4,7 @@ The `csgo` plugin gather metrics from Counter-Strike: Global Offensive servers. ## Configuration -```toml +```toml @sample.conf # Fetch metrics from a CSGO SRCDS [[inputs.csgo]] ## Specify servers using the following format: diff --git a/plugins/inputs/csgo/csgo.go b/plugins/inputs/csgo/csgo.go index 1c344d1c31ec0..3f3ba73a37499 100644 --- a/plugins/inputs/csgo/csgo.go +++ b/plugins/inputs/csgo/csgo.go @@ -1,6 +1,8 @@ +//go:generate ../../../tools/readme_config_includer/generator package csgo import ( + _ "embed" "encoding/json" "errors" "strconv" @@ -14,6 +16,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 statsData struct { CPU float64 `json:"cpu"` NetIn float64 `json:"net_in"` @@ -31,6 +37,10 @@ type CSGO struct { Servers [][]string `toml:"servers"` } +func (*CSGO) SampleConfig() string { + return sampleConfig +} + func (s *CSGO) Gather(acc telegraf.Accumulator) error { var wg sync.WaitGroup diff --git a/plugins/inputs/csgo/csgo_sample_config.go b/plugins/inputs/csgo/csgo_sample_config.go deleted file mode 100644 index 2a1603a1aebda..0000000000000 --- a/plugins/inputs/csgo/csgo_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package csgo - -func (*CSGO) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/inputs/dcos/README.md b/plugins/inputs/dcos/README.md index e3d4d929648a7..920b73c52438c 100644 --- a/plugins/inputs/dcos/README.md +++ b/plugins/inputs/dcos/README.md @@ -20,7 +20,7 @@ your database. ## Configuration -```toml +```toml @sample.conf # Input plugin for DC/OS metrics [[inputs.dcos]] ## The DC/OS cluster URL. diff --git a/plugins/inputs/dcos/dcos.go b/plugins/inputs/dcos/dcos.go index f3a6a6d3f6c64..3822bc99f7bcb 100644 --- a/plugins/inputs/dcos/dcos.go +++ b/plugins/inputs/dcos/dcos.go @@ -1,7 +1,9 @@ +//go:generate ../../../tools/readme_config_includer/generator package dcos import ( "context" + _ "embed" "net/url" "os" "sort" @@ -18,6 +20,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 + const ( defaultMaxConnections = 10 defaultResponseTimeout = 20 * time.Second @@ -69,6 +75,10 @@ type DCOS struct { appFilter filter.Filter } +func (*DCOS) SampleConfig() string { + return sampleConfig +} + func (d *DCOS) Gather(acc telegraf.Accumulator) error { err := d.init() if err != nil { diff --git a/plugins/inputs/dcos/dcos_sample_config.go b/plugins/inputs/dcos/dcos_sample_config.go deleted file mode 100644 index 91e8fd58d9f50..0000000000000 --- a/plugins/inputs/dcos/dcos_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package dcos - -func (d *DCOS) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/inputs/directory_monitor/README.md b/plugins/inputs/directory_monitor/README.md index 44257f4f84f89..bdcb5045f00f6 100644 --- a/plugins/inputs/directory_monitor/README.md +++ b/plugins/inputs/directory_monitor/README.md @@ -7,7 +7,7 @@ This plugin is intended to read files that are moved or copied to the monitored ## Configuration -```toml +```toml @sample.conf # Ingests files in a directory and then moves them to a target directory. [[inputs.directory_monitor]] ## The directory to monitor and read files from. diff --git a/plugins/inputs/directory_monitor/directory_monitor.go b/plugins/inputs/directory_monitor/directory_monitor.go index 45cafbe47f753..e29cacaa1a141 100644 --- a/plugins/inputs/directory_monitor/directory_monitor.go +++ b/plugins/inputs/directory_monitor/directory_monitor.go @@ -1,9 +1,11 @@ +//go:generate ../../../tools/readme_config_includer/generator package directory_monitor import ( "bufio" "compress/gzip" "context" + _ "embed" "errors" "fmt" "io" @@ -24,6 +26,10 @@ import ( "github.com/influxdata/telegraf/selfstat" ) +// DO NOT REMOVE THE NEXT TWO LINES! This is required to embedd the sampleConfig data. +//go:embed sample.conf +var sampleConfig string + var ( defaultFilesToMonitor = []string{} defaultFilesToIgnore = []string{} @@ -59,6 +65,10 @@ type DirectoryMonitor struct { filesToProcess chan string } +func (*DirectoryMonitor) SampleConfig() string { + return sampleConfig +} + func (monitor *DirectoryMonitor) Gather(_ telegraf.Accumulator) error { // Get all files sitting in the directory. files, err := os.ReadDir(monitor.Directory) diff --git a/plugins/inputs/directory_monitor/directory_monitor_sample_config.go b/plugins/inputs/directory_monitor/directory_monitor_sample_config.go deleted file mode 100644 index 1fca93b677394..0000000000000 --- a/plugins/inputs/directory_monitor/directory_monitor_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package directory_monitor - -func (monitor *DirectoryMonitor) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/inputs/disk/README.md b/plugins/inputs/disk/README.md index 46d796456957d..212b903ad329b 100644 --- a/plugins/inputs/disk/README.md +++ b/plugins/inputs/disk/README.md @@ -8,7 +8,7 @@ Note that `used_percent` is calculated by doing `used / (used + free)`, _not_ ## Configuration -```toml +```toml @sample.conf # Read metrics about disk usage by mount point [[inputs.disk]] ## By default stats will be gathered for all mount points. diff --git a/plugins/inputs/disk/disk.go b/plugins/inputs/disk/disk.go index 0f4017a12ccfe..94c94be424b34 100644 --- a/plugins/inputs/disk/disk.go +++ b/plugins/inputs/disk/disk.go @@ -1,6 +1,8 @@ +//go:generate ../../../tools/readme_config_includer/generator package disk import ( + _ "embed" "fmt" "strings" @@ -9,6 +11,10 @@ import ( "github.com/influxdata/telegraf/plugins/inputs/system" ) +// DO NOT REMOVE THE NEXT TWO LINES! This is required to embedd the sampleConfig data. +//go:embed sample.conf +var sampleConfig string + type DiskStats struct { ps system.PS @@ -21,6 +27,10 @@ type DiskStats struct { Log telegraf.Logger `toml:"-"` } +func (*DiskStats) SampleConfig() string { + return sampleConfig +} + func (ds *DiskStats) Init() error { // Legacy support: if len(ds.LegacyMountPoints) != 0 { diff --git a/plugins/inputs/disk/disk_sample_config.go b/plugins/inputs/disk/disk_sample_config.go deleted file mode 100644 index e7be4f9112528..0000000000000 --- a/plugins/inputs/disk/disk_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package disk - -func (ds *DiskStats) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/inputs/diskio/README.md b/plugins/inputs/diskio/README.md index 9fd0173bc2fe2..daadc301255a2 100644 --- a/plugins/inputs/diskio/README.md +++ b/plugins/inputs/diskio/README.md @@ -4,7 +4,7 @@ The diskio input plugin gathers metrics about disk traffic and timing. ## Configuration -```toml +```toml @sample.conf # Read metrics about disk IO by device [[inputs.diskio]] ## By default, telegraf will gather stats for all devices including diff --git a/plugins/inputs/diskio/diskio.go b/plugins/inputs/diskio/diskio.go index ddbea6cf648f1..02fd639de32ce 100644 --- a/plugins/inputs/diskio/diskio.go +++ b/plugins/inputs/diskio/diskio.go @@ -1,6 +1,8 @@ +//go:generate ../../../tools/readme_config_includer/generator package diskio import ( + _ "embed" "fmt" "regexp" "strings" @@ -11,6 +13,10 @@ import ( "github.com/influxdata/telegraf/plugins/inputs/system" ) +// DO NOT REMOVE THE NEXT TWO LINES! This is required to embedd the sampleConfig data. +//go:embed sample.conf +var sampleConfig string + var ( varRegex = regexp.MustCompile(`\$(?:\w+|\{\w+\})`) ) @@ -27,7 +33,6 @@ type DiskIO struct { infoCache map[string]diskInfoCache deviceFilter filter.Filter - initialized bool } // hasMeta reports whether s contains any special glob characters. @@ -35,7 +40,11 @@ func hasMeta(s string) bool { return strings.ContainsAny(s, "*?[") } -func (d *DiskIO) init() error { +func (*DiskIO) SampleConfig() string { + return sampleConfig +} + +func (d *DiskIO) Init() error { for _, device := range d.Devices { if hasMeta(device) { deviceFilter, err := filter.Compile(d.Devices) @@ -45,18 +54,10 @@ func (d *DiskIO) init() error { d.deviceFilter = deviceFilter } } - d.initialized = true return nil } func (d *DiskIO) Gather(acc telegraf.Accumulator) error { - if !d.initialized { - err := d.init() - if err != nil { - return err - } - } - devices := []string{} if d.deviceFilter == nil { devices = d.Devices diff --git a/plugins/inputs/diskio/diskio_sample_config.go b/plugins/inputs/diskio/diskio_sample_config.go deleted file mode 100644 index a840e5eef5ad5..0000000000000 --- a/plugins/inputs/diskio/diskio_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package diskio - -func (d *DiskIO) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/inputs/diskio/diskio_test.go b/plugins/inputs/diskio/diskio_test.go index 383e7e81044ec..c597a41525032 100644 --- a/plugins/inputs/diskio/diskio_test.go +++ b/plugins/inputs/diskio/diskio_test.go @@ -111,6 +111,7 @@ func TestDiskIO(t *testing.T) { ps: &mps, Devices: tt.devices, } + require.NoError(t, diskio.Init()) err := diskio.Gather(&acc) require.Equal(t, tt.err, err) diff --git a/plugins/inputs/disque/README.md b/plugins/inputs/disque/README.md index 351ce67598bcf..96f3a0cad7ec1 100644 --- a/plugins/inputs/disque/README.md +++ b/plugins/inputs/disque/README.md @@ -4,7 +4,7 @@ ## Configuration -```toml +```toml @sample.conf # Read metrics from one or many disque servers [[inputs.disque]] ## An array of URI to gather stats about. Specify an ip or hostname diff --git a/plugins/inputs/disque/disque.go b/plugins/inputs/disque/disque.go index ead29c67dd2b4..b7cc2e120e141 100644 --- a/plugins/inputs/disque/disque.go +++ b/plugins/inputs/disque/disque.go @@ -1,7 +1,9 @@ +//go:generate ../../../tools/readme_config_includer/generator package disque import ( "bufio" + _ "embed" "errors" "fmt" "net" @@ -15,6 +17,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 Disque struct { Servers []string @@ -45,6 +51,10 @@ var Tracking = map[string]string{ var ErrProtocolError = errors.New("disque protocol error") +func (*Disque) SampleConfig() string { + return sampleConfig +} + // Reads stats from all configured servers accumulates stats. // Returns one of the errors encountered while gather stats (if any). func (d *Disque) Gather(acc telegraf.Accumulator) error { diff --git a/plugins/inputs/disque/disque_sample_config.go b/plugins/inputs/disque/disque_sample_config.go deleted file mode 100644 index fc84362b954ff..0000000000000 --- a/plugins/inputs/disque/disque_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package disque - -func (d *Disque) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/inputs/dmcache/README.md b/plugins/inputs/dmcache/README.md index b228b3f02b843..64892b9e96ecc 100644 --- a/plugins/inputs/dmcache/README.md +++ b/plugins/inputs/dmcache/README.md @@ -8,7 +8,7 @@ This plugin requires sudo, that is why you should setup and be sure that the tel ## Configuration -```toml +```toml @sample.conf # Provide a native collection for dmsetup based statistics for dm-cache [[inputs.dmcache]] ## Whether to report per-device stats or not diff --git a/plugins/inputs/dmcache/dmcache.go b/plugins/inputs/dmcache/dmcache.go index 5871fc6f80a6f..ec1181206210d 100644 --- a/plugins/inputs/dmcache/dmcache.go +++ b/plugins/inputs/dmcache/dmcache.go @@ -1,15 +1,26 @@ +//go:generate ../../../tools/readme_config_includer/generator package dmcache import ( + _ "embed" + "github.com/influxdata/telegraf" "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 DMCache struct { PerDevice bool `toml:"per_device"` getCurrentStatus func() ([]string, error) } +func (*DMCache) SampleConfig() string { + return sampleConfig +} + func init() { inputs.Add("dmcache", func() telegraf.Input { return &DMCache{ diff --git a/plugins/inputs/dmcache/dmcache_linux.go b/plugins/inputs/dmcache/dmcache_linux.go index 712e67900ba4d..349cb55a96c43 100644 --- a/plugins/inputs/dmcache/dmcache_linux.go +++ b/plugins/inputs/dmcache/dmcache_linux.go @@ -62,7 +62,7 @@ func (c *DMCache) Gather(acc telegraf.Accumulator) error { func parseDMSetupStatus(line string) (cacheStatus, error) { var err error - parseError := errors.New("Output from dmsetup could not be parsed") + parseError := errors.New("output from dmsetup could not be parsed") status := cacheStatus{} values := strings.Fields(line) if len(values) < 15 { diff --git a/plugins/inputs/dmcache/dmcache_sample_config.go b/plugins/inputs/dmcache/dmcache_sample_config.go deleted file mode 100644 index 4b10517fc6b45..0000000000000 --- a/plugins/inputs/dmcache/dmcache_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package dmcache - -func (c *DMCache) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/inputs/dns_query/README.md b/plugins/inputs/dns_query/README.md index 287addc20d8d9..cc61d7c52cdc0 100644 --- a/plugins/inputs/dns_query/README.md +++ b/plugins/inputs/dns_query/README.md @@ -4,7 +4,7 @@ The DNS plugin gathers dns query times in miliseconds - like [Dig](https://en.wi ## Configuration -```toml +```toml @sample.conf # Query given DNS server and gives statistics [[inputs.dns_query]] ## servers to query diff --git a/plugins/inputs/dns_query/dns_query.go b/plugins/inputs/dns_query/dns_query.go index edf406a2c1401..5f74505b13c35 100644 --- a/plugins/inputs/dns_query/dns_query.go +++ b/plugins/inputs/dns_query/dns_query.go @@ -1,6 +1,8 @@ +//go:generate ../../../tools/readme_config_includer/generator package dns_query import ( + _ "embed" "fmt" "net" "strconv" @@ -13,6 +15,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 ResultType uint64 const ( @@ -41,6 +47,10 @@ type DNSQuery struct { Timeout int } +func (*DNSQuery) SampleConfig() string { + return sampleConfig +} + func (d *DNSQuery) Gather(acc telegraf.Accumulator) error { var wg sync.WaitGroup d.setDefaultValues() diff --git a/plugins/inputs/dns_query/dns_query_sample_config.go b/plugins/inputs/dns_query/dns_query_sample_config.go deleted file mode 100644 index 14e14e3501fa8..0000000000000 --- a/plugins/inputs/dns_query/dns_query_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package dns_query - -func (d *DNSQuery) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/inputs/docker/README.md b/plugins/inputs/docker/README.md index 5a0585b414dca..81173c6e3b5cd 100644 --- a/plugins/inputs/docker/README.md +++ b/plugins/inputs/docker/README.md @@ -8,7 +8,7 @@ to gather stats from the [Engine API](https://docs.docker.com/engine/api/v1.24/) ## Configuration -```toml +```toml @sample.conf # Read metrics about docker containers [[inputs.docker]] ## Docker Endpoint diff --git a/plugins/inputs/docker/docker.go b/plugins/inputs/docker/docker.go index 3f0c73bf1a149..af3ad819b57ae 100644 --- a/plugins/inputs/docker/docker.go +++ b/plugins/inputs/docker/docker.go @@ -1,8 +1,10 @@ +//go:generate ../../../tools/readme_config_includer/generator package docker import ( "context" "crypto/tls" + _ "embed" "encoding/json" "fmt" "io" @@ -25,6 +27,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 + // Docker object type Docker struct { Endpoint string @@ -83,6 +89,10 @@ var ( now = time.Now ) +func (*Docker) SampleConfig() string { + return sampleConfig +} + func (d *Docker) Init() error { err := choice.CheckSlice(d.PerDeviceInclude, containerMetricClasses) if err != nil { diff --git a/plugins/inputs/docker/docker_sample_config.go b/plugins/inputs/docker/docker_sample_config.go deleted file mode 100644 index e25737232df06..0000000000000 --- a/plugins/inputs/docker/docker_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package docker - -func (d *Docker) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/inputs/docker_log/README.md b/plugins/inputs/docker_log/README.md index 0faaf962ed24d..079f5adbe0d7b 100644 --- a/plugins/inputs/docker_log/README.md +++ b/plugins/inputs/docker_log/README.md @@ -14,7 +14,7 @@ The docker plugin uses the [Official Docker Client][] to gather logs from the ## Configuration -```toml +```toml @sample.conf # Read logging output from the Docker engine [[inputs.docker_log]] ## Docker Endpoint diff --git a/plugins/inputs/docker_log/docker_log.go b/plugins/inputs/docker_log/docker_log.go index d340f4de2726b..9be78ff68e633 100644 --- a/plugins/inputs/docker_log/docker_log.go +++ b/plugins/inputs/docker_log/docker_log.go @@ -1,3 +1,4 @@ +//go:generate ../../../tools/readme_config_includer/generator package docker_log import ( @@ -5,6 +6,7 @@ import ( "bytes" "context" "crypto/tls" + _ "embed" "fmt" "io" "strings" @@ -24,6 +26,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 + const ( defaultEndpoint = "unix:///var/run/docker.sock" ) @@ -61,6 +67,10 @@ type DockerLogs struct { containerList map[string]context.CancelFunc } +func (*DockerLogs) SampleConfig() string { + return sampleConfig +} + func (d *DockerLogs) Init() error { var err error if d.Endpoint == "ENV" { diff --git a/plugins/inputs/docker_log/docker_log_sample_config.go b/plugins/inputs/docker_log/docker_log_sample_config.go deleted file mode 100644 index 8194558c51149..0000000000000 --- a/plugins/inputs/docker_log/docker_log_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package docker_log - -func (d *DockerLogs) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/inputs/dovecot/README.md b/plugins/inputs/dovecot/README.md index 573cbd1f79d04..09e0cf7e4625e 100644 --- a/plugins/inputs/dovecot/README.md +++ b/plugins/inputs/dovecot/README.md @@ -8,7 +8,7 @@ the [upgrading steps][upgrading]. ## Configuration -```toml +```toml @sample.conf # Read metrics about dovecot servers [[inputs.dovecot]] ## specify dovecot servers via an address:port list diff --git a/plugins/inputs/dovecot/dovecot.go b/plugins/inputs/dovecot/dovecot.go index 86e6c38051d39..e0d2a6974c206 100644 --- a/plugins/inputs/dovecot/dovecot.go +++ b/plugins/inputs/dovecot/dovecot.go @@ -1,7 +1,9 @@ +//go:generate ../../../tools/readme_config_includer/generator package dovecot import ( "bytes" + _ "embed" "fmt" "io" "net" @@ -14,6 +16,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 Dovecot struct { Type string Filters []string @@ -26,6 +32,10 @@ var validQuery = map[string]bool{ "user": true, "domain": true, "global": true, "ip": true, } +func (*Dovecot) SampleConfig() string { + return sampleConfig +} + // Reads stats from all configured servers. func (d *Dovecot) Gather(acc telegraf.Accumulator) error { if !validQuery[d.Type] { diff --git a/plugins/inputs/dovecot/dovecot_sample_config.go b/plugins/inputs/dovecot/dovecot_sample_config.go deleted file mode 100644 index c396dd9d6d6c0..0000000000000 --- a/plugins/inputs/dovecot/dovecot_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package dovecot - -func (d *Dovecot) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/inputs/dpdk/README.md b/plugins/inputs/dpdk/README.md index 92c920dff39d8..59a0ae9a5d37e 100644 --- a/plugins/inputs/dpdk/README.md +++ b/plugins/inputs/dpdk/README.md @@ -34,7 +34,7 @@ to discover and test the capabilities of DPDK libraries and to explore the expos This plugin offers multiple configuration options, please review examples below for additional usage information. -```toml +```toml @sample.conf # Reads metrics from DPDK applications using v2 telemetry interface. [[inputs.dpdk]] ## Path to DPDK telemetry socket. This shall point to v2 version of DPDK telemetry interface. diff --git a/plugins/inputs/dpdk/dpdk.go b/plugins/inputs/dpdk/dpdk.go index 41aaf46dfdcac..5312a041f9f5d 100644 --- a/plugins/inputs/dpdk/dpdk.go +++ b/plugins/inputs/dpdk/dpdk.go @@ -1,9 +1,11 @@ +//go:generate ../../../tools/readme_config_includer/generator //go:build linux // +build linux package dpdk import ( + _ "embed" "encoding/json" "fmt" "time" @@ -16,6 +18,10 @@ import ( jsonparser "github.com/influxdata/telegraf/plugins/parsers/json" ) +// DO NOT REMOVE THE NEXT TWO LINES! This is required to embedd the sampleConfig data. +//go:embed sample.conf +var sampleConfig string + const ( defaultPathToSocket = "/var/run/dpdk/rte/dpdk_telemetry.v2" defaultAccessTimeout = config.Duration(200 * time.Millisecond) @@ -55,6 +61,10 @@ func init() { }) } +func (*dpdk) SampleConfig() string { + return sampleConfig +} + // Performs validation of all parameters from configuration func (dpdk *dpdk) Init() error { if dpdk.SocketPath == "" { diff --git a/plugins/inputs/dpdk/dpdk_sample_config.go b/plugins/inputs/dpdk/dpdk_sample_config.go deleted file mode 100644 index 63e76a9618af8..0000000000000 --- a/plugins/inputs/dpdk/dpdk_sample_config.go +++ /dev/null @@ -1,11 +0,0 @@ -//go:build linux -// +build linux - -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package dpdk - -func (dpdk *dpdk) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/inputs/ecs/README.md b/plugins/inputs/ecs/README.md index b5152a3ebfab8..66f3d34dd1234 100644 --- a/plugins/inputs/ecs/README.md +++ b/plugins/inputs/ecs/README.md @@ -16,7 +16,7 @@ present in the metadata/stats endpoints. ## Configuration -```toml +```toml @sample.conf # Read metrics about ECS containers [[inputs.ecs]] ## ECS metadata url. diff --git a/plugins/inputs/ecs/ecs.go b/plugins/inputs/ecs/ecs.go index 8ef3a2f882aac..7c2cf3c8c7384 100644 --- a/plugins/inputs/ecs/ecs.go +++ b/plugins/inputs/ecs/ecs.go @@ -1,6 +1,8 @@ +//go:generate ../../../tools/readme_config_includer/generator package ecs import ( + _ "embed" "os" "strings" "time" @@ -11,6 +13,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 + // Ecs config object type Ecs struct { EndpointURL string `toml:"endpoint_url"` @@ -45,6 +51,10 @@ const ( v2Endpoint = "http://169.254.170.2" ) +func (*Ecs) SampleConfig() string { + return sampleConfig +} + // Gather is the entrypoint for telegraf metrics collection func (ecs *Ecs) Gather(acc telegraf.Accumulator) error { err := initSetup(ecs) diff --git a/plugins/inputs/ecs/ecs_sample_config.go b/plugins/inputs/ecs/ecs_sample_config.go deleted file mode 100644 index 7ea2966481bec..0000000000000 --- a/plugins/inputs/ecs/ecs_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package ecs - -func (ecs *Ecs) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/inputs/elasticsearch/README.md b/plugins/inputs/elasticsearch/README.md index c29173301e9f2..12ef60287e5e0 100644 --- a/plugins/inputs/elasticsearch/README.md +++ b/plugins/inputs/elasticsearch/README.md @@ -23,7 +23,7 @@ Note that specific statistics information can change between Elasticsearch versi ## Configuration -```toml +```toml @sample.conf # Read stats from one or more Elasticsearch servers or clusters [[inputs.elasticsearch]] ## specify a list of one or more Elasticsearch servers diff --git a/plugins/inputs/elasticsearch/elasticsearch.go b/plugins/inputs/elasticsearch/elasticsearch.go index dcb37dac77ebb..c796e0819abe3 100644 --- a/plugins/inputs/elasticsearch/elasticsearch.go +++ b/plugins/inputs/elasticsearch/elasticsearch.go @@ -1,6 +1,8 @@ +//go:generate ../../../tools/readme_config_includer/generator package elasticsearch import ( + _ "embed" "encoding/json" "fmt" "io" @@ -19,6 +21,10 @@ import ( jsonparser "github.com/influxdata/telegraf/plugins/parsers/json" ) +// DO NOT REMOVE THE NEXT TWO LINES! This is required to embedd the sampleConfig data. +//go:embed sample.conf +var sampleConfig string + // mask for masking username/password from error messages var mask = regexp.MustCompile(`https?:\/\/\S+:\S+@`) @@ -156,6 +162,10 @@ func mapShardStatusToCode(s string) int { return 0 } +func (*Elasticsearch) SampleConfig() string { + return sampleConfig +} + // Init the plugin. func (e *Elasticsearch) Init() error { // Compile the configured indexes to match for sorting. diff --git a/plugins/inputs/elasticsearch/elasticsearch_sample_config.go b/plugins/inputs/elasticsearch/elasticsearch_sample_config.go deleted file mode 100644 index 06f4a20fd9d8e..0000000000000 --- a/plugins/inputs/elasticsearch/elasticsearch_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package elasticsearch - -func (e *Elasticsearch) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/inputs/elasticsearch_query/README.md b/plugins/inputs/elasticsearch_query/README.md index 67ceff4b55e14..3df9d5fe6421f 100755 --- a/plugins/inputs/elasticsearch_query/README.md +++ b/plugins/inputs/elasticsearch_query/README.md @@ -15,7 +15,7 @@ Currently it is known to break on 7.x or greater versions. ## Configuration -```toml +```toml @sample.conf # Derive metrics from aggregating Elasticsearch query results [[inputs.elasticsearch_query]] ## The full HTTP endpoint URL for your Elasticsearch instance diff --git a/plugins/inputs/elasticsearch_query/elasticsearch_query.go b/plugins/inputs/elasticsearch_query/elasticsearch_query.go index aa73b09bda35f..f682dfc3d7fd6 100644 --- a/plugins/inputs/elasticsearch_query/elasticsearch_query.go +++ b/plugins/inputs/elasticsearch_query/elasticsearch_query.go @@ -1,7 +1,9 @@ +//go:generate ../../../tools/readme_config_includer/generator package elasticsearch_query import ( "context" + _ "embed" "fmt" "net/http" "strconv" @@ -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 + // ElasticsearchQuery struct type ElasticsearchQuery struct { URLs []string `toml:"urls"` @@ -51,6 +57,10 @@ type esAggregation struct { aggregationQueryList []aggregationQueryData } +func (*ElasticsearchQuery) SampleConfig() string { + return sampleConfig +} + // Init the plugin. func (e *ElasticsearchQuery) Init() error { if e.URLs == nil { diff --git a/plugins/inputs/elasticsearch_query/elasticsearch_query_sample_config.go b/plugins/inputs/elasticsearch_query/elasticsearch_query_sample_config.go deleted file mode 100644 index c0c5b135765c9..0000000000000 --- a/plugins/inputs/elasticsearch_query/elasticsearch_query_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package elasticsearch_query - -func (e *ElasticsearchQuery) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/inputs/ethtool/README.md b/plugins/inputs/ethtool/README.md index 9a805f3ca5789..f93d543bc74d7 100644 --- a/plugins/inputs/ethtool/README.md +++ b/plugins/inputs/ethtool/README.md @@ -4,7 +4,7 @@ The ethtool input plugin pulls ethernet device stats. Fields pulled will depend ## Configuration -```toml +```toml @sample.conf # Returns ethtool statistics for given interfaces [[inputs.ethtool]] ## List of interfaces to pull metrics for diff --git a/plugins/inputs/ethtool/ethtool.go b/plugins/inputs/ethtool/ethtool.go index 951b5cee9416c..0503aef4eb0af 100644 --- a/plugins/inputs/ethtool/ethtool.go +++ b/plugins/inputs/ethtool/ethtool.go @@ -1,11 +1,16 @@ package ethtool import ( + _ "embed" "net" "github.com/influxdata/telegraf" ) +// DO NOT REMOVE THE NEXT TWO LINES! This is required to embedd the sampleConfig data. +//go:embed sample.conf +var sampleConfig string + type Command interface { Init() error DriverName(intf string) (string, error) @@ -29,6 +34,10 @@ type Ethtool struct { command Command } +func (*Ethtool) SampleConfig() string { + return sampleConfig +} + const ( pluginName = "ethtool" tagInterface = "interface" diff --git a/plugins/inputs/ethtool/ethtool_linux.go b/plugins/inputs/ethtool/ethtool_linux.go index 16081e4cd831a..78962b7ae7330 100644 --- a/plugins/inputs/ethtool/ethtool_linux.go +++ b/plugins/inputs/ethtool/ethtool_linux.go @@ -1,3 +1,4 @@ +//go:generate ../../../tools/readme_config_includer/generator //go:build linux // +build linux diff --git a/plugins/inputs/ethtool/ethtool_sample_config.go b/plugins/inputs/ethtool/ethtool_sample_config.go deleted file mode 100644 index d3de2fdb94cbd..0000000000000 --- a/plugins/inputs/ethtool/ethtool_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package ethtool - -func (e *Ethtool) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/inputs/eventhub_consumer/README.md b/plugins/inputs/eventhub_consumer/README.md index c6964b9ec34e4..82526ebc432bc 100644 --- a/plugins/inputs/eventhub_consumer/README.md +++ b/plugins/inputs/eventhub_consumer/README.md @@ -12,7 +12,7 @@ The main focus for development of this plugin is Azure IoT hub: ## Configuration -```toml +```toml @sample.conf # Azure Event Hubs service input plugin [[inputs.eventhub_consumer]] ## The default behavior is to create a new Event Hub client from environment variables. diff --git a/plugins/inputs/eventhub_consumer/eventhub_consumer.go b/plugins/inputs/eventhub_consumer/eventhub_consumer.go index fcc76e1afbb9f..d55b65949bc02 100644 --- a/plugins/inputs/eventhub_consumer/eventhub_consumer.go +++ b/plugins/inputs/eventhub_consumer/eventhub_consumer.go @@ -1,7 +1,9 @@ +//go:generate ../../../tools/readme_config_includer/generator package eventhub_consumer import ( "context" + _ "embed" "fmt" "sync" "time" @@ -15,6 +17,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 ) @@ -63,6 +69,10 @@ type EventHub struct { in chan []telegraf.Metric } +func (*EventHub) SampleConfig() string { + return sampleConfig +} + // SetParser sets the parser func (e *EventHub) SetParser(parser parsers.Parser) { e.parser = parser diff --git a/plugins/inputs/eventhub_consumer/eventhub_consumer_sample_config.go b/plugins/inputs/eventhub_consumer/eventhub_consumer_sample_config.go deleted file mode 100644 index bda841e8bc773..0000000000000 --- a/plugins/inputs/eventhub_consumer/eventhub_consumer_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package eventhub_consumer - -func (*EventHub) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/inputs/example/README.md b/plugins/inputs/example/README.md index 69f66d29febad..fc5f0c51b110a 100644 --- a/plugins/inputs/example/README.md +++ b/plugins/inputs/example/README.md @@ -12,7 +12,7 @@ Plugin minimum tested version: x.x This section contains the default TOML to configure the plugin. You can generate it using `telegraf --usage `. -```toml +```toml @sample.conf # This is an example plugin [[inputs.example]] example_option = "example_value" diff --git a/plugins/inputs/example/example.go b/plugins/inputs/example/example.go index 1e61a51d1459c..752521de1d015 100644 --- a/plugins/inputs/example/example.go +++ b/plugins/inputs/example/example.go @@ -1,6 +1,8 @@ +//go:generate ../../../tools/readme_config_includer/generator package example import ( + _ "embed" "fmt" "math/rand" "time" @@ -10,6 +12,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 + // Example struct should be named the same as the Plugin type Example struct { // Example for a mandatory option to set a tag @@ -32,6 +38,10 @@ type Example struct { count int64 } +func (*Example) SampleConfig() string { + return sampleConfig +} + // Init can be implemented to do one-time processing stuff like initializing variables func (m *Example) Init() error { // Check your options according to your requirements diff --git a/plugins/inputs/example/example_sample_config.go b/plugins/inputs/example/example_sample_config.go deleted file mode 100644 index a5ca2518f8fa7..0000000000000 --- a/plugins/inputs/example/example_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package example - -func (m *Example) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/inputs/exec/README.md b/plugins/inputs/exec/README.md index 3d188bbbcf7d6..49b798721796f 100644 --- a/plugins/inputs/exec/README.md +++ b/plugins/inputs/exec/README.md @@ -7,7 +7,7 @@ This plugin can be used to poll for custom metrics from any source. ## Configuration -```toml +```toml @sample.conf # Read metrics from one or more commands that can output to stdout [[inputs.exec]] ## Commands array diff --git a/plugins/inputs/exec/exec.go b/plugins/inputs/exec/exec.go index 3369979eafb55..104e993dca6af 100644 --- a/plugins/inputs/exec/exec.go +++ b/plugins/inputs/exec/exec.go @@ -1,7 +1,9 @@ +//go:generate ../../../tools/readme_config_includer/generator package exec import ( "bytes" + _ "embed" "fmt" "io" "os" @@ -22,6 +24,10 @@ import ( "github.com/influxdata/telegraf/plugins/parsers/nagios" ) +// DO NOT REMOVE THE NEXT TWO LINES! This is required to embedd the sampleConfig data. +//go:embed sample.conf +var sampleConfig string + const MaxStderrBytes int = 512 type Exec struct { @@ -123,6 +129,10 @@ func removeWindowsCarriageReturns(b bytes.Buffer) bytes.Buffer { return b } +func (*Exec) SampleConfig() string { + return sampleConfig +} + func (e *Exec) ProcessCommand(command string, acc telegraf.Accumulator, wg *sync.WaitGroup) { defer wg.Done() _, isNagios := e.parser.(*nagios.NagiosParser) diff --git a/plugins/inputs/exec/exec_sample_config.go b/plugins/inputs/exec/exec_sample_config.go deleted file mode 100644 index 9d0d8bbf79cca..0000000000000 --- a/plugins/inputs/exec/exec_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package exec - -func (e *Exec) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/inputs/execd/README.md b/plugins/inputs/execd/README.md index 31997e9587eb5..6680e95dd6df4 100644 --- a/plugins/inputs/execd/README.md +++ b/plugins/inputs/execd/README.md @@ -15,7 +15,7 @@ STDERR from the process will be relayed to Telegraf as errors in the logs. ## Configuration -```toml +```toml @sample.conf # Run executable as long-running input plugin [[inputs.execd]] ## One program to run as daemon. diff --git a/plugins/inputs/execd/execd.go b/plugins/inputs/execd/execd.go index 08ef50ef7394c..a09c3fd613fca 100644 --- a/plugins/inputs/execd/execd.go +++ b/plugins/inputs/execd/execd.go @@ -1,7 +1,9 @@ +//go:generate ../../../tools/readme_config_includer/generator package execd import ( "bufio" + _ "embed" "errors" "fmt" "io" @@ -17,6 +19,10 @@ import ( "github.com/influxdata/telegraf/plugins/parsers/prometheus" ) +// DO NOT REMOVE THE NEXT TWO LINES! This is required to embedd the sampleConfig data. +//go:embed sample.conf +var sampleConfig string + type Execd struct { Command []string `toml:"command"` Environment []string `toml:"environment"` @@ -29,6 +35,10 @@ type Execd struct { parser parsers.Parser } +func (*Execd) SampleConfig() string { + return sampleConfig +} + func (e *Execd) SetParser(parser parsers.Parser) { e.parser = parser } diff --git a/plugins/inputs/execd/execd_sample_config.go b/plugins/inputs/execd/execd_sample_config.go deleted file mode 100644 index bc59d8ef367c8..0000000000000 --- a/plugins/inputs/execd/execd_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package execd - -func (e *Execd) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/inputs/fail2ban/README.md b/plugins/inputs/fail2ban/README.md index 221f9d5b44c68..322ea07feb6ef 100644 --- a/plugins/inputs/fail2ban/README.md +++ b/plugins/inputs/fail2ban/README.md @@ -11,7 +11,7 @@ Acquiring the required permissions can be done using several methods: ## Configuration -```toml +```toml @sample.conf # Read metrics from fail2ban. [[inputs.fail2ban]] ## Use sudo to run fail2ban-client diff --git a/plugins/inputs/fail2ban/fail2ban.go b/plugins/inputs/fail2ban/fail2ban.go index 7961a473db532..2d8aa1a6356d8 100644 --- a/plugins/inputs/fail2ban/fail2ban.go +++ b/plugins/inputs/fail2ban/fail2ban.go @@ -1,17 +1,22 @@ +//go:generate ../../../tools/readme_config_includer/generator package fail2ban import ( + _ "embed" "errors" "fmt" "os/exec" - "strings" - "strconv" + "strings" "github.com/influxdata/telegraf" "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 + var ( execCommand = exec.Command // execCommand is used to mock commands in tests. ) @@ -35,6 +40,30 @@ var metricsTargets = []struct { }, } +const cmd = "fail2ban-client" + +func (*Fail2ban) SampleConfig() string { + return sampleConfig +} + +func (f *Fail2ban) Init() error { + // Set defaults + if f.path == "" { + path, err := exec.LookPath(cmd) + if err != nil { + return fmt.Errorf("looking up %q failed: %v", cmd, err) + } + f.path = path + } + + // Check parameters + if f.path == "" { + return fmt.Errorf("%q not found", cmd) + } + + return nil +} + func (f *Fail2ban) Gather(acc telegraf.Accumulator) error { if len(f.path) == 0 { return errors.New("fail2ban-client not found: verify that fail2ban is installed and that fail2ban-client is in your PATH") @@ -106,13 +135,7 @@ func extractCount(line string) (string, int) { } func init() { - f := Fail2ban{} - path, _ := exec.LookPath("fail2ban-client") - if len(path) > 0 { - f.path = path - } inputs.Add("fail2ban", func() telegraf.Input { - f := f - return &f + return &Fail2ban{} }) } diff --git a/plugins/inputs/fail2ban/fail2ban_sample_config.go b/plugins/inputs/fail2ban/fail2ban_sample_config.go deleted file mode 100644 index ea8e27d36822a..0000000000000 --- a/plugins/inputs/fail2ban/fail2ban_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package fail2ban - -func (f *Fail2ban) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/inputs/fail2ban/fail2ban_test.go b/plugins/inputs/fail2ban/fail2ban_test.go index 1afac3d789abd..0bf17f574ee02 100644 --- a/plugins/inputs/fail2ban/fail2ban_test.go +++ b/plugins/inputs/fail2ban/fail2ban_test.go @@ -7,6 +7,8 @@ import ( "strings" "testing" + "github.com/stretchr/testify/require" + "github.com/influxdata/telegraf/testutil" ) @@ -50,10 +52,9 @@ func TestGather(t *testing.T) { execCommand = fakeExecCommand defer func() { execCommand = exec.Command }() var acc testutil.Accumulator - err := f.Gather(&acc) - if err != nil { - t.Fatal(err) - } + + require.NoError(t, f.Init()) + require.NoError(t, f.Gather(&acc)) fields1 := map[string]interface{}{ "banned": 2, diff --git a/plugins/inputs/fibaro/README.md b/plugins/inputs/fibaro/README.md index d02af0d5b8f74..24d9fd2e2e947 100644 --- a/plugins/inputs/fibaro/README.md +++ b/plugins/inputs/fibaro/README.md @@ -5,7 +5,7 @@ Those values could be true (1) or false (0) for switches, percentage for dimmers ## Configuration -```toml +```toml @sample.conf # Read devices value(s) from a Fibaro controller [[inputs.fibaro]] ## Required Fibaro controller address/hostname. diff --git a/plugins/inputs/fibaro/fibaro.go b/plugins/inputs/fibaro/fibaro.go index aa35328682855..6bb7d3310fb47 100644 --- a/plugins/inputs/fibaro/fibaro.go +++ b/plugins/inputs/fibaro/fibaro.go @@ -1,6 +1,8 @@ +//go:generate ../../../tools/readme_config_includer/generator package fibaro import ( + _ "embed" "encoding/json" "fmt" "net/http" @@ -12,6 +14,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 + const defaultTimeout = 5 * time.Second // Fibaro contains connection information @@ -98,6 +104,10 @@ func (f *Fibaro) getJSON(path string, dataStruct interface{}) error { return nil } +func (*Fibaro) SampleConfig() string { + return sampleConfig +} + // Gather fetches all required information to output metrics func (f *Fibaro) Gather(acc telegraf.Accumulator) error { if f.client == nil { diff --git a/plugins/inputs/fibaro/fibaro_sample_config.go b/plugins/inputs/fibaro/fibaro_sample_config.go deleted file mode 100644 index fb556a4486bf1..0000000000000 --- a/plugins/inputs/fibaro/fibaro_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package fibaro - -func (f *Fibaro) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/inputs/file/README.md b/plugins/inputs/file/README.md index 439c9f996950a..898374548a55a 100644 --- a/plugins/inputs/file/README.md +++ b/plugins/inputs/file/README.md @@ -8,7 +8,7 @@ plugin instead. ## Configuration -```toml +```toml @sample.conf # Parse a complete file each interval [[inputs.file]] ## Files to parse each interval. Accept standard unix glob matching rules, diff --git a/plugins/inputs/file/file.go b/plugins/inputs/file/file.go index 9f717cf24a36e..8fdc3790c6e00 100644 --- a/plugins/inputs/file/file.go +++ b/plugins/inputs/file/file.go @@ -1,18 +1,25 @@ +//go:generate ../../../tools/readme_config_includer/generator package file import ( + _ "embed" "fmt" "io" "os" "path/filepath" "github.com/dimchansky/utfbom" + "github.com/influxdata/telegraf" "github.com/influxdata/telegraf/internal/globpath" "github.com/influxdata/telegraf/plugins/common/encoding" "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 File struct { Files []string `toml:"files"` FileTag string `toml:"file_tag"` @@ -23,6 +30,10 @@ type File struct { decoder *encoding.Decoder } +func (*File) SampleConfig() string { + return sampleConfig +} + func (f *File) Init() error { var err error f.decoder, err = encoding.NewDecoder(f.CharacterEncoding) diff --git a/plugins/inputs/file/file_sample_config.go b/plugins/inputs/file/file_sample_config.go deleted file mode 100644 index aae05dce6da67..0000000000000 --- a/plugins/inputs/file/file_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package file - -func (f *File) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/inputs/filecount/README.md b/plugins/inputs/filecount/README.md index 1a56dd5be9b2b..0842a4722c355 100644 --- a/plugins/inputs/filecount/README.md +++ b/plugins/inputs/filecount/README.md @@ -4,7 +4,7 @@ Reports the number and total size of files in specified directories. ## Configuration -```toml +```toml @sample.conf # Count files in a directory [[inputs.filecount]] ## Directories to gather stats about. diff --git a/plugins/inputs/filecount/filecount.go b/plugins/inputs/filecount/filecount.go index e796a416364ab..5ab9114f99e26 100644 --- a/plugins/inputs/filecount/filecount.go +++ b/plugins/inputs/filecount/filecount.go @@ -1,18 +1,25 @@ +//go:generate ../../../tools/readme_config_includer/generator package filecount import ( + _ "embed" "os" "path/filepath" "time" + "github.com/karrick/godirwalk" + "github.com/pkg/errors" + "github.com/influxdata/telegraf" "github.com/influxdata/telegraf/config" "github.com/influxdata/telegraf/internal/globpath" "github.com/influxdata/telegraf/plugins/inputs" - "github.com/karrick/godirwalk" - "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 FileCount struct { Directory string `toml:"directory" deprecated:"1.9.0;use 'directories' instead"` Directories []string @@ -201,6 +208,10 @@ func (fc *FileCount) filter(file os.FileInfo) (bool, error) { return true, nil } +func (*FileCount) SampleConfig() string { + return sampleConfig +} + func (fc *FileCount) Gather(acc telegraf.Accumulator) error { if fc.globPaths == nil { fc.initGlobPaths(acc) diff --git a/plugins/inputs/filecount/filecount_sample_config.go b/plugins/inputs/filecount/filecount_sample_config.go deleted file mode 100644 index f8d3bf3a434ab..0000000000000 --- a/plugins/inputs/filecount/filecount_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package filecount - -func (fc *FileCount) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/inputs/filestat/README.md b/plugins/inputs/filestat/README.md index c8670471a9870..772b99201efd6 100644 --- a/plugins/inputs/filestat/README.md +++ b/plugins/inputs/filestat/README.md @@ -4,7 +4,7 @@ The filestat plugin gathers metrics about file existence, size, and other stats. ## Configuration -```toml +```toml @sample.conf # Read stats about given file(s) [[inputs.filestat]] ## Files to gather stats about. diff --git a/plugins/inputs/filestat/filestat.go b/plugins/inputs/filestat/filestat.go index 2811786eea7f8..6b919f7298309 100644 --- a/plugins/inputs/filestat/filestat.go +++ b/plugins/inputs/filestat/filestat.go @@ -1,7 +1,9 @@ +//go:generate ../../../tools/readme_config_includer/generator package filestat import ( "crypto/md5" + _ "embed" "fmt" "io" "os" @@ -11,6 +13,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 FileStat struct { Md5 bool Files []string @@ -34,6 +40,10 @@ func NewFileStat() *FileStat { } } +func (*FileStat) SampleConfig() string { + return sampleConfig +} + func (f *FileStat) Gather(acc telegraf.Accumulator) error { var err error diff --git a/plugins/inputs/filestat/filestat_sample_config.go b/plugins/inputs/filestat/filestat_sample_config.go deleted file mode 100644 index c58f483a63639..0000000000000 --- a/plugins/inputs/filestat/filestat_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package filestat - -func (*FileStat) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/inputs/fireboard/README.md b/plugins/inputs/fireboard/README.md index cb5abe83539a9..2c46a6e6fd1ca 100644 --- a/plugins/inputs/fireboard/README.md +++ b/plugins/inputs/fireboard/README.md @@ -6,7 +6,7 @@ the [Fireboard REST API](https://docs.fireboard.io/reference/restapi.html). ## Configuration -```toml +```toml @sample.conf # Read real time temps from fireboard.io servers [[inputs.fireboard]] ## Specify auth token for your account diff --git a/plugins/inputs/fireboard/fireboard.go b/plugins/inputs/fireboard/fireboard.go index ff197ab7b82b0..bcdb69cf494c7 100644 --- a/plugins/inputs/fireboard/fireboard.go +++ b/plugins/inputs/fireboard/fireboard.go @@ -1,6 +1,8 @@ +//go:generate ../../../tools/readme_config_includer/generator package fireboard import ( + _ "embed" "encoding/json" "fmt" "net/http" @@ -12,6 +14,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 + // Fireboard gathers statistics from the fireboard.io servers type Fireboard struct { AuthToken string `toml:"auth_token"` @@ -45,6 +51,10 @@ type fireboardStats struct { Latesttemps []RTT `json:"latest_temps"` } +func (*Fireboard) SampleConfig() string { + return sampleConfig +} + // Init the things func (r *Fireboard) Init() error { if len(r.AuthToken) == 0 { diff --git a/plugins/inputs/fireboard/fireboard_sample_config.go b/plugins/inputs/fireboard/fireboard_sample_config.go deleted file mode 100644 index b4ed9bdb0a5d2..0000000000000 --- a/plugins/inputs/fireboard/fireboard_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package fireboard - -func (r *Fireboard) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/inputs/fluentd/README.md b/plugins/inputs/fluentd/README.md index 0686af82a8afb..c044dbc1e6ff4 100644 --- a/plugins/inputs/fluentd/README.md +++ b/plugins/inputs/fluentd/README.md @@ -18,7 +18,7 @@ example configuration with `@id` parameter for http plugin: ## Configuration -```toml +```toml @sample.conf # Read metrics exposed by fluentd in_monitor plugin [[inputs.fluentd]] ## This plugin reads information exposed by fluentd (using /api/plugins.json endpoint). diff --git a/plugins/inputs/fluentd/fluentd.go b/plugins/inputs/fluentd/fluentd.go index b90a177593bd5..c980ce84bce16 100644 --- a/plugins/inputs/fluentd/fluentd.go +++ b/plugins/inputs/fluentd/fluentd.go @@ -1,6 +1,8 @@ +//go:generate ../../../tools/readme_config_includer/generator package fluentd import ( + _ "embed" "encoding/json" "fmt" "io" @@ -12,6 +14,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 + const measurement = "fluentd" // Fluentd - plugin main structure @@ -64,6 +70,10 @@ func parse(data []byte) (datapointArray []pluginData, err error) { return datapointArray, err } +func (*Fluentd) SampleConfig() string { + return sampleConfig +} + // Gather - Main code responsible for gathering, processing and creating metrics func (h *Fluentd) Gather(acc telegraf.Accumulator) error { _, err := url.Parse(h.Endpoint) diff --git a/plugins/inputs/fluentd/fluentd_sample_config.go b/plugins/inputs/fluentd/fluentd_sample_config.go deleted file mode 100644 index 286cfc2688328..0000000000000 --- a/plugins/inputs/fluentd/fluentd_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package fluentd - -func (h *Fluentd) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/inputs/github/README.md b/plugins/inputs/github/README.md index 549916ef0474f..d24825c4d848b 100644 --- a/plugins/inputs/github/README.md +++ b/plugins/inputs/github/README.md @@ -7,7 +7,7 @@ alternative method for collecting repository information. ## Configuration -```toml +```toml @sample.conf # Gather repository information from GitHub hosted repositories. [[inputs.github]] ## List of repositories to monitor diff --git a/plugins/inputs/github/github.go b/plugins/inputs/github/github.go index d78df647786a0..6b6e66f087eb2 100644 --- a/plugins/inputs/github/github.go +++ b/plugins/inputs/github/github.go @@ -1,7 +1,9 @@ +//go:generate ../../../tools/readme_config_includer/generator package github import ( "context" + _ "embed" "fmt" "net/http" "strings" @@ -17,6 +19,10 @@ import ( "github.com/influxdata/telegraf/selfstat" ) +// DO NOT REMOVE THE NEXT TWO LINES! This is required to embedd the sampleConfig data. +//go:embed sample.conf +var sampleConfig string + // GitHub - plugin main structure type GitHub struct { Repositories []string `toml:"repositories"` @@ -66,6 +72,10 @@ func (g *GitHub) newGithubClient(httpClient *http.Client) (*githubLib.Client, er return githubLib.NewClient(httpClient), nil } +func (*GitHub) SampleConfig() string { + return sampleConfig +} + // Gather GitHub Metrics func (g *GitHub) Gather(acc telegraf.Accumulator) error { ctx := context.Background() diff --git a/plugins/inputs/github/github_sample_config.go b/plugins/inputs/github/github_sample_config.go deleted file mode 100644 index fc01a79c82de0..0000000000000 --- a/plugins/inputs/github/github_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package github - -func (g *GitHub) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/inputs/gnmi/README.md b/plugins/inputs/gnmi/README.md index 49f2a160c6096..ab7bf2a57512d 100644 --- a/plugins/inputs/gnmi/README.md +++ b/plugins/inputs/gnmi/README.md @@ -8,7 +8,7 @@ It has been optimized to support gNMI telemetry as produced by Cisco IOS XR (64- ## Configuration -```toml +```toml @sample.conf # gNMI telemetry input plugin [[inputs.gnmi]] ## Address and port of the gNMI GRPC server diff --git a/plugins/inputs/gnmi/gnmi.go b/plugins/inputs/gnmi/gnmi.go index f45bf0d8e4c65..d017aabbb1fd3 100644 --- a/plugins/inputs/gnmi/gnmi.go +++ b/plugins/inputs/gnmi/gnmi.go @@ -1,9 +1,11 @@ +//go:generate ../../../tools/readme_config_includer/generator package gnmi import ( "bytes" "context" "crypto/tls" + _ "embed" "encoding/json" "fmt" "io" @@ -28,6 +30,10 @@ import ( jsonparser "github.com/influxdata/telegraf/plugins/parsers/json" ) +// DO NOT REMOVE THE NEXT TWO LINES! This is required to embedd the sampleConfig data. +//go:embed sample.conf +var sampleConfig string + // gNMI plugin instance type GNMI struct { Addresses []string `toml:"addresses"` @@ -82,6 +88,10 @@ type Subscription struct { TagOnly bool `toml:"tag_only"` } +func (*GNMI) SampleConfig() string { + return sampleConfig +} + // Start the http listener service func (c *GNMI) Start(acc telegraf.Accumulator) error { var err error diff --git a/plugins/inputs/gnmi/gnmi_sample_config.go b/plugins/inputs/gnmi/gnmi_sample_config.go deleted file mode 100644 index 4454fedeea18b..0000000000000 --- a/plugins/inputs/gnmi/gnmi_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package gnmi - -func (c *GNMI) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/inputs/graylog/README.md b/plugins/inputs/graylog/README.md index deb822ac51d96..68abbe40c3cdd 100644 --- a/plugins/inputs/graylog/README.md +++ b/plugins/inputs/graylog/README.md @@ -13,7 +13,7 @@ Note: if namespace end point specified metrics array will be ignored for that ca ## Configuration -```toml +```toml @sample.conf # Read flattened metrics from one or more GrayLog HTTP endpoints [[inputs.graylog]] ## API endpoint, currently supported API: diff --git a/plugins/inputs/graylog/graylog.go b/plugins/inputs/graylog/graylog.go index 34614af89b751..1cc8ffad4bb47 100644 --- a/plugins/inputs/graylog/graylog.go +++ b/plugins/inputs/graylog/graylog.go @@ -1,7 +1,9 @@ +//go:generate ../../../tools/readme_config_includer/generator package graylog import ( "bytes" + _ "embed" "encoding/base64" "encoding/json" "fmt" @@ -19,6 +21,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 ResponseMetrics struct { Metrics []Metric `json:"metrics"` } @@ -76,6 +82,10 @@ func (c *RealHTTPClient) HTTPClient() *http.Client { return c.client } +func (*GrayLog) SampleConfig() string { + return sampleConfig +} + // Gathers data for all servers. func (h *GrayLog) Gather(acc telegraf.Accumulator) error { var wg sync.WaitGroup diff --git a/plugins/inputs/graylog/graylog_sample_config.go b/plugins/inputs/graylog/graylog_sample_config.go deleted file mode 100644 index 8191695e188dc..0000000000000 --- a/plugins/inputs/graylog/graylog_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package graylog - -func (h *GrayLog) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/inputs/haproxy/README.md b/plugins/inputs/haproxy/README.md index 4ce0070d91820..496d97dbb3955 100644 --- a/plugins/inputs/haproxy/README.md +++ b/plugins/inputs/haproxy/README.md @@ -7,7 +7,7 @@ or [HTTP statistics page](https://cbonte.github.io/haproxy-dconv/1.9/management. ## Configuration -```toml +```toml @sample.conf # Read metrics of HAProxy, via socket or HTTP stats page [[inputs.haproxy]] ## An array of address to gather stats about. Specify an ip on hostname diff --git a/plugins/inputs/haproxy/haproxy.go b/plugins/inputs/haproxy/haproxy.go index 045dc7c7951f9..72d1d61b281a1 100644 --- a/plugins/inputs/haproxy/haproxy.go +++ b/plugins/inputs/haproxy/haproxy.go @@ -1,6 +1,8 @@ +//go:generate ../../../tools/readme_config_includer/generator package haproxy import ( + _ "embed" "encoding/csv" "fmt" "io" @@ -18,6 +20,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 + //CSV format: https://cbonte.github.io/haproxy-dconv/1.5/configuration.html#9.1 type haproxy struct { @@ -30,6 +36,10 @@ type haproxy struct { client *http.Client } +func (*haproxy) SampleConfig() string { + return sampleConfig +} + // Reads stats from all configured servers accumulates stats. // Returns one of the errors encountered while gather stats (if any). func (h *haproxy) Gather(acc telegraf.Accumulator) error { diff --git a/plugins/inputs/haproxy/haproxy_sample_config.go b/plugins/inputs/haproxy/haproxy_sample_config.go deleted file mode 100644 index 7381c3ab1f7f6..0000000000000 --- a/plugins/inputs/haproxy/haproxy_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package haproxy - -func (h *haproxy) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/inputs/hddtemp/README.md b/plugins/inputs/hddtemp/README.md index 0f752398678f5..0a9631db42a03 100644 --- a/plugins/inputs/hddtemp/README.md +++ b/plugins/inputs/hddtemp/README.md @@ -6,7 +6,7 @@ Hddtemp should be installed and its daemon running. ## Configuration -```toml +```toml @sample.conf # Monitor disks' temperatures using hddtemp [[inputs.hddtemp]] ## By default, telegraf gathers temps data from all disks detected by the diff --git a/plugins/inputs/hddtemp/hddtemp.go b/plugins/inputs/hddtemp/hddtemp.go index 82d06f0b4534a..154d2e4a0eb26 100644 --- a/plugins/inputs/hddtemp/hddtemp.go +++ b/plugins/inputs/hddtemp/hddtemp.go @@ -1,6 +1,8 @@ +//go:generate ../../../tools/readme_config_includer/generator package hddtemp import ( + _ "embed" "net" "github.com/influxdata/telegraf" @@ -8,6 +10,10 @@ import ( gohddtemp "github.com/influxdata/telegraf/plugins/inputs/hddtemp/go-hddtemp" ) +// DO NOT REMOVE THE NEXT TWO LINES! This is required to embedd the sampleConfig data. +//go:embed sample.conf +var sampleConfig string + const defaultAddress = "127.0.0.1:7634" type HDDTemp struct { @@ -32,6 +38,10 @@ var hddtempSampleConfig = ` # devices = ["sda", "*"] ` +func (*HDDTemp) SampleConfig() string { + return sampleConfig +} + func (h *HDDTemp) Gather(acc telegraf.Accumulator) error { if h.fetcher == nil { h.fetcher = gohddtemp.New() diff --git a/plugins/inputs/hddtemp/hddtemp_sample_config.go b/plugins/inputs/hddtemp/hddtemp_sample_config.go deleted file mode 100644 index c1fb51286f488..0000000000000 --- a/plugins/inputs/hddtemp/hddtemp_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package hddtemp - -func (h *HDDTemp) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/inputs/http/README.md b/plugins/inputs/http/README.md index 4ec3bd26e1c62..4fd50bdb90481 100644 --- a/plugins/inputs/http/README.md +++ b/plugins/inputs/http/README.md @@ -4,7 +4,7 @@ The HTTP input plugin collects metrics from one or more HTTP(S) endpoints. The ## Configuration -```toml +```toml @sample.conf # Read formatted metrics from one or more HTTP endpoints [[inputs.http]] ## One or more URLs from which to read formatted metrics diff --git a/plugins/inputs/http/http.go b/plugins/inputs/http/http.go index 247a95e4ea07d..bbba049f2094d 100644 --- a/plugins/inputs/http/http.go +++ b/plugins/inputs/http/http.go @@ -1,8 +1,10 @@ +//go:generate ../../../tools/readme_config_includer/generator package http import ( "bytes" "context" + _ "embed" "fmt" "io" "io/ioutil" @@ -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 HTTP struct { URLs []string `toml:"urls"` Method string `toml:"method"` @@ -42,6 +48,10 @@ type HTTP struct { parserFunc telegraf.ParserFunc } +func (*HTTP) SampleConfig() string { + return sampleConfig +} + func (h *HTTP) Init() error { ctx := context.Background() client, err := h.HTTPClientConfig.CreateClient(ctx, h.Log) diff --git a/plugins/inputs/http/http_sample_config.go b/plugins/inputs/http/http_sample_config.go deleted file mode 100644 index 4edad16267ff8..0000000000000 --- a/plugins/inputs/http/http_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package http - -func (*HTTP) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/inputs/http_listener_v2/README.md b/plugins/inputs/http_listener_v2/README.md index e0b68ffef88e2..bdcfd1fa43abd 100644 --- a/plugins/inputs/http_listener_v2/README.md +++ b/plugins/inputs/http_listener_v2/README.md @@ -13,7 +13,7 @@ InfluxDB it is recommended to use [`influxdb_listener`][influxdb_listener] or [` This is a sample configuration for the plugin. -```toml +```toml @sample.conf # Generic HTTP write listener [[inputs.http_listener_v2]] ## Address and port to host HTTP listener on diff --git a/plugins/inputs/http_listener_v2/http_listener_v2.go b/plugins/inputs/http_listener_v2/http_listener_v2.go index 8ce14c7b0a6ad..fa452b160cfb8 100644 --- a/plugins/inputs/http_listener_v2/http_listener_v2.go +++ b/plugins/inputs/http_listener_v2/http_listener_v2.go @@ -1,9 +1,11 @@ +//go:generate ../../../tools/readme_config_includer/generator package http_listener_v2 import ( "compress/gzip" "crypto/subtle" "crypto/tls" + _ "embed" "errors" "io" "net" @@ -14,6 +16,7 @@ import ( "time" "github.com/golang/snappy" + "github.com/influxdata/telegraf" "github.com/influxdata/telegraf/config" "github.com/influxdata/telegraf/internal/choice" @@ -22,6 +25,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 + // defaultMaxBodySize is the default maximum request body size, in bytes. // if the request body is over this size, we will return an HTTP 413 error. // 500 MB @@ -67,6 +74,10 @@ type HTTPListenerV2 struct { acc telegraf.Accumulator } +func (*HTTPListenerV2) SampleConfig() string { + return sampleConfig +} + func (h *HTTPListenerV2) Gather(_ telegraf.Accumulator) error { return nil } diff --git a/plugins/inputs/http_listener_v2/http_listener_v2_sample_config.go b/plugins/inputs/http_listener_v2/http_listener_v2_sample_config.go deleted file mode 100644 index 3b2d52077c41e..0000000000000 --- a/plugins/inputs/http_listener_v2/http_listener_v2_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package http_listener_v2 - -func (h *HTTPListenerV2) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/inputs/http_response/README.md b/plugins/inputs/http_response/README.md index fded2cd915e4d..eab8a7101cff5 100644 --- a/plugins/inputs/http_response/README.md +++ b/plugins/inputs/http_response/README.md @@ -4,7 +4,7 @@ This input plugin checks HTTP/HTTPS connections. ## Configuration -```toml +```toml @sample.conf # HTTP/HTTPS request given an address a method and a timeout [[inputs.http_response]] ## List of urls to query. diff --git a/plugins/inputs/http_response/http_response.go b/plugins/inputs/http_response/http_response.go index 1520a82e3fcb3..41f788a84ba38 100644 --- a/plugins/inputs/http_response/http_response.go +++ b/plugins/inputs/http_response/http_response.go @@ -1,6 +1,8 @@ +//go:generate ../../../tools/readme_config_includer/generator package http_response import ( + _ "embed" "errors" "fmt" "io" @@ -20,6 +22,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 + const ( // defaultResponseBodyMaxSize is the default maximum response body size, in bytes. // if the response body is over this size, we will raise a body_read_error. @@ -318,6 +324,10 @@ func (h *HTTPResponse) setBodyReadError(errorMsg string, bodyBytes []byte, field } } +func (*HTTPResponse) SampleConfig() string { + return sampleConfig +} + // Gather gets all metric fields and tags and returns any errors it encounters func (h *HTTPResponse) Gather(acc telegraf.Accumulator) error { // Compile the body regex if it exist diff --git a/plugins/inputs/http_response/http_response_sample_config.go b/plugins/inputs/http_response/http_response_sample_config.go deleted file mode 100644 index 9d679aa76e1dc..0000000000000 --- a/plugins/inputs/http_response/http_response_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package http_response - -func (h *HTTPResponse) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/inputs/httpjson/README.md b/plugins/inputs/httpjson/README.md index be6492a4e0b02..57d48da15b01a 100644 --- a/plugins/inputs/httpjson/README.md +++ b/plugins/inputs/httpjson/README.md @@ -6,7 +6,7 @@ The httpjson plugin collects data from HTTP URLs which respond with JSON. It fl ## Configuration -```toml +```toml @sample.conf # Read flattened metrics from one or more JSON HTTP endpoints [[inputs.httpjson]] ## NOTE This plugin only reads numerical measurements, strings and booleans diff --git a/plugins/inputs/httpjson/httpjson.go b/plugins/inputs/httpjson/httpjson.go index 233f3e1a98302..4e5cc64606d9d 100644 --- a/plugins/inputs/httpjson/httpjson.go +++ b/plugins/inputs/httpjson/httpjson.go @@ -1,7 +1,9 @@ +//go:generate ../../../tools/readme_config_includer/generator package httpjson import ( "bytes" + _ "embed" "fmt" "io" "net/http" @@ -17,6 +19,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 + var ( utf8BOM = []byte("\xef\xbb\xbf") ) @@ -66,6 +72,10 @@ func (c *RealHTTPClient) HTTPClient() *http.Client { return c.client } +func (*HTTPJSON) SampleConfig() string { + return sampleConfig +} + // Gathers data for all servers. func (h *HTTPJSON) Gather(acc telegraf.Accumulator) error { var wg sync.WaitGroup diff --git a/plugins/inputs/httpjson/httpjson_sample_config.go b/plugins/inputs/httpjson/httpjson_sample_config.go deleted file mode 100644 index f8a2281b7ce0c..0000000000000 --- a/plugins/inputs/httpjson/httpjson_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package httpjson - -func (h *HTTPJSON) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/inputs/hugepages/README.md b/plugins/inputs/hugepages/README.md index c08360f76a41e..93535f9fb0c3e 100644 --- a/plugins/inputs/hugepages/README.md +++ b/plugins/inputs/hugepages/README.md @@ -8,7 +8,7 @@ Consult ## Configuration -```toml +```toml @sample.conf # Gathers huge pages measurements. [[inputs.hugepages]] ## Supported huge page types: diff --git a/plugins/inputs/hugepages/hugepages.go b/plugins/inputs/hugepages/hugepages.go index 5280932c69efc..bb25870e76529 100644 --- a/plugins/inputs/hugepages/hugepages.go +++ b/plugins/inputs/hugepages/hugepages.go @@ -1,3 +1,4 @@ +//go:generate ../../../tools/readme_config_includer/generator //go:build linux // +build linux @@ -5,6 +6,7 @@ package hugepages import ( "bytes" + _ "embed" "fmt" "io/ioutil" "path/filepath" @@ -15,6 +17,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 + const ( // path to root huge page control directory rootHugepagePath = "/sys/kernel/mm/hugepages" @@ -72,6 +78,10 @@ type Hugepages struct { meminfoPath string } +func (*Hugepages) SampleConfig() string { + return sampleConfig +} + func (h *Hugepages) Init() error { err := h.parseHugepagesConfig() if err != nil { diff --git a/plugins/inputs/hugepages/hugepages_sample_config.go b/plugins/inputs/hugepages/hugepages_sample_config.go deleted file mode 100644 index d2929fa435085..0000000000000 --- a/plugins/inputs/hugepages/hugepages_sample_config.go +++ /dev/null @@ -1,11 +0,0 @@ -//go:build linux -// +build linux - -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package hugepages - -func (h *Hugepages) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/inputs/icinga2/README.md b/plugins/inputs/icinga2/README.md index da6824e7fccfc..336bdf0cb9a86 100644 --- a/plugins/inputs/icinga2/README.md +++ b/plugins/inputs/icinga2/README.md @@ -8,7 +8,7 @@ services and hosts. You can read Icinga2's documentation for their remote API ## Configuration -```toml +```toml @sample.conf # Gather Icinga2 status [[inputs.icinga2]] ## Required Icinga2 server address diff --git a/plugins/inputs/icinga2/icinga2.go b/plugins/inputs/icinga2/icinga2.go index 5cfb64ed13ee1..8314e9cdb4afb 100644 --- a/plugins/inputs/icinga2/icinga2.go +++ b/plugins/inputs/icinga2/icinga2.go @@ -1,6 +1,8 @@ +//go:generate ../../../tools/readme_config_includer/generator package icinga2 import ( + _ "embed" "encoding/json" "fmt" "net/http" @@ -13,6 +15,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 Icinga2 struct { Server string ObjectType string @@ -50,6 +56,10 @@ var levels = []string{"ok", "warning", "critical", "unknown"} type ObjectType string +func (*Icinga2) SampleConfig() string { + return sampleConfig +} + func (i *Icinga2) GatherStatus(acc telegraf.Accumulator, checks []Object) { for _, check := range checks { serverURL, err := url.Parse(i.Server) diff --git a/plugins/inputs/icinga2/icinga2_sample_config.go b/plugins/inputs/icinga2/icinga2_sample_config.go deleted file mode 100644 index 214f537a6bcc7..0000000000000 --- a/plugins/inputs/icinga2/icinga2_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package icinga2 - -func (i *Icinga2) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/inputs/infiniband/README.md b/plugins/inputs/infiniband/README.md index 441e427f3d86b..fb630ae3a42ef 100644 --- a/plugins/inputs/infiniband/README.md +++ b/plugins/inputs/infiniband/README.md @@ -8,7 +8,7 @@ system. These are the counters that can be found in ## Configuration -```toml +```toml @sample.conf # Gets counters from all InfiniBand cards and ports installed [[inputs.infiniband]] # no configuration diff --git a/plugins/inputs/infiniband/infiniband.go b/plugins/inputs/infiniband/infiniband.go index dbb6d639b2e37..bf5b72cb5543e 100644 --- a/plugins/inputs/infiniband/infiniband.go +++ b/plugins/inputs/infiniband/infiniband.go @@ -1,11 +1,28 @@ +//go:generate ../../../tools/readme_config_includer/generator package infiniband import ( + _ "embed" + "github.com/influxdata/telegraf" + "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 + // Stores the configuration values for the infiniband plugin - as there are no // config values, this is intentionally empty type Infiniband struct { Log telegraf.Logger `toml:"-"` } + +func (*Infiniband) SampleConfig() string { + return sampleConfig +} + +// Initialise plugin +func init() { + inputs.Add("infiniband", func() telegraf.Input { return &Infiniband{} }) +} diff --git a/plugins/inputs/infiniband/infiniband_linux.go b/plugins/inputs/infiniband/infiniband_linux.go index 2868c683e7ebb..9ccb7dc2fc110 100644 --- a/plugins/inputs/infiniband/infiniband_linux.go +++ b/plugins/inputs/infiniband/infiniband_linux.go @@ -5,10 +5,10 @@ package infiniband import ( "fmt" + "strconv" + "github.com/Mellanox/rdmamap" "github.com/influxdata/telegraf" - "github.com/influxdata/telegraf/plugins/inputs" - "strconv" ) // Gather statistics from our infiniband cards @@ -51,8 +51,3 @@ func addStats(dev string, port string, stats []rdmamap.RdmaStatEntry, acc telegr acc.AddFields("infiniband", fields, tags) } - -// Initialise plugin -func init() { - inputs.Add("infiniband", func() telegraf.Input { return &Infiniband{} }) -} diff --git a/plugins/inputs/infiniband/infiniband_sample_config.go b/plugins/inputs/infiniband/infiniband_sample_config.go deleted file mode 100644 index e2dc0ef998517..0000000000000 --- a/plugins/inputs/infiniband/infiniband_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package infiniband - -func (i *Infiniband) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/inputs/influxdb/README.md b/plugins/inputs/influxdb/README.md index e13e6c4c6bd72..76c29dd91fb91 100644 --- a/plugins/inputs/influxdb/README.md +++ b/plugins/inputs/influxdb/README.md @@ -9,7 +9,7 @@ InfluxDB-formatted endpoints. See below for more information. ## Configuration -```toml +```toml @sample.conf # Read InfluxDB-formatted JSON metrics from one or more HTTP endpoints [[inputs.influxdb]] ## Works with InfluxDB debug endpoints out of the box, diff --git a/plugins/inputs/influxdb/influxdb.go b/plugins/inputs/influxdb/influxdb.go index 3e07437fad364..0aa293f940edb 100644 --- a/plugins/inputs/influxdb/influxdb.go +++ b/plugins/inputs/influxdb/influxdb.go @@ -1,7 +1,9 @@ +//go:generate ../../../tools/readme_config_includer/generator package influxdb import ( "bytes" + _ "embed" "encoding/json" "errors" "io" @@ -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 + const ( maxErrorResponseBodyLength = 1024 ) @@ -43,6 +49,10 @@ type InfluxDB struct { client *http.Client } +func (*InfluxDB) SampleConfig() string { + return sampleConfig +} + func (i *InfluxDB) Gather(acc telegraf.Accumulator) error { if len(i.URLs) == 0 { i.URLs = []string{"http://localhost:8086/debug/vars"} diff --git a/plugins/inputs/influxdb/influxdb_sample_config.go b/plugins/inputs/influxdb/influxdb_sample_config.go deleted file mode 100644 index e35777fdbc30d..0000000000000 --- a/plugins/inputs/influxdb/influxdb_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package influxdb - -func (*InfluxDB) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/inputs/influxdb_listener/README.md b/plugins/inputs/influxdb_listener/README.md index 9f3b167351696..755b7de5c0d63 100644 --- a/plugins/inputs/influxdb_listener/README.md +++ b/plugins/inputs/influxdb_listener/README.md @@ -20,7 +20,7 @@ submits data to InfluxDB determines the destination database. ## Configuration -```toml +```toml @sample.conf # Accept metrics over InfluxDB 1.x HTTP API [[inputs.influxdb_listener]] ## Address and port to host HTTP listener on diff --git a/plugins/inputs/influxdb_listener/influxdb_listener.go b/plugins/inputs/influxdb_listener/influxdb_listener.go index b6964ac7c8230..a4b8372c59c1d 100644 --- a/plugins/inputs/influxdb_listener/influxdb_listener.go +++ b/plugins/inputs/influxdb_listener/influxdb_listener.go @@ -1,9 +1,11 @@ +//go:generate ../../../tools/readme_config_includer/generator package influxdb_listener import ( "compress/gzip" "context" "crypto/tls" + _ "embed" "encoding/json" "fmt" "net" @@ -20,6 +22,10 @@ import ( "github.com/influxdata/telegraf/selfstat" ) +// DO NOT REMOVE THE NEXT TWO LINES! This is required to embedd the sampleConfig data. +//go:embed sample.conf +var sampleConfig string + const ( // defaultMaxBodySize is the default maximum request body size, in bytes. // if the request body is over this size, we will return an HTTP 413 error. @@ -63,6 +69,10 @@ type InfluxDBListener struct { mux http.ServeMux } +func (*InfluxDBListener) SampleConfig() string { + return sampleConfig +} + func (h *InfluxDBListener) Gather(_ telegraf.Accumulator) error { return nil } diff --git a/plugins/inputs/influxdb_listener/influxdb_listener_sample_config.go b/plugins/inputs/influxdb_listener/influxdb_listener_sample_config.go deleted file mode 100644 index 53000d4d260e2..0000000000000 --- a/plugins/inputs/influxdb_listener/influxdb_listener_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package influxdb_listener - -func (h *InfluxDBListener) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/inputs/influxdb_v2_listener/README.md b/plugins/inputs/influxdb_v2_listener/README.md index 116a7a937bba8..2cf48d529dc4d 100644 --- a/plugins/inputs/influxdb_v2_listener/README.md +++ b/plugins/inputs/influxdb_v2_listener/README.md @@ -13,7 +13,7 @@ Telegraf minimum version: Telegraf 1.16.0 ## Configuration -```toml +```toml @sample.conf # Accept metrics over InfluxDB 2.x HTTP API [[inputs.influxdb_v2_listener]] ## Address and port to host InfluxDB listener on diff --git a/plugins/inputs/influxdb_v2_listener/influxdb_v2_listener.go b/plugins/inputs/influxdb_v2_listener/influxdb_v2_listener.go index a393e5e6404a6..3612283c5493f 100644 --- a/plugins/inputs/influxdb_v2_listener/influxdb_v2_listener.go +++ b/plugins/inputs/influxdb_v2_listener/influxdb_v2_listener.go @@ -1,9 +1,11 @@ +//go:generate ../../../tools/readme_config_includer/generator package influxdb_v2_listener import ( "compress/gzip" "context" "crypto/tls" + _ "embed" "encoding/json" "errors" "fmt" @@ -22,6 +24,10 @@ import ( "github.com/influxdata/telegraf/selfstat" ) +// DO NOT REMOVE THE NEXT TWO LINES! This is required to embedd the sampleConfig data. +//go:embed sample.conf +var sampleConfig string + const ( // defaultMaxBodySize is the default maximum request body size, in bytes. // if the request body is over this size, we will return an HTTP 413 error. @@ -71,6 +77,10 @@ type InfluxDBV2Listener struct { mux http.ServeMux } +func (*InfluxDBV2Listener) SampleConfig() string { + return sampleConfig +} + func (h *InfluxDBV2Listener) Gather(_ telegraf.Accumulator) error { return nil } diff --git a/plugins/inputs/influxdb_v2_listener/influxdb_v2_listener_sample_config.go b/plugins/inputs/influxdb_v2_listener/influxdb_v2_listener_sample_config.go deleted file mode 100644 index 66b7c180887ed..0000000000000 --- a/plugins/inputs/influxdb_v2_listener/influxdb_v2_listener_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package influxdb_v2_listener - -func (h *InfluxDBV2Listener) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/inputs/intel_pmu/README.md b/plugins/inputs/intel_pmu/README.md index 92a07d14e68f6..9d520f0f305d4 100644 --- a/plugins/inputs/intel_pmu/README.md +++ b/plugins/inputs/intel_pmu/README.md @@ -11,7 +11,7 @@ They form a basis for profiling applications to trace dynamic control flow and i ## Configuration -```toml +```toml @sample.conf # Intel Performance Monitoring Unit plugin exposes Intel PMU metrics available through Linux Perf subsystem [[inputs.intel_pmu]] ## List of filesystem locations of JSON files that contain PMU event definitions. diff --git a/plugins/inputs/intel_pmu/intel_pmu.go b/plugins/inputs/intel_pmu/intel_pmu.go index 63072c9926f40..bd179aab34bd4 100644 --- a/plugins/inputs/intel_pmu/intel_pmu.go +++ b/plugins/inputs/intel_pmu/intel_pmu.go @@ -1,9 +1,11 @@ +//go:generate ../../../tools/readme_config_includer/generator //go:build linux && amd64 // +build linux,amd64 package intel_pmu import ( + _ "embed" "fmt" "io/ioutil" "math" @@ -13,11 +15,16 @@ import ( "strings" "syscall" + ia "github.com/intel/iaevents" + "github.com/influxdata/telegraf" "github.com/influxdata/telegraf/plugins/inputs" - ia "github.com/intel/iaevents" ) +// DO NOT REMOVE THE NEXT TWO LINES! This is required to embedd the sampleConfig data. +//go:embed sample.conf +var sampleConfig string + // Linux availability: https://www.kernel.org/doc/Documentation/sysctl/fs.txt const fileMaxPath = "/proc/sys/fs/file-max" @@ -117,6 +124,10 @@ func (IntelPMU) Start(_ telegraf.Accumulator) error { return nil } +func (*IntelPMU) SampleConfig() string { + return sampleConfig +} + func (i *IntelPMU) Init() error { err := checkFiles(i.EventListPaths, i.fileInfo) if err != nil { diff --git a/plugins/inputs/intel_pmu/intel_pmu_sample_config.go b/plugins/inputs/intel_pmu/intel_pmu_sample_config.go deleted file mode 100644 index ce91a44264c91..0000000000000 --- a/plugins/inputs/intel_pmu/intel_pmu_sample_config.go +++ /dev/null @@ -1,11 +0,0 @@ -//go:build linux && amd64 -// +build linux,amd64 - -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package intel_pmu - -func (i *IntelPMU) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/inputs/intel_powerstat/README.md b/plugins/inputs/intel_powerstat/README.md index 0b1e5cb5dd579..db84ef73f6fae 100644 --- a/plugins/inputs/intel_powerstat/README.md +++ b/plugins/inputs/intel_powerstat/README.md @@ -8,7 +8,7 @@ to take preventive/corrective actions based on platform busyness, CPU temperatur ## Configuration -```toml +```toml @sample.conf # Intel PowerStat plugin enables monitoring of platform metrics (power, TDP) and per-CPU metrics like temperature, power and utilization. [[inputs.intel_powerstat]] ## The user can choose which package metrics are monitored by the plugin with the package_metrics setting: diff --git a/plugins/inputs/intel_powerstat/intel_powerstat.go b/plugins/inputs/intel_powerstat/intel_powerstat.go index 78336bbdf6c89..1daeefcc892e4 100644 --- a/plugins/inputs/intel_powerstat/intel_powerstat.go +++ b/plugins/inputs/intel_powerstat/intel_powerstat.go @@ -1,9 +1,11 @@ +//go:generate ../../../tools/readme_config_includer/generator //go:build linux // +build linux package intel_powerstat import ( + _ "embed" "fmt" "math/big" "strconv" @@ -15,6 +17,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 + const ( cpuFrequency = "cpu_frequency" cpuBusyFrequency = "cpu_busy_frequency" @@ -56,6 +62,10 @@ type PowerStat struct { logOnce map[string]error } +func (*PowerStat) SampleConfig() string { + return sampleConfig +} + // Init performs one time setup of the plugin func (p *PowerStat) Init() error { p.parsePackageMetricsConfig() diff --git a/plugins/inputs/intel_powerstat/intel_powerstat_sample_config.go b/plugins/inputs/intel_powerstat/intel_powerstat_sample_config.go deleted file mode 100644 index 24bb2d804fcfb..0000000000000 --- a/plugins/inputs/intel_powerstat/intel_powerstat_sample_config.go +++ /dev/null @@ -1,11 +0,0 @@ -//go:build linux -// +build linux - -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package intel_powerstat - -func (p *PowerStat) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/inputs/intel_powerstat/sample.conf b/plugins/inputs/intel_powerstat/sample.conf index 75cf62a452edb..93e63fcf8fe7b 100644 --- a/plugins/inputs/intel_powerstat/sample.conf +++ b/plugins/inputs/intel_powerstat/sample.conf @@ -1,9 +1,16 @@ # Intel PowerStat plugin enables monitoring of platform metrics (power, TDP) and per-CPU metrics like temperature, power and utilization. [[inputs.intel_powerstat]] - ## All global metrics are always collected by Intel PowerStat plugin. - ## User can choose which per-CPU metrics are monitored by the plugin in cpu_metrics array. - ## Empty array means no per-CPU specific metrics will be collected by the plugin - in this case only platform level - ## telemetry will be exposed by Intel PowerStat plugin. + ## The user can choose which package metrics are monitored by the plugin with the package_metrics setting: + ## - The default, will collect "current_power_consumption", "current_dram_power_consumption" and "thermal_design_power" + ## - Setting this value to an empty array means no package metrics will be collected + ## - Finally, a user can specify individual metrics to capture from the supported options list ## Supported options: - ## "cpu_frequency", "cpu_busy_frequency", "cpu_temperature", "cpu_c1_state_residency", "cpu_c6_state_residency", "cpu_busy_cycles" + ## "current_power_consumption", "current_dram_power_consumption", "thermal_design_power", "max_turbo_frequency" + # package_metrics = ["current_power_consumption", "current_dram_power_consumption", "thermal_design_power"] + + ## The user can choose which per-CPU metrics are monitored by the plugin in cpu_metrics array. + ## Empty or missing array means no per-CPU specific metrics will be collected by the plugin. + ## Supported options: + ## "cpu_frequency", "cpu_c0_state_residency", "cpu_c1_state_residency", "cpu_c6_state_residency", "cpu_busy_cycles", "cpu_temperature", "cpu_busy_frequency" + ## ATTENTION: cpu_busy_cycles option is DEPRECATED - superseded by cpu_c0_state_residency # cpu_metrics = [] diff --git a/plugins/inputs/intel_rdt/README.md b/plugins/inputs/intel_rdt/README.md index 5c49d08be502d..a6eaa08393235 100644 --- a/plugins/inputs/intel_rdt/README.md +++ b/plugins/inputs/intel_rdt/README.md @@ -84,7 +84,7 @@ More about Intel RDT: [^|]*)\|(?P[^|]*)\|(?P.*)`) @@ -42,6 +48,33 @@ type Ipmi struct { Log telegraf.Logger `toml:"-"` } +const cmd = "ipmitool" + +func (*Ipmi) SampleConfig() string { + return sampleConfig +} + +func (m *Ipmi) Init() error { + // Set defaults + if m.Path == "" { + path, err := exec.LookPath(cmd) + if err != nil { + return fmt.Errorf("looking up %q failed: %v", cmd, err) + } + m.Path = path + } + if m.CachePath == "" { + m.CachePath = os.TempDir() + } + + // Check parameters + if m.Path == "" { + return fmt.Errorf("no path for %q specified", cmd) + } + + return nil +} + // Gather is the main execution function for the plugin func (m *Ipmi) Gather(acc telegraf.Accumulator) error { if len(m.Path) == 0 { @@ -282,16 +315,7 @@ func transform(s string) string { } func init() { - m := Ipmi{} - path, _ := exec.LookPath("ipmitool") - if len(path) > 0 { - m.Path = path - } - m.Timeout = config.Duration(time.Second * 20) - m.UseCache = false - m.CachePath = os.TempDir() inputs.Add("ipmi_sensor", func() telegraf.Input { - m := m - return &m + return &Ipmi{Timeout: config.Duration(20 * time.Second)} }) } diff --git a/plugins/inputs/ipmi_sensor/ipmi_sensor_sample_config.go b/plugins/inputs/ipmi_sensor/ipmi_sensor_sample_config.go deleted file mode 100644 index a3ab73163092e..0000000000000 --- a/plugins/inputs/ipmi_sensor/ipmi_sensor_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package ipmi_sensor - -func (m *Ipmi) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/inputs/ipmi_sensor/ipmi_sensor_test.go b/plugins/inputs/ipmi_sensor/ipmi_sensor_test.go index 504a7467f5130..a65dc5a1561bf 100644 --- a/plugins/inputs/ipmi_sensor/ipmi_sensor_test.go +++ b/plugins/inputs/ipmi_sensor/ipmi_sensor_test.go @@ -28,10 +28,8 @@ func TestGather(t *testing.T) { execCommand = fakeExecCommand var acc testutil.Accumulator - err := acc.GatherError(i.Gather) - - require.NoError(t, err) - + require.NoError(t, i.Init()) + require.NoError(t, acc.GatherError(i.Gather)) require.EqualValues(t, acc.NFields(), 262, "non-numeric measurements should be ignored") conn := NewConnection(i.Servers[0], i.Privilege, i.HexKey) @@ -132,8 +130,8 @@ func TestGather(t *testing.T) { Log: testutil.Logger{}, } - err = acc.GatherError(i.Gather) - require.NoError(t, err) + require.NoError(t, i.Init()) + require.NoError(t, acc.GatherError(i.Gather)) var testsWithoutServer = []struct { fields map[string]interface{} @@ -404,9 +402,8 @@ func TestGatherV2(t *testing.T) { execCommand = fakeExecCommandV2 var acc testutil.Accumulator - err := acc.GatherError(i.Gather) - - require.NoError(t, err) + require.NoError(t, i.Init()) + require.NoError(t, acc.GatherError(i.Gather)) conn := NewConnection(i.Servers[0], i.Privilege, i.HexKey) require.EqualValues(t, "USERID", conn.Username) @@ -443,8 +440,8 @@ func TestGatherV2(t *testing.T) { Log: testutil.Logger{}, } - err = acc.GatherError(i.Gather) - require.NoError(t, err) + require.NoError(t, i.Init()) + require.NoError(t, acc.GatherError(i.Gather)) var testsWithoutServer = []struct { fields map[string]interface{} diff --git a/plugins/inputs/ipset/README.md b/plugins/inputs/ipset/README.md index 77b840f01ead4..4fba5a292522a 100644 --- a/plugins/inputs/ipset/README.md +++ b/plugins/inputs/ipset/README.md @@ -46,7 +46,7 @@ Defaults!IPSETSAVE !logfile, !syslog, !pam_session ## Configuration -```toml +```toml @sample.conf # Gather packets and bytes counters from Linux ipsets [[inputs.ipset]] ## By default, we only show sets which have already matched at least 1 packet. diff --git a/plugins/inputs/ipset/ipset.go b/plugins/inputs/ipset/ipset.go index 6e98ac4c4dc74..7d7cd1bd65de1 100644 --- a/plugins/inputs/ipset/ipset.go +++ b/plugins/inputs/ipset/ipset.go @@ -1,8 +1,10 @@ +//go:generate ../../../tools/readme_config_includer/generator package ipset import ( "bufio" "bytes" + _ "embed" "fmt" "os/exec" "strconv" @@ -15,6 +17,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 + // Ipsets is a telegraf plugin to gather packets and bytes counters from ipset type Ipset struct { IncludeUnmatchedSets bool @@ -29,6 +35,10 @@ const measurement = "ipset" var defaultTimeout = config.Duration(time.Second) +func (*Ipset) SampleConfig() string { + return sampleConfig +} + func (i *Ipset) Init() error { _, err := exec.LookPath("ipset") if err != nil { diff --git a/plugins/inputs/ipset/ipset_sample_config.go b/plugins/inputs/ipset/ipset_sample_config.go deleted file mode 100644 index ce21dcdb39529..0000000000000 --- a/plugins/inputs/ipset/ipset_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package ipset - -func (i *Ipset) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/inputs/iptables/README.md b/plugins/inputs/iptables/README.md index 015b0b0a83647..07254ebd8abd3 100644 --- a/plugins/inputs/iptables/README.md +++ b/plugins/inputs/iptables/README.md @@ -51,7 +51,7 @@ Defining multiple instances of this plugin in telegraf.conf can lead to concurre ## Configuration -```toml +```toml @sample.conf # Gather packets and bytes throughput from iptables [[inputs.iptables]] ## iptables require root access on most systems. diff --git a/plugins/inputs/iptables/iptables.go b/plugins/inputs/iptables/iptables.go index a1160d0ef8df0..8d4c4820dee53 100644 --- a/plugins/inputs/iptables/iptables.go +++ b/plugins/inputs/iptables/iptables.go @@ -1,9 +1,11 @@ +//go:generate ../../../tools/readme_config_includer/generator //go:build linux // +build linux package iptables import ( + _ "embed" "errors" "os/exec" "regexp" @@ -14,6 +16,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 + // Iptables is a telegraf plugin to gather packets and bytes throughput from Linux's iptables packet filter. type Iptables struct { UseSudo bool @@ -24,6 +30,10 @@ type Iptables struct { lister chainLister } +func (*Iptables) SampleConfig() string { + return sampleConfig +} + // Gather gathers iptables packets and bytes throughput from the configured tables and chains. func (ipt *Iptables) Gather(acc telegraf.Accumulator) error { if ipt.Table == "" || len(ipt.Chains) == 0 { @@ -123,7 +133,7 @@ type chainLister func(table, chain string) (string, error) func init() { inputs.Add("iptables", func() telegraf.Input { - ipt := new(Iptables) + ipt := &Iptables{} ipt.lister = ipt.chainList return ipt }) diff --git a/plugins/inputs/iptables/iptables_sample_config.go b/plugins/inputs/iptables/iptables_sample_config.go deleted file mode 100644 index 572222aabe53c..0000000000000 --- a/plugins/inputs/iptables/iptables_sample_config.go +++ /dev/null @@ -1,11 +0,0 @@ -//go:build linux -// +build linux - -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package iptables - -func (ipt *Iptables) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/inputs/ipvs/README.md b/plugins/inputs/ipvs/README.md index d195fa57edc8c..ccea19690a298 100644 --- a/plugins/inputs/ipvs/README.md +++ b/plugins/inputs/ipvs/README.md @@ -7,7 +7,7 @@ metrics about ipvs virtual and real servers. ## Configuration -```toml +```toml @sample.conf # Collect virtual and real server stats from Linux IPVS [[inputs.ipvs]] # no configuration diff --git a/plugins/inputs/ipvs/ipvs.go b/plugins/inputs/ipvs/ipvs.go index 7e709299564c6..6383460e28e26 100644 --- a/plugins/inputs/ipvs/ipvs.go +++ b/plugins/inputs/ipvs/ipvs.go @@ -1,26 +1,37 @@ +//go:generate ../../../tools/readme_config_includer/generator //go:build linux // +build linux package ipvs import ( + _ "embed" "fmt" "math/bits" "strconv" "syscall" + "github.com/moby/ipvs" + "github.com/influxdata/telegraf" "github.com/influxdata/telegraf/plugins/common/logrus" "github.com/influxdata/telegraf/plugins/inputs" - "github.com/moby/ipvs" ) +// DO NOT REMOVE THE NEXT TWO LINES! This is required to embedd the sampleConfig data. +//go:embed sample.conf +var sampleConfig string + // IPVS holds the state for this input plugin type IPVS struct { handle *ipvs.Handle Log telegraf.Logger } +func (*IPVS) SampleConfig() string { + return sampleConfig +} + // Gather gathers the stats func (i *IPVS) Gather(acc telegraf.Accumulator) error { if i.handle == nil { diff --git a/plugins/inputs/ipvs/ipvs_sample_config.go b/plugins/inputs/ipvs/ipvs_sample_config.go deleted file mode 100644 index 2f917971a0f4f..0000000000000 --- a/plugins/inputs/ipvs/ipvs_sample_config.go +++ /dev/null @@ -1,11 +0,0 @@ -//go:build linux -// +build linux - -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package ipvs - -func (i *IPVS) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/inputs/jenkins/README.md b/plugins/inputs/jenkins/README.md index 9bcc7eb1da986..b4a484457fe3d 100644 --- a/plugins/inputs/jenkins/README.md +++ b/plugins/inputs/jenkins/README.md @@ -6,7 +6,7 @@ This plugin does not require a plugin on jenkins and it makes use of Jenkins API ## Configuration -```toml +```toml @sample.conf # Read jobs and cluster metrics from Jenkins instances [[inputs.jenkins]] ## The Jenkins URL in the format "schema://host:port" diff --git a/plugins/inputs/jenkins/jenkins.go b/plugins/inputs/jenkins/jenkins.go index 73eb3330a2a2c..160fcd66b48ae 100644 --- a/plugins/inputs/jenkins/jenkins.go +++ b/plugins/inputs/jenkins/jenkins.go @@ -1,7 +1,9 @@ +//go:generate ../../../tools/readme_config_includer/generator package jenkins import ( "context" + _ "embed" "fmt" "net/http" "net/url" @@ -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 + // Jenkins plugin gathers information about the nodes and jobs running in a jenkins instance. type Jenkins struct { URL string @@ -54,6 +60,10 @@ const ( measurementJob = "jenkins_job" ) +func (*Jenkins) SampleConfig() string { + return sampleConfig +} + // Gather implements telegraf.Input interface func (j *Jenkins) Gather(acc telegraf.Accumulator) error { if j.client == nil { diff --git a/plugins/inputs/jenkins/jenkins_sample_config.go b/plugins/inputs/jenkins/jenkins_sample_config.go deleted file mode 100644 index b1edb6b8a7bf6..0000000000000 --- a/plugins/inputs/jenkins/jenkins_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package jenkins - -func (j *Jenkins) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/inputs/jolokia/README.md b/plugins/inputs/jolokia/README.md index 3b152f8e096a4..ba9b90854564c 100644 --- a/plugins/inputs/jolokia/README.md +++ b/plugins/inputs/jolokia/README.md @@ -4,7 +4,7 @@ ## Configuration -```toml +```toml @sample.conf # Read JMX metrics through Jolokia [[inputs.jolokia]] ## This is the context root used to compose the jolokia url diff --git a/plugins/inputs/jolokia/jolokia.go b/plugins/inputs/jolokia/jolokia.go index d0cac7d0bc4f8..18c7e610d664b 100644 --- a/plugins/inputs/jolokia/jolokia.go +++ b/plugins/inputs/jolokia/jolokia.go @@ -1,7 +1,9 @@ +//go:generate ../../../tools/readme_config_includer/generator package jolokia import ( "bytes" + _ "embed" "encoding/json" "fmt" "io" @@ -14,6 +16,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 + // Default http timeouts var DefaultResponseHeaderTimeout = config.Duration(3 * time.Second) var DefaultClientTimeout = config.Duration(4 * time.Second) @@ -182,6 +188,10 @@ func (j *Jolokia) extractValues(measurement string, value interface{}, fields ma } } +func (*Jolokia) SampleConfig() string { + return sampleConfig +} + func (j *Jolokia) Gather(acc telegraf.Accumulator) error { if j.jClient == nil { j.Log.Warn("DEPRECATED: the jolokia plugin has been deprecated " + diff --git a/plugins/inputs/jolokia/jolokia_sample_config.go b/plugins/inputs/jolokia/jolokia_sample_config.go deleted file mode 100644 index 292682c93facf..0000000000000 --- a/plugins/inputs/jolokia/jolokia_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package jolokia - -func (j *Jolokia) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/inputs/jolokia2/README.md b/plugins/inputs/jolokia2/README.md index 1377df84b446c..665a4f1dacb17 100644 --- a/plugins/inputs/jolokia2/README.md +++ b/plugins/inputs/jolokia2/README.md @@ -11,7 +11,7 @@ The [Jolokia](http://jolokia.org) _agent_ and _proxy_ input plugins collect JMX The `jolokia2_agent` input plugin reads JMX metrics from one or more [Jolokia agent](https://jolokia.org/agent/jvm.html) REST endpoints. -```toml +```toml @sample.conf [[inputs.jolokia2_agent]] urls = ["http://agent:8080/jolokia"] diff --git a/plugins/inputs/jolokia2/jolokia2_agent/jolokia2_agent.go b/plugins/inputs/jolokia2/jolokia2_agent/jolokia2_agent.go index 4cb80f4b07d3a..0b425c62d726d 100644 --- a/plugins/inputs/jolokia2/jolokia2_agent/jolokia2_agent.go +++ b/plugins/inputs/jolokia2/jolokia2_agent/jolokia2_agent.go @@ -1,6 +1,9 @@ +//go:generate ../../../../tools/readme_config_includer/generator package jolokia2_agent import ( + _ "embed" + "fmt" "sync" "time" @@ -11,6 +14,10 @@ import ( "github.com/influxdata/telegraf/plugins/inputs/jolokia2/common" ) +// DO NOT REMOVE THE NEXT TWO LINES! This is required to embedd the sampleConfig data. +//go:embed sample.conf +var sampleConfig string + type JolokiaAgent struct { DefaultFieldPrefix string DefaultFieldSeparator string @@ -28,6 +35,10 @@ type JolokiaAgent struct { clients []*common.Client } +func (*JolokiaAgent) SampleConfig() string { + return sampleConfig +} + func (ja *JolokiaAgent) Gather(acc telegraf.Accumulator) error { if ja.gatherer == nil { ja.gatherer = common.NewGatherer(ja.createMetrics()) diff --git a/plugins/inputs/jolokia2/jolokia2_agent/jolokia2_agent_sample_config.go b/plugins/inputs/jolokia2/jolokia2_agent/jolokia2_agent_sample_config.go deleted file mode 100644 index 27840458d1d9d..0000000000000 --- a/plugins/inputs/jolokia2/jolokia2_agent/jolokia2_agent_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//go:generate go run ../../../../tools/generate_plugindata/main.go -//go:generate go run ../../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package jolokia2_agent - -func (ja *JolokiaAgent) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/inputs/jolokia2/jolokia2_agent/sample.conf b/plugins/inputs/jolokia2/jolokia2_agent/sample.conf index 7e5529edc568e..24f0e4636501d 100644 --- a/plugins/inputs/jolokia2/jolokia2_agent/sample.conf +++ b/plugins/inputs/jolokia2/jolokia2_agent/sample.conf @@ -21,4 +21,3 @@ name = "java_runtime" mbean = "java.lang:type=Runtime" paths = ["Uptime"] - diff --git a/plugins/inputs/jolokia2/jolokia2_proxy/jolokia2_proxy_sample_config.go b/plugins/inputs/jolokia2/jolokia2_proxy/jolokia2_proxy_sample_config.go deleted file mode 100644 index b99cf0aa9009d..0000000000000 --- a/plugins/inputs/jolokia2/jolokia2_proxy/jolokia2_proxy_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//go:generate go run ../../../../tools/generate_plugindata/main.go -//go:generate go run ../../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package jolokia2_proxy - -func (ja *JolokiaProxy) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/inputs/jolokia2/jolokia2_proxy/jolokia_proxy.go b/plugins/inputs/jolokia2/jolokia2_proxy/jolokia_proxy.go index 1354182e12c77..1a31d9ccc5ac0 100644 --- a/plugins/inputs/jolokia2/jolokia2_proxy/jolokia_proxy.go +++ b/plugins/inputs/jolokia2/jolokia2_proxy/jolokia_proxy.go @@ -1,6 +1,8 @@ +//go:generate ../../../../tools/readme_config_includer/generator package jolokia2_proxy import ( + _ "embed" "time" "github.com/influxdata/telegraf" @@ -9,6 +11,10 @@ import ( "github.com/influxdata/telegraf/plugins/inputs/jolokia2/common" ) +// DO NOT REMOVE THE NEXT TWO LINES! This is required to embedd the sampleConfig data. +//go:embed sample.conf +var sampleConfig string + type JolokiaProxy struct { DefaultFieldPrefix string DefaultFieldSeparator string @@ -35,6 +41,10 @@ type JolokiaProxyTargetConfig struct { Password string } +func (*JolokiaProxy) SampleConfig() string { + return sampleConfig +} + func (jp *JolokiaProxy) Gather(acc telegraf.Accumulator) error { if jp.gatherer == nil { jp.gatherer = common.NewGatherer(jp.createMetrics()) diff --git a/plugins/inputs/jti_openconfig_telemetry/README.md b/plugins/inputs/jti_openconfig_telemetry/README.md index 895a4b5cf3de6..deeb7cae1d260 100644 --- a/plugins/inputs/jti_openconfig_telemetry/README.md +++ b/plugins/inputs/jti_openconfig_telemetry/README.md @@ -5,7 +5,7 @@ This plugin reads Juniper Networks implementation of OpenConfig telemetry data f ## Configuration -```toml +```toml @sample.conf # Subscribe and receive OpenConfig Telemetry data using JTI [[inputs.jti_openconfig_telemetry]] ## List of device addresses to collect telemetry from diff --git a/plugins/inputs/jti_openconfig_telemetry/jti_openconfig_telemetry.go b/plugins/inputs/jti_openconfig_telemetry/jti_openconfig_telemetry.go index 9d12ad46c8254..f1ac43859e0c6 100644 --- a/plugins/inputs/jti_openconfig_telemetry/jti_openconfig_telemetry.go +++ b/plugins/inputs/jti_openconfig_telemetry/jti_openconfig_telemetry.go @@ -1,6 +1,8 @@ +//go:generate ../../../tools/readme_config_includer/generator package jti_openconfig_telemetry import ( + _ "embed" "fmt" "net" "regexp" @@ -22,6 +24,10 @@ import ( telemetry "github.com/influxdata/telegraf/plugins/inputs/jti_openconfig_telemetry/oc" ) +// DO NOT REMOVE THE NEXT TWO LINES! This is required to embedd the sampleConfig data. +//go:embed sample.conf +var sampleConfig string + type OpenConfigTelemetry struct { Servers []string `toml:"servers"` Sensors []string `toml:"sensors"` @@ -46,6 +52,10 @@ var ( keyPathRegex = regexp.MustCompile(`/([^/]*)\[([A-Za-z0-9\-/]*=[^\[]*)]`) ) +func (*OpenConfigTelemetry) SampleConfig() string { + return sampleConfig +} + func (m *OpenConfigTelemetry) Gather(_ telegraf.Accumulator) error { return nil } diff --git a/plugins/inputs/jti_openconfig_telemetry/jti_openconfig_telemetry_sample_config.go b/plugins/inputs/jti_openconfig_telemetry/jti_openconfig_telemetry_sample_config.go deleted file mode 100644 index 8094b58dd1d5e..0000000000000 --- a/plugins/inputs/jti_openconfig_telemetry/jti_openconfig_telemetry_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package jti_openconfig_telemetry - -func (m *OpenConfigTelemetry) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/inputs/kafka_consumer/README.md b/plugins/inputs/kafka_consumer/README.md index 12d8005c1bea3..1bc3f2cb1ddd9 100644 --- a/plugins/inputs/kafka_consumer/README.md +++ b/plugins/inputs/kafka_consumer/README.md @@ -8,7 +8,7 @@ and use the old zookeeper connection method. ## Configuration -```toml +```toml @sample.conf # Read metrics from Kafka topics [[inputs.kafka_consumer]] ## Kafka brokers. diff --git a/plugins/inputs/kafka_consumer/kafka_consumer.go b/plugins/inputs/kafka_consumer/kafka_consumer.go index 393d7e9327977..b2f679f7eeea2 100644 --- a/plugins/inputs/kafka_consumer/kafka_consumer.go +++ b/plugins/inputs/kafka_consumer/kafka_consumer.go @@ -1,7 +1,9 @@ +//go:generate ../../../tools/readme_config_includer/generator package kafka_consumer import ( "context" + _ "embed" "fmt" "strings" "sync" @@ -17,6 +19,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 defaultMaxProcessingTime = config.Duration(100 * time.Millisecond) @@ -67,6 +73,10 @@ func (*SaramaCreator) Create(brokers []string, group string, cfg *sarama.Config) return sarama.NewConsumerGroup(brokers, group, cfg) } +func (*KafkaConsumer) SampleConfig() string { + return sampleConfig +} + func (k *KafkaConsumer) SetParser(parser parsers.Parser) { k.parser = parser } diff --git a/plugins/inputs/kafka_consumer/kafka_consumer_sample_config.go b/plugins/inputs/kafka_consumer/kafka_consumer_sample_config.go deleted file mode 100644 index 985786650e783..0000000000000 --- a/plugins/inputs/kafka_consumer/kafka_consumer_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package kafka_consumer - -func (k *KafkaConsumer) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/inputs/kafka_consumer_legacy/README.md b/plugins/inputs/kafka_consumer_legacy/README.md index 755277ed84543..b9d9e97bbf5a2 100644 --- a/plugins/inputs/kafka_consumer_legacy/README.md +++ b/plugins/inputs/kafka_consumer_legacy/README.md @@ -10,7 +10,7 @@ from the same topic in parallel. ## Configuration -```toml +```toml @sample.conf ## DEPRECATED: The 'kafka_consumer_legacy' plugin is deprecated in version 1.4.0, use 'inputs.kafka_consumer' instead, NOTE: 'kafka_consumer' only supports Kafka v0.8+. # Read metrics from Kafka topic(s) [[inputs.kafka_consumer_legacy]] diff --git a/plugins/inputs/kafka_consumer_legacy/kafka_consumer_legacy.go b/plugins/inputs/kafka_consumer_legacy/kafka_consumer_legacy.go index 58d6b207ff80e..6e3927d92cb43 100644 --- a/plugins/inputs/kafka_consumer_legacy/kafka_consumer_legacy.go +++ b/plugins/inputs/kafka_consumer_legacy/kafka_consumer_legacy.go @@ -1,18 +1,24 @@ +//go:generate ../../../tools/readme_config_includer/generator package kafka_consumer_legacy import ( + _ "embed" "fmt" "strings" "sync" + "github.com/Shopify/sarama" + "github.com/wvanbergen/kafka/consumergroup" + "github.com/influxdata/telegraf" "github.com/influxdata/telegraf/plugins/inputs" "github.com/influxdata/telegraf/plugins/parsers" - - "github.com/Shopify/sarama" - "github.com/wvanbergen/kafka/consumergroup" ) +// DO NOT REMOVE THE NEXT TWO LINES! This is required to embedd the sampleConfig data. +//go:embed sample.conf +var sampleConfig string + type Kafka struct { ConsumerGroup string Topics []string @@ -47,6 +53,10 @@ type Kafka struct { doNotCommitMsgs bool } +func (*Kafka) SampleConfig() string { + return sampleConfig +} + func (k *Kafka) SetParser(parser parsers.Parser) { k.parser = parser } diff --git a/plugins/inputs/kafka_consumer_legacy/kafka_consumer_legacy_sample_config.go b/plugins/inputs/kafka_consumer_legacy/kafka_consumer_legacy_sample_config.go deleted file mode 100644 index ee4143dddb122..0000000000000 --- a/plugins/inputs/kafka_consumer_legacy/kafka_consumer_legacy_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package kafka_consumer_legacy - -func (k *Kafka) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/inputs/kapacitor/README.md b/plugins/inputs/kapacitor/README.md index f089cee8f65a1..b73db98230a02 100644 --- a/plugins/inputs/kapacitor/README.md +++ b/plugins/inputs/kapacitor/README.md @@ -4,7 +4,7 @@ The Kapacitor plugin collects metrics from the given Kapacitor instances. ## Configuration -```toml +```toml @sample.conf # Read Kapacitor-formatted JSON metrics from one or more HTTP endpoints [[inputs.kapacitor]] ## Multiple URLs from which to read Kapacitor-formatted JSON @@ -356,7 +356,7 @@ The number of events collected by Kapacitor topics. --- -*Note:* The Kapacitor variables `host`, `cluster_id`, and `server_id` +__Note:__ The Kapacitor variables `host`, `cluster_id`, and `server_id` are currently not recorded due to the potential high cardinality of these values. diff --git a/plugins/inputs/kapacitor/kapacitor.go b/plugins/inputs/kapacitor/kapacitor.go index a624bfc30dd54..1bb70abba8c0f 100644 --- a/plugins/inputs/kapacitor/kapacitor.go +++ b/plugins/inputs/kapacitor/kapacitor.go @@ -1,6 +1,8 @@ +//go:generate ../../../tools/readme_config_includer/generator package kapacitor import ( + _ "embed" "encoding/json" "fmt" "net/http" @@ -13,6 +15,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 + const ( defaultURL = "http://localhost:9092/kapacitor/v1/debug/vars" ) @@ -25,6 +31,10 @@ type Kapacitor struct { client *http.Client } +func (*Kapacitor) SampleConfig() string { + return sampleConfig +} + func (k *Kapacitor) Gather(acc telegraf.Accumulator) error { if k.client == nil { client, err := k.createHTTPClient() diff --git a/plugins/inputs/kapacitor/kapacitor_sample_config.go b/plugins/inputs/kapacitor/kapacitor_sample_config.go deleted file mode 100644 index 9a82a9d2f99fe..0000000000000 --- a/plugins/inputs/kapacitor/kapacitor_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package kapacitor - -func (*Kapacitor) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/inputs/kernel/README.md b/plugins/inputs/kernel/README.md index d3467e826db8f..a2063a332499b 100644 --- a/plugins/inputs/kernel/README.md +++ b/plugins/inputs/kernel/README.md @@ -41,7 +41,7 @@ Number of forks since boot. ## Configuration -```toml +```toml @sample.conf # Get kernel statistics from /proc/stat [[inputs.kernel]] # no configuration diff --git a/plugins/inputs/kernel/kernel.go b/plugins/inputs/kernel/kernel.go index 3afcd4bffb188..ea5a6bd0239c9 100644 --- a/plugins/inputs/kernel/kernel.go +++ b/plugins/inputs/kernel/kernel.go @@ -1,3 +1,4 @@ +//go:generate ../../../tools/readme_config_includer/generator //go:build linux // +build linux @@ -5,6 +6,7 @@ package kernel import ( "bytes" + _ "embed" "fmt" "os" "strconv" @@ -14,6 +16,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 + // /proc/stat file line prefixes to gather stats on: var ( interrupts = []byte("intr") @@ -28,6 +34,10 @@ type Kernel struct { entropyStatFile string } +func (*Kernel) SampleConfig() string { + return sampleConfig +} + func (k *Kernel) Gather(acc telegraf.Accumulator) error { data, err := k.getProcStat() if err != nil { diff --git a/plugins/inputs/kernel/kernel_sample_config.go b/plugins/inputs/kernel/kernel_sample_config.go deleted file mode 100644 index 7109de4c2ba10..0000000000000 --- a/plugins/inputs/kernel/kernel_sample_config.go +++ /dev/null @@ -1,11 +0,0 @@ -//go:build linux -// +build linux - -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package kernel - -func (k *Kernel) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/inputs/kernel_vmstat/README.md b/plugins/inputs/kernel_vmstat/README.md index a5e54f158c4f7..f5a9773b6eb0d 100644 --- a/plugins/inputs/kernel_vmstat/README.md +++ b/plugins/inputs/kernel_vmstat/README.md @@ -110,7 +110,7 @@ nr_bounce 0 ## Configuration -```toml +```toml @sample.conf # Get kernel statistics from /proc/vmstat [[inputs.kernel_vmstat]] # no configuration diff --git a/plugins/inputs/kernel_vmstat/kernel_vmstat.go b/plugins/inputs/kernel_vmstat/kernel_vmstat.go index b34d2654de5bb..e54cba84dcf59 100644 --- a/plugins/inputs/kernel_vmstat/kernel_vmstat.go +++ b/plugins/inputs/kernel_vmstat/kernel_vmstat.go @@ -1,3 +1,4 @@ +//go:generate ../../../tools/readme_config_includer/generator //go:build linux // +build linux @@ -5,6 +6,7 @@ package kernel_vmstat import ( "bytes" + _ "embed" "fmt" "os" "strconv" @@ -13,10 +15,18 @@ 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 KernelVmstat struct { statFile string } +func (*KernelVmstat) SampleConfig() string { + return sampleConfig +} + func (k *KernelVmstat) Gather(acc telegraf.Accumulator) error { data, err := k.getProcVmstat() if err != nil { diff --git a/plugins/inputs/kernel_vmstat/kernel_vmstat_sample_config.go b/plugins/inputs/kernel_vmstat/kernel_vmstat_sample_config.go deleted file mode 100644 index 98f0dd27af944..0000000000000 --- a/plugins/inputs/kernel_vmstat/kernel_vmstat_sample_config.go +++ /dev/null @@ -1,11 +0,0 @@ -//go:build linux -// +build linux - -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package kernel_vmstat - -func (k *KernelVmstat) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/inputs/kibana/README.md b/plugins/inputs/kibana/README.md index d3391eb2b03e3..e0d95f61a4da0 100644 --- a/plugins/inputs/kibana/README.md +++ b/plugins/inputs/kibana/README.md @@ -9,7 +9,7 @@ The `kibana` plugin queries the [Kibana][] API to obtain the service status. ## Configuration -```toml +```toml @sample.conf # Read status information from one or more Kibana servers [[inputs.kibana]] ## Specify a list of one or more Kibana servers diff --git a/plugins/inputs/kibana/kibana.go b/plugins/inputs/kibana/kibana.go index 749c8d927d221..c99b8a1f9bbda 100644 --- a/plugins/inputs/kibana/kibana.go +++ b/plugins/inputs/kibana/kibana.go @@ -1,6 +1,8 @@ +//go:generate ../../../tools/readme_config_includer/generator package kibana import ( + _ "embed" "encoding/json" "fmt" "io" @@ -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 + const statusPath = "/api/status" type kibanaStatus struct { @@ -110,6 +116,10 @@ func mapHealthStatusToCode(s string) int { return 0 } +func (*Kibana) SampleConfig() string { + return sampleConfig +} + func (k *Kibana) Gather(acc telegraf.Accumulator) error { if k.client == nil { client, err := k.createHTTPClient() diff --git a/plugins/inputs/kibana/kibana_sample_config.go b/plugins/inputs/kibana/kibana_sample_config.go deleted file mode 100644 index d4d889e2c0fa3..0000000000000 --- a/plugins/inputs/kibana/kibana_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package kibana - -func (k *Kibana) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/inputs/kinesis_consumer/README.md b/plugins/inputs/kinesis_consumer/README.md index 0306627ee72f5..d571d887fb0c6 100644 --- a/plugins/inputs/kinesis_consumer/README.md +++ b/plugins/inputs/kinesis_consumer/README.md @@ -5,7 +5,7 @@ and creates metrics using one of the supported [input data formats][]. ## Configuration -```toml +```toml @sample.conf # Configuration for the AWS Kinesis input. [[inputs.kinesis_consumer]] ## Amazon REGION of kinesis endpoint. diff --git a/plugins/inputs/kinesis_consumer/kinesis_consumer.go b/plugins/inputs/kinesis_consumer/kinesis_consumer.go index 343c4b082fdca..5bd5ba08351bd 100644 --- a/plugins/inputs/kinesis_consumer/kinesis_consumer.go +++ b/plugins/inputs/kinesis_consumer/kinesis_consumer.go @@ -1,3 +1,4 @@ +//go:generate ../../../tools/readme_config_includer/generator package kinesis_consumer import ( @@ -5,6 +6,7 @@ import ( "compress/gzip" "compress/zlib" "context" + _ "embed" "fmt" "io" "math/big" @@ -23,6 +25,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 + type ( DynamoDB struct { AppName string `toml:"app_name"` @@ -73,6 +79,10 @@ type processContent func([]byte) ([]byte, error) // this is the largest sequence number allowed - https://docs.aws.amazon.com/kinesis/latest/APIReference/API_SequenceNumberRange.html var maxSeq = strToBint(strings.Repeat("9", 129)) +func (*KinesisConsumer) SampleConfig() string { + return sampleConfig +} + func (k *KinesisConsumer) SetParser(parser parsers.Parser) { k.parser = parser } diff --git a/plugins/inputs/kinesis_consumer/kinesis_consumer_sample_config.go b/plugins/inputs/kinesis_consumer/kinesis_consumer_sample_config.go deleted file mode 100644 index df1e931f351c3..0000000000000 --- a/plugins/inputs/kinesis_consumer/kinesis_consumer_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package kinesis_consumer - -func (k *KinesisConsumer) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/inputs/knx_listener/README.md b/plugins/inputs/knx_listener/README.md index 14d77556f0465..04acac83a254d 100644 --- a/plugins/inputs/knx_listener/README.md +++ b/plugins/inputs/knx_listener/README.md @@ -9,7 +9,7 @@ underlying "knx-go" project site (). This is a sample config for the plugin. -```toml +```toml @sample.conf # Listener capable of handling KNX bus messages provided through a KNX-IP Interface. [[inputs.knx_listener]] ## Type of KNX-IP interface. diff --git a/plugins/inputs/knx_listener/knx_listener.go b/plugins/inputs/knx_listener/knx_listener.go index 6ecd1865ca1de..bde61ebb7c28d 100644 --- a/plugins/inputs/knx_listener/knx_listener.go +++ b/plugins/inputs/knx_listener/knx_listener.go @@ -1,6 +1,8 @@ +//go:generate ../../../tools/readme_config_includer/generator package knx_listener import ( + _ "embed" "fmt" "reflect" "sync" @@ -12,6 +14,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 KNXInterface interface { Inbound() <-chan knx.GroupEvent Close() @@ -42,6 +48,10 @@ type KNXListener struct { wg sync.WaitGroup } +func (*KNXListener) SampleConfig() string { + return sampleConfig +} + func (kl *KNXListener) Gather(_ telegraf.Accumulator) error { return nil } diff --git a/plugins/inputs/knx_listener/knx_listener_sample_config.go b/plugins/inputs/knx_listener/knx_listener_sample_config.go deleted file mode 100644 index a40272dd051e2..0000000000000 --- a/plugins/inputs/knx_listener/knx_listener_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package knx_listener - -func (kl *KNXListener) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/inputs/kube_inventory/README.md b/plugins/inputs/kube_inventory/README.md index f58f0e2f8ecc1..0f3150e7b08a6 100644 --- a/plugins/inputs/kube_inventory/README.md +++ b/plugins/inputs/kube_inventory/README.md @@ -33,7 +33,7 @@ avoid cardinality issues: ## Configuration -```toml +```toml @sample.conf # Read metrics from the Kubernetes api [[inputs.kube_inventory]] ## URL for the Kubernetes API diff --git a/plugins/inputs/kube_inventory/kube_inventory.go b/plugins/inputs/kube_inventory/kube_inventory.go index 87af3b4de1c42..be804d679e44b 100644 --- a/plugins/inputs/kube_inventory/kube_inventory.go +++ b/plugins/inputs/kube_inventory/kube_inventory.go @@ -1,7 +1,9 @@ +//go:generate ../../../tools/readme_config_includer/generator package kube_inventory import ( "context" + _ "embed" "fmt" "os" "strconv" @@ -18,6 +20,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 + const ( defaultServiceAccountPath = "/run/secrets/kubernetes.io/serviceaccount/token" ) @@ -44,6 +50,10 @@ type KubernetesInventory struct { selectorFilter filter.Filter } +func (*KubernetesInventory) SampleConfig() string { + return sampleConfig +} + func (ki *KubernetesInventory) Init() error { // If neither are provided, use the default service account. if ki.BearerToken == "" && ki.BearerTokenString == "" { diff --git a/plugins/inputs/kube_inventory/kube_inventory_sample_config.go b/plugins/inputs/kube_inventory/kube_inventory_sample_config.go deleted file mode 100644 index c18c20175ed45..0000000000000 --- a/plugins/inputs/kube_inventory/kube_inventory_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package kube_inventory - -func (ki *KubernetesInventory) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/inputs/kubernetes/README.md b/plugins/inputs/kubernetes/README.md index 035bdb8560e9c..c0b4c96c7d3a9 100644 --- a/plugins/inputs/kubernetes/README.md +++ b/plugins/inputs/kubernetes/README.md @@ -34,7 +34,7 @@ avoid cardinality issues: ## Configuration -```toml +```toml @sample.conf # Read metrics from the kubernetes kubelet api [[inputs.kubernetes]] ## URL for the kubelet diff --git a/plugins/inputs/kubernetes/kubernetes.go b/plugins/inputs/kubernetes/kubernetes.go index 7a2301919f02d..a1e9675311700 100644 --- a/plugins/inputs/kubernetes/kubernetes.go +++ b/plugins/inputs/kubernetes/kubernetes.go @@ -1,6 +1,8 @@ +//go:generate ../../../tools/readme_config_includer/generator package kubernetes import ( + _ "embed" "encoding/json" "fmt" "net/http" @@ -15,6 +17,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 + // Kubernetes represents the config object for the plugin type Kubernetes struct { URL string @@ -49,6 +55,10 @@ func init() { }) } +func (*Kubernetes) SampleConfig() string { + return sampleConfig +} + func (k *Kubernetes) Init() error { // If neither are provided, use the default service account. if k.BearerToken == "" && k.BearerTokenString == "" { diff --git a/plugins/inputs/kubernetes/kubernetes_sample_config.go b/plugins/inputs/kubernetes/kubernetes_sample_config.go deleted file mode 100644 index 777ed7f4a530d..0000000000000 --- a/plugins/inputs/kubernetes/kubernetes_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package kubernetes - -func (k *Kubernetes) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/inputs/lanz/README.md b/plugins/inputs/lanz/README.md index 589f6773abc49..650039ccaf899 100644 --- a/plugins/inputs/lanz/README.md +++ b/plugins/inputs/lanz/README.md @@ -18,7 +18,7 @@ You will need to configure LANZ and enable streaming LANZ data. - - -```toml +```toml @sample.conf # Read metrics off Arista LANZ, via socket [[inputs.lanz]] ## URL to Arista LANZ endpoint diff --git a/plugins/inputs/lanz/lanz.go b/plugins/inputs/lanz/lanz.go index 6af46f09687f2..525877336fd90 100644 --- a/plugins/inputs/lanz/lanz.go +++ b/plugins/inputs/lanz/lanz.go @@ -1,6 +1,8 @@ +//go:generate ../../../tools/readme_config_includer/generator package lanz import ( + _ "embed" "net/url" "strconv" "sync" @@ -13,6 +15,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 + func init() { inputs.Add("lanz", func() telegraf.Input { return NewLanz() @@ -29,6 +35,10 @@ func NewLanz() *Lanz { return &Lanz{} } +func (*Lanz) SampleConfig() string { + return sampleConfig +} + func (l *Lanz) Gather(_ telegraf.Accumulator) error { return nil } diff --git a/plugins/inputs/lanz/lanz_sample_config.go b/plugins/inputs/lanz/lanz_sample_config.go deleted file mode 100644 index 31c66d7d301dd..0000000000000 --- a/plugins/inputs/lanz/lanz_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package lanz - -func (l *Lanz) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/inputs/leofs/README.md b/plugins/inputs/leofs/README.md index 4034a7fe93fa1..dcb1448c7f645 100644 --- a/plugins/inputs/leofs/README.md +++ b/plugins/inputs/leofs/README.md @@ -4,7 +4,7 @@ The LeoFS plugin gathers metrics of LeoGateway, LeoManager, and LeoStorage using ## Configuration -```toml +```toml @sample.conf # Read metrics from a LeoFS Server via SNMP [[inputs.leofs]] ## An array of URLs of the form: diff --git a/plugins/inputs/leofs/leofs.go b/plugins/inputs/leofs/leofs.go index 2888cb23c699b..bc7e22860fbbe 100644 --- a/plugins/inputs/leofs/leofs.go +++ b/plugins/inputs/leofs/leofs.go @@ -1,7 +1,9 @@ +//go:generate ../../../tools/readme_config_includer/generator package leofs import ( "bufio" + _ "embed" "fmt" "os/exec" "strconv" @@ -14,6 +16,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 + const oid = ".1.3.6.1.4.1.35450" // For Manager Master @@ -146,6 +152,10 @@ var serverTypeMapping = map[string]ServerType{ "4001": ServerTypeGateway, } +func (*LeoFS) SampleConfig() string { + return sampleConfig +} + func (l *LeoFS) Gather(acc telegraf.Accumulator) error { if len(l.Servers) == 0 { return l.gatherServer(defaultEndpoint, ServerTypeManagerMaster, acc) diff --git a/plugins/inputs/leofs/leofs_sample_config.go b/plugins/inputs/leofs/leofs_sample_config.go deleted file mode 100644 index 94cd25f1e1bb7..0000000000000 --- a/plugins/inputs/leofs/leofs_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package leofs - -func (l *LeoFS) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/inputs/linux_sysctl_fs/README.md b/plugins/inputs/linux_sysctl_fs/README.md index a5a03037f6555..1fbf6e9fb4772 100644 --- a/plugins/inputs/linux_sysctl_fs/README.md +++ b/plugins/inputs/linux_sysctl_fs/README.md @@ -10,7 +10,7 @@ Example output: ## Configuration -```toml +```toml @sample.conf # Provides Linux sysctl fs metrics [[inputs.linux_sysctl_fs]] # no configuration diff --git a/plugins/inputs/linux_sysctl_fs/linux_sysctl_fs.go b/plugins/inputs/linux_sysctl_fs/linux_sysctl_fs.go index 61fa3709bec76..26891d8e411ce 100644 --- a/plugins/inputs/linux_sysctl_fs/linux_sysctl_fs.go +++ b/plugins/inputs/linux_sysctl_fs/linux_sysctl_fs.go @@ -1,17 +1,22 @@ +//go:generate ../../../tools/readme_config_includer/generator package linux_sysctl_fs import ( "bytes" + _ "embed" "errors" "os" - "strconv" - "path" + "strconv" "github.com/influxdata/telegraf" "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 + // https://www.kernel.org/doc/Documentation/sysctl/fs.txt type SysctlFS struct { path string @@ -68,6 +73,10 @@ func (sfs *SysctlFS) gatherOne(name string, fields map[string]interface{}) error return nil } +func (*SysctlFS) SampleConfig() string { + return sampleConfig +} + func (sfs *SysctlFS) Gather(acc telegraf.Accumulator) error { fields := map[string]interface{}{} diff --git a/plugins/inputs/linux_sysctl_fs/linux_sysctl_fs_sample_config.go b/plugins/inputs/linux_sysctl_fs/linux_sysctl_fs_sample_config.go deleted file mode 100644 index a232cf5576ba1..0000000000000 --- a/plugins/inputs/linux_sysctl_fs/linux_sysctl_fs_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package linux_sysctl_fs - -func (sfs SysctlFS) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/inputs/logparser/README.md b/plugins/inputs/logparser/README.md index 3fd2f1de8089d..f8b8125707842 100644 --- a/plugins/inputs/logparser/README.md +++ b/plugins/inputs/logparser/README.md @@ -47,7 +47,7 @@ Migration Example: ## Configuration -```toml +```toml @sample.conf ## DEPRECATED: The 'logparser' plugin is deprecated in version 1.15.0, use 'inputs.tail' with 'grok' data format instead. # Read metrics off Arista LANZ, via socket [[inputs.logparser]] diff --git a/plugins/inputs/logparser/logparser.go b/plugins/inputs/logparser/logparser.go index 5c21659e9c7f6..bbcae9e3565e2 100644 --- a/plugins/inputs/logparser/logparser.go +++ b/plugins/inputs/logparser/logparser.go @@ -1,14 +1,17 @@ +//go:generate ../../../tools/readme_config_includer/generator //go:build !solaris // +build !solaris package logparser import ( + _ "embed" "fmt" "strings" "sync" "github.com/influxdata/tail" + "github.com/influxdata/telegraf" "github.com/influxdata/telegraf/internal/globpath" "github.com/influxdata/telegraf/models" @@ -16,6 +19,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 ( defaultWatchMethod = "inotify" ) @@ -76,6 +83,10 @@ func NewLogParser() *LogParserPlugin { } } +func (*LogParserPlugin) SampleConfig() string { + return sampleConfig +} + func (l *LogParserPlugin) Init() error { l.Log.Warnf(`The logparser plugin is deprecated; please use the 'tail' input with the 'grok' data_format`) return nil diff --git a/plugins/inputs/logparser/logparser_sample_config.go b/plugins/inputs/logparser/logparser_sample_config.go deleted file mode 100644 index aa052b8983a69..0000000000000 --- a/plugins/inputs/logparser/logparser_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package logparser - -func (l *LogParserPlugin) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/inputs/logstash/README.md b/plugins/inputs/logstash/README.md index d582262d86c69..1f09eb830dd75 100644 --- a/plugins/inputs/logstash/README.md +++ b/plugins/inputs/logstash/README.md @@ -7,7 +7,7 @@ Logstash 5 and later is supported. ## Configuration -```toml +```toml @sample.conf # Read metrics exposed by Logstash [[inputs.logstash]] ## The URL of the exposed Logstash API endpoint. diff --git a/plugins/inputs/logstash/logstash.go b/plugins/inputs/logstash/logstash.go index a8508f5a40e4a..634861e8efe13 100644 --- a/plugins/inputs/logstash/logstash.go +++ b/plugins/inputs/logstash/logstash.go @@ -1,6 +1,8 @@ +//go:generate ../../../tools/readme_config_includer/generator package logstash import ( + _ "embed" "encoding/json" "fmt" "io" @@ -17,6 +19,10 @@ import ( jsonParser "github.com/influxdata/telegraf/plugins/parsers/json" ) +// DO NOT REMOVE THE NEXT TWO LINES! This is required to embedd the sampleConfig data. +//go:embed sample.conf +var sampleConfig string + type Logstash struct { URL string `toml:"url"` @@ -111,6 +117,10 @@ const processStats = "/_node/stats/process" const pipelinesStats = "/_node/stats/pipelines" const pipelineStats = "/_node/stats/pipeline" +func (*Logstash) SampleConfig() string { + return sampleConfig +} + func (logstash *Logstash) Init() error { err := choice.CheckSlice(logstash.Collect, []string{"pipelines", "process", "jvm"}) if err != nil { diff --git a/plugins/inputs/logstash/logstash_sample_config.go b/plugins/inputs/logstash/logstash_sample_config.go deleted file mode 100644 index c9c62e6d0340c..0000000000000 --- a/plugins/inputs/logstash/logstash_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package logstash - -func (logstash *Logstash) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/inputs/lustre2/README.md b/plugins/inputs/lustre2/README.md index 0142c0cf5a8bf..8d2e562c3a762 100644 --- a/plugins/inputs/lustre2/README.md +++ b/plugins/inputs/lustre2/README.md @@ -7,7 +7,7 @@ This plugin monitors the Lustre file system using its entries in the proc filesy ## Configuration -```toml +```toml @sample.conf # Read metrics from local Lustre service on OST, MDS [[inputs.lustre2]] ## An array of /proc globs to search for Lustre stats diff --git a/plugins/inputs/lustre2/lustre2.go b/plugins/inputs/lustre2/lustre2.go index 73762be8db667..143d865497fb9 100644 --- a/plugins/inputs/lustre2/lustre2.go +++ b/plugins/inputs/lustre2/lustre2.go @@ -1,3 +1,4 @@ +//go:generate ../../../tools/readme_config_includer/generator //go:build !windows // +build !windows @@ -8,6 +9,7 @@ package lustre2 import ( + _ "embed" "os" "path/filepath" "regexp" @@ -18,6 +20,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 tags struct { name, job, client string } @@ -341,6 +347,10 @@ var wantedMdtJobstatsFields = []*mapping{ }, } +func (*Lustre2) SampleConfig() string { + return sampleConfig +} + func (l *Lustre2) GetLustreProcStats(fileglob string, wantedFields []*mapping) error { files, err := filepath.Glob(fileglob) if err != nil { diff --git a/plugins/inputs/lustre2/lustre2_sample_config.go b/plugins/inputs/lustre2/lustre2_sample_config.go deleted file mode 100644 index 2e1a031f16fd9..0000000000000 --- a/plugins/inputs/lustre2/lustre2_sample_config.go +++ /dev/null @@ -1,11 +0,0 @@ -//go:build !windows -// +build !windows - -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package lustre2 - -func (l *Lustre2) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/inputs/lvm/README.md b/plugins/inputs/lvm/README.md index 40f37500b68ed..f0267077676e3 100644 --- a/plugins/inputs/lvm/README.md +++ b/plugins/inputs/lvm/README.md @@ -8,7 +8,7 @@ physical volumes, volume groups, and logical volumes. The `lvm` command requires elevated permissions. If the user has configured sudo with the ability to run these commands, then set the `use_sudo` to true. -```toml +```toml @sample.conf # Read metrics about LVM physical volumes, volume groups, logical volumes. [[inputs.lvm]] ## Use sudo to run LVM commands diff --git a/plugins/inputs/lvm/lvm.go b/plugins/inputs/lvm/lvm.go index 8ae6526b8645d..5afccfb9b8c23 100644 --- a/plugins/inputs/lvm/lvm.go +++ b/plugins/inputs/lvm/lvm.go @@ -1,6 +1,8 @@ +//go:generate ../../../tools/readme_config_includer/generator package lvm import ( + _ "embed" "encoding/json" "fmt" "os/exec" @@ -13,6 +15,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 + var ( execCommand = exec.Command ) @@ -21,6 +27,10 @@ type LVM struct { UseSudo bool `toml:"use_sudo"` } +func (*LVM) SampleConfig() string { + return sampleConfig +} + func (lvm *LVM) Init() error { return nil } diff --git a/plugins/inputs/lvm/lvm_sample_config.go b/plugins/inputs/lvm/lvm_sample_config.go deleted file mode 100644 index a7caf7252ea67..0000000000000 --- a/plugins/inputs/lvm/lvm_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package lvm - -func (lvm *LVM) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/inputs/mailchimp/README.md b/plugins/inputs/mailchimp/README.md index fe9d403264a22..9086898d69538 100644 --- a/plugins/inputs/mailchimp/README.md +++ b/plugins/inputs/mailchimp/README.md @@ -7,7 +7,7 @@ Pulls campaign reports from the [Mailchimp API](https://developer.mailchimp.com/ This section contains the default TOML to configure the plugin. You can generate it using `telegraf --usage mailchimp`. -```toml +```toml @sample.conf # Gathers metrics from the /3.0/reports MailChimp API [[inputs.mailchimp]] ## MailChimp API key diff --git a/plugins/inputs/mailchimp/mailchimp.go b/plugins/inputs/mailchimp/mailchimp.go index 3a4cf04beb4c8..0c4d4be91a710 100644 --- a/plugins/inputs/mailchimp/mailchimp.go +++ b/plugins/inputs/mailchimp/mailchimp.go @@ -1,6 +1,8 @@ +//go:generate ../../../tools/readme_config_includer/generator package mailchimp import ( + _ "embed" "fmt" "time" @@ -8,6 +10,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 MailChimp struct { api *ChimpAPI @@ -18,6 +24,10 @@ type MailChimp struct { Log telegraf.Logger `toml:"-"` } +func (*MailChimp) SampleConfig() string { + return sampleConfig +} + func (m *MailChimp) Init() error { m.api = NewChimpAPI(m.APIKey, m.Log) diff --git a/plugins/inputs/mailchimp/mailchimp_sample_config.go b/plugins/inputs/mailchimp/mailchimp_sample_config.go deleted file mode 100644 index 71dc385337adf..0000000000000 --- a/plugins/inputs/mailchimp/mailchimp_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package mailchimp - -func (m *MailChimp) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/inputs/marklogic/README.md b/plugins/inputs/marklogic/README.md index 539cb531b3a1f..50260f7c43ce8 100644 --- a/plugins/inputs/marklogic/README.md +++ b/plugins/inputs/marklogic/README.md @@ -4,7 +4,7 @@ The MarkLogic Telegraf plugin gathers health status metrics from one or more hos ## Configuration -```toml +```toml @sample.conf # Retrieves information on a specific host in a MarkLogic Cluster [[inputs.marklogic]] ## Base URL of the MarkLogic HTTP Server. diff --git a/plugins/inputs/marklogic/marklogic.go b/plugins/inputs/marklogic/marklogic.go index b4b2078e6eda5..b07155ff0f71a 100644 --- a/plugins/inputs/marklogic/marklogic.go +++ b/plugins/inputs/marklogic/marklogic.go @@ -1,6 +1,8 @@ +//go:generate ../../../tools/readme_config_includer/generator package marklogic import ( + _ "embed" "encoding/json" "fmt" "net/http" @@ -14,6 +16,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 + // Marklogic configuration toml type Marklogic struct { URL string `toml:"url"` @@ -82,6 +88,10 @@ type MlHost struct { } `json:"host-status"` } +func (*Marklogic) SampleConfig() string { + return sampleConfig +} + // Init parse all source URLs and place on the Marklogic struct func (c *Marklogic) Init() error { if len(c.URL) == 0 { diff --git a/plugins/inputs/marklogic/marklogic_sample_config.go b/plugins/inputs/marklogic/marklogic_sample_config.go deleted file mode 100644 index 0616e75368120..0000000000000 --- a/plugins/inputs/marklogic/marklogic_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package marklogic - -func (c *Marklogic) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/inputs/mcrouter/README.md b/plugins/inputs/mcrouter/README.md index a657ef125a6de..147935b2c4d34 100644 --- a/plugins/inputs/mcrouter/README.md +++ b/plugins/inputs/mcrouter/README.md @@ -4,7 +4,7 @@ This plugin gathers statistics data from a Mcrouter server. ## Configuration -```toml +```toml @sample.conf # Read metrics from one or many mcrouter servers. [[inputs.mcrouter]] ## An array of address to gather stats about. Specify an ip or hostname diff --git a/plugins/inputs/mcrouter/mcrouter.go b/plugins/inputs/mcrouter/mcrouter.go index 8867081f9bf29..71c40891626be 100644 --- a/plugins/inputs/mcrouter/mcrouter.go +++ b/plugins/inputs/mcrouter/mcrouter.go @@ -1,8 +1,10 @@ +//go:generate ../../../tools/readme_config_includer/generator package mcrouter import ( "bufio" "context" + _ "embed" "fmt" "net" "net/url" @@ -15,6 +17,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 + // Mcrouter is a mcrouter plugin type Mcrouter struct { Servers []string @@ -104,6 +110,10 @@ var sendMetrics = map[string]statType{ "cmd_lease_set_out_all": typeInt, } +func (*Mcrouter) SampleConfig() string { + return sampleConfig +} + // Gather reads stats from all configured servers accumulates stats func (m *Mcrouter) Gather(acc telegraf.Accumulator) error { ctx := context.Background() diff --git a/plugins/inputs/mcrouter/mcrouter_sample_config.go b/plugins/inputs/mcrouter/mcrouter_sample_config.go deleted file mode 100644 index 3b3a1fc1a35e5..0000000000000 --- a/plugins/inputs/mcrouter/mcrouter_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package mcrouter - -func (m *Mcrouter) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/inputs/mdstat/README.md b/plugins/inputs/mdstat/README.md index 462ac89ca5507..4bdcf349e0bdd 100644 --- a/plugins/inputs/mdstat/README.md +++ b/plugins/inputs/mdstat/README.md @@ -10,7 +10,7 @@ Stat collection based on Prometheus' mdstat collection library at INT64, etc). - ## measurement *1 - (optional) measurement name, defaults to the setting of the request - ## omit - (optional) omit this field. Useful to leave out single values when querying many registers - ## with a single request. Defaults to "false". - ## - ## *1: Those fields are ignored if field is omitted ("omit"=true) - ## - ## *2: Thise fields are ignored for both "coil" and "discrete"-input type of registers. For those register types - ## the fields are output as zero or one in UINT64 format by default. - - ## Coil / discrete input example - # fields = [ - # { address=0, name="motor1_run"}, - # { address=1, name="jog", measurement="motor"}, - # { address=2, name="motor1_stop", omit=true}, - # { address=3, name="motor1_overheating"}, - # ] - - ## Per-request tags - ## These tags take precedence over predefined tags. - # [[inputs.modbus.request.tags]] - # name = "value" - - ## Holding / input example - ## All of those examples will result in FLOAT64 field outputs - # fields = [ - # { address=0, name="voltage", type="INT16", scale=0.1 }, - # { address=1, name="current", type="INT32", scale=0.001 }, - # { address=3, name="power", type="UINT32", omit=true }, - # { address=5, name="energy", type="FLOAT32", scale=0.001, measurement="W" }, - # { address=7, name="frequency", type="UINT32", scale=0.1 }, - # { address=8, name="power_factor", type="INT64", scale=0.01 }, - # ] - - ## Holding / input example with type conversions - # fields = [ - # { address=0, name="rpm", type="INT16" }, # will result in INT64 field - # { address=1, name="temperature", type="INT16", scale=0.1 }, # will result in FLOAT64 field - # { address=2, name="force", type="INT32", output="FLOAT64" }, # will result in FLOAT64 field - # { address=4, name="hours", type="UINT32" }, # will result in UIN64 field - # ] - - ## Per-request tags - ## These tags take precedence over predefined tags. - # [[inputs.modbus.request.tags]] - # name = "value" -` +// DO NOT REMOVE THE NEXT TWO LINES! This is required to embedd the sampleConfig data. +//go:embed sample_request.conf +var sampleConfigPartPerRequest string type requestFieldDefinition struct { Address uint16 `toml:"address"` diff --git a/plugins/inputs/modbus/modbus.go b/plugins/inputs/modbus/modbus.go index d844b2ad858a4..977b2f592058c 100644 --- a/plugins/inputs/modbus/modbus.go +++ b/plugins/inputs/modbus/modbus.go @@ -1,6 +1,8 @@ +//go:generate ../../../tools/readme_config_includer/generator package modbus import ( + _ "embed" "fmt" "net" "net/url" @@ -15,6 +17,14 @@ 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_general_begin.conf +var sampleConfigStart string + +// DO NOT REMOVE THE NEXT TWO LINES! This is required to embedd the sampleConfig data. +//go:embed sample_general_end.conf +var sampleConfigEnd string + type ModbusWorkarounds struct { PollPause config.Duration `toml:"pause_between_requests"` CloseAfterGather bool `toml:"close_connection_after_gather"` @@ -74,6 +84,22 @@ const ( cInputRegisters = "input_register" ) +// SampleConfig returns a basic configuration for the plugin +func (m *Modbus) SampleConfig() string { + configs := []Configuration{} + cfgOriginal := m.ConfigurationOriginal + cfgPerRequest := m.ConfigurationPerRequest + configs = append(configs, &cfgOriginal, &cfgPerRequest) + + totalConfig := sampleConfigStart + for _, c := range configs { + totalConfig += c.SampleConfigPart() + "\n" + } + totalConfig += "\n" + totalConfig += sampleConfigEnd + return totalConfig +} + func (m *Modbus) Init() error { //check device name if m.Name == "" { diff --git a/plugins/inputs/modbus/modbus_sample_config.go b/plugins/inputs/modbus/modbus_sample_config.go deleted file mode 100644 index a29d296a5c1c4..0000000000000 --- a/plugins/inputs/modbus/modbus_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package modbus - -func (m *Modbus) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/inputs/modbus/sample_general_begin.conf b/plugins/inputs/modbus/sample_general_begin.conf new file mode 100644 index 0000000000000..b3c5e677e22b2 --- /dev/null +++ b/plugins/inputs/modbus/sample_general_begin.conf @@ -0,0 +1,46 @@ +# Retrieve data from MODBUS slave devices +[[inputs.modbus]] + ## Connection Configuration + ## + ## The plugin supports connections to PLCs via MODBUS/TCP, RTU over TCP, ASCII over TCP or + ## via serial line communication in binary (RTU) or readable (ASCII) encoding + ## + ## Device name + name = "Device" + + ## Slave ID - addresses a MODBUS device on the bus + ## Range: 0 - 255 [0 = broadcast; 248 - 255 = reserved] + slave_id = 1 + + ## Timeout for each request + timeout = "1s" + + ## Maximum number of retries and the time to wait between retries + ## when a slave-device is busy. + # busy_retries = 0 + # busy_retries_wait = "100ms" + + # TCP - connect via Modbus/TCP + controller = "tcp://localhost:502" + + ## Serial (RS485; RS232) + # controller = "file:///dev/ttyUSB0" + # baud_rate = 9600 + # data_bits = 8 + # parity = "N" + # stop_bits = 1 + + ## For Modbus over TCP you can choose between "TCP", "RTUoverTCP" and "ASCIIoverTCP" + ## default behaviour is "TCP" if the controller is TCP + ## For Serial you can choose between "RTU" and "ASCII" + # transmission_mode = "RTU" + + ## Trace the connection to the modbus device as debug messages + ## Note: You have to enable telegraf's debug mode to see those messages! + # debug_connection = false + + ## Define the configuration schema + ## |---register -- define fields per register type in the original style (only supports one slave ID) + ## |---request -- define fields on a requests base + configuration_type = "register" + diff --git a/plugins/inputs/modbus/sample_general_end.conf b/plugins/inputs/modbus/sample_general_end.conf new file mode 100644 index 0000000000000..f6245caed9473 --- /dev/null +++ b/plugins/inputs/modbus/sample_general_end.conf @@ -0,0 +1,8 @@ + ## Enable workarounds required by some devices to work correctly + # [inputs.modbus.workarounds] + ## Pause between read requests sent to the device. This might be necessary for (slow) serial devices. + # pause_between_requests = "0ms" + ## Close the connection after every gather cycle. Usually the plugin closes the connection after a certain + ## idle-timeout, however, if you query a device with limited simultaneous connectivity (e.g. serial devices) + ## from multiple instances you might want to only stay connected during gather and disconnect afterwards. + # close_connection_after_gather = false diff --git a/plugins/inputs/modbus/sample_register.conf b/plugins/inputs/modbus/sample_register.conf new file mode 100644 index 0000000000000..ebfaf636d1e0a --- /dev/null +++ b/plugins/inputs/modbus/sample_register.conf @@ -0,0 +1,50 @@ + ## --- "register" configuration style --- + + ## Measurements + ## + + ## Digital Variables, Discrete Inputs and Coils + ## measurement - the (optional) measurement name, defaults to "modbus" + ## name - the variable name + ## address - variable address + + discrete_inputs = [ + { name = "start", address = [0]}, + { name = "stop", address = [1]}, + { name = "reset", address = [2]}, + { name = "emergency_stop", address = [3]}, + ] + coils = [ + { name = "motor1_run", address = [0]}, + { name = "motor1_jog", address = [1]}, + { name = "motor1_stop", address = [2]}, + ] + + ## Analog Variables, Input Registers and Holding Registers + ## measurement - the (optional) measurement name, defaults to "modbus" + ## name - the variable name + ## byte_order - the ordering of bytes + ## |---AB, ABCD - Big Endian + ## |---BA, DCBA - Little Endian + ## |---BADC - Mid-Big Endian + ## |---CDAB - Mid-Little Endian + ## data_type - INT16, UINT16, INT32, UINT32, INT64, UINT64, + ## FLOAT32-IEEE, FLOAT64-IEEE (the IEEE 754 binary representation) + ## FLOAT32, FIXED, UFIXED (fixed-point representation on input) + ## scale - the final numeric variable representation + ## address - variable address + + holding_registers = [ + { name = "power_factor", byte_order = "AB", data_type = "FIXED", scale=0.01, address = [8]}, + { name = "voltage", byte_order = "AB", data_type = "FIXED", scale=0.1, address = [0]}, + { name = "energy", byte_order = "ABCD", data_type = "FIXED", scale=0.001, address = [5,6]}, + { name = "current", byte_order = "ABCD", data_type = "FIXED", scale=0.001, address = [1,2]}, + { name = "frequency", byte_order = "AB", data_type = "UFIXED", scale=0.1, address = [7]}, + { name = "power", byte_order = "ABCD", data_type = "UFIXED", scale=0.1, address = [3,4]}, + ] + input_registers = [ + { name = "tank_level", byte_order = "AB", data_type = "INT16", scale=1.0, address = [0]}, + { name = "tank_ph", byte_order = "AB", data_type = "INT16", scale=1.0, address = [1]}, + { name = "pump1_speed", byte_order = "ABCD", data_type = "INT32", scale=1.0, address = [3,4]}, + ] + diff --git a/plugins/inputs/modbus/sample_request.conf b/plugins/inputs/modbus/sample_request.conf new file mode 100644 index 0000000000000..717b04e2de22e --- /dev/null +++ b/plugins/inputs/modbus/sample_request.conf @@ -0,0 +1,92 @@ + ## --- "request" configuration style --- + + ## Per request definition + ## + + ## Define a request sent to the device + ## Multiple of those requests can be defined. Data will be collated into metrics at the end of data collection. + [[inputs.modbus.request]] + ## ID of the modbus slave device to query. + ## If you need to query multiple slave-devices, create several "request" definitions. + slave_id = 1 + + ## Byte order of the data. + ## |---ABCD -- Big Endian (Motorola) + ## |---DCBA -- Little Endian (Intel) + ## |---BADC -- Big Endian with byte swap + ## |---CDAB -- Little Endian with byte swap + byte_order = "ABCD" + + ## Type of the register for the request + ## Can be "coil", "discrete", "holding" or "input" + register = "coil" + + ## Name of the measurement. + ## Can be overriden by the individual field definitions. Defaults to "modbus" + # measurement = "modbus" + + ## Field definitions + ## Analog Variables, Input Registers and Holding Registers + ## address - address of the register to query. For coil and discrete inputs this is the bit address. + ## name *1 - field name + ## type *1,2 - type of the modbus field, can be INT16, UINT16, INT32, UINT32, INT64, UINT64 and + ## FLOAT32, FLOAT64 (IEEE 754 binary representation) + ## scale *1,2 - (optional) factor to scale the variable with + ## output *1,2 - (optional) type of resulting field, can be INT64, UINT64 or FLOAT64. Defaults to FLOAT64 if + ## "scale" is provided and to the input "type" class otherwise (i.e. INT* -> INT64, etc). + ## measurement *1 - (optional) measurement name, defaults to the setting of the request + ## omit - (optional) omit this field. Useful to leave out single values when querying many registers + ## with a single request. Defaults to "false". + ## + ## *1: Those fields are ignored if field is omitted ("omit"=true) + ## + ## *2: Thise fields are ignored for both "coil" and "discrete"-input type of registers. For those register types + ## the fields are output as zero or one in UINT64 format by default. + + ## Coil / discrete input example + fields = [ + { address=0, name="motor1_run"}, + { address=1, name="jog", measurement="motor"}, + { address=2, name="motor1_stop", omit=true}, + { address=3, name="motor1_overheating"}, + ] + + [[inputs.modbus.request.tags]] + machine = "impresser" + location = "main building" + + [[inputs.modbus.request]] + ## Holding example + ## All of those examples will result in FLOAT64 field outputs + slave_id = 1 + byte_order = "DCBA" + register = "holding" + fields = [ + { address=0, name="voltage", type="INT16", scale=0.1 }, + { address=1, name="current", type="INT32", scale=0.001 }, + { address=3, name="power", type="UINT32", omit=true }, + { address=5, name="energy", type="FLOAT32", scale=0.001, measurement="W" }, + { address=7, name="frequency", type="UINT32", scale=0.1 }, + { address=8, name="power_factor", type="INT64", scale=0.01 }, + ] + + [[inputs.modbus.request.tags]] + machine = "impresser" + location = "main building" + + [[inputs.modbus.request]] + ## Input example with type conversions + slave_id = 1 + byte_order = "ABCD" + register = "input" + fields = [ + { address=0, name="rpm", type="INT16" }, # will result in INT64 field + { address=1, name="temperature", type="INT16", scale=0.1 }, # will result in FLOAT64 field + { address=2, name="force", type="INT32", output="FLOAT64" }, # will result in FLOAT64 field + { address=4, name="hours", type="UINT32" }, # will result in UIN64 field + ] + + [[inputs.modbus.request.tags]] + machine = "impresser" + location = "main building" + diff --git a/plugins/inputs/mongodb/README.md b/plugins/inputs/mongodb/README.md index 64aa2a73f2e14..8715ec1edb8cb 100644 --- a/plugins/inputs/mongodb/README.md +++ b/plugins/inputs/mongodb/README.md @@ -4,7 +4,7 @@ All MongoDB server versions from 2.6 and higher are supported. ## Configuration -```toml +```toml @sample.conf # Read metrics from one or many MongoDB servers [[inputs.mongodb]] ## An array of URLs of the form: diff --git a/plugins/inputs/mongodb/mongodb.go b/plugins/inputs/mongodb/mongodb.go index 94633434687b4..8086f649200d1 100644 --- a/plugins/inputs/mongodb/mongodb.go +++ b/plugins/inputs/mongodb/mongodb.go @@ -1,23 +1,30 @@ +//go:generate ../../../tools/readme_config_includer/generator package mongodb import ( "context" "crypto/tls" "crypto/x509" + _ "embed" "fmt" "net/url" "strings" "sync" "time" - "github.com/influxdata/telegraf" - tlsint "github.com/influxdata/telegraf/plugins/common/tls" - "github.com/influxdata/telegraf/plugins/inputs" "go.mongodb.org/mongo-driver/mongo" "go.mongodb.org/mongo-driver/mongo/options" "go.mongodb.org/mongo-driver/mongo/readpref" + + "github.com/influxdata/telegraf" + tlsint "github.com/influxdata/telegraf/plugins/common/tls" + "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 MongoDB struct { Servers []string Ssl Ssl @@ -38,6 +45,10 @@ type Ssl struct { CaCerts []string `toml:"cacerts" deprecated:"1.3.0;use 'tls_ca' instead"` } +func (*MongoDB) SampleConfig() string { + return sampleConfig +} + func (m *MongoDB) Init() error { var tlsConfig *tls.Config if m.Ssl.Enabled { diff --git a/plugins/inputs/mongodb/mongodb_sample_config.go b/plugins/inputs/mongodb/mongodb_sample_config.go deleted file mode 100644 index fd8ac219f2686..0000000000000 --- a/plugins/inputs/mongodb/mongodb_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package mongodb - -func (m *MongoDB) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/inputs/monit/README.md b/plugins/inputs/monit/README.md index f166252e0faea..ddb7ba4e1488e 100644 --- a/plugins/inputs/monit/README.md +++ b/plugins/inputs/monit/README.md @@ -14,7 +14,7 @@ Minimum Version of Monit tested with is 5.16. ## Configuration -```toml +```toml @sample.conf # Read metrics and status information about processes managed by Monit [[inputs.monit]] ## Monit HTTPD address diff --git a/plugins/inputs/monit/monit.go b/plugins/inputs/monit/monit.go index 066df699249a6..c6b36c684fed9 100644 --- a/plugins/inputs/monit/monit.go +++ b/plugins/inputs/monit/monit.go @@ -1,6 +1,8 @@ +//go:generate ../../../tools/readme_config_includer/generator package monit import ( + _ "embed" "encoding/xml" "fmt" "net/http" @@ -14,6 +16,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 + const ( fileSystem = "0" directory = "1" @@ -187,6 +193,10 @@ type Messagebody struct { Metrics []string `json:"metrics"` } +func (*Monit) SampleConfig() string { + return sampleConfig +} + func (m *Monit) Init() error { tlsCfg, err := m.ClientConfig.TLSConfig() if err != nil { diff --git a/plugins/inputs/monit/monit_sample_config.go b/plugins/inputs/monit/monit_sample_config.go deleted file mode 100644 index 9a3e28305fe37..0000000000000 --- a/plugins/inputs/monit/monit_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package monit - -func (m *Monit) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/inputs/mqtt_consumer/README.md b/plugins/inputs/mqtt_consumer/README.md index 350ec5c468a58..e4742088b5152 100644 --- a/plugins/inputs/mqtt_consumer/README.md +++ b/plugins/inputs/mqtt_consumer/README.md @@ -5,7 +5,7 @@ and creates metrics using one of the supported [input data formats][]. ## Configuration -```toml +```toml @sample.conf # Read metrics from MQTT topic(s) [[inputs.mqtt_consumer]] ## Broker URLs for the MQTT server or cluster. To connect to multiple diff --git a/plugins/inputs/mqtt_consumer/mqtt_consumer.go b/plugins/inputs/mqtt_consumer/mqtt_consumer.go index 27b46d23ce753..a0d4867dd1d06 100644 --- a/plugins/inputs/mqtt_consumer/mqtt_consumer.go +++ b/plugins/inputs/mqtt_consumer/mqtt_consumer.go @@ -1,7 +1,9 @@ +//go:generate ../../../tools/readme_config_includer/generator package mqtt_consumer import ( "context" + _ "embed" "errors" "fmt" "strconv" @@ -10,6 +12,7 @@ import ( "time" mqtt "github.com/eclipse/paho.mqtt.golang" + "github.com/influxdata/telegraf" "github.com/influxdata/telegraf/config" "github.com/influxdata/telegraf/internal" @@ -18,6 +21,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 + var ( // 30 Seconds is the default used by paho.mqtt.golang defaultConnectionTimeout = config.Duration(30 * time.Second) @@ -85,6 +92,10 @@ type MQTTConsumer struct { cancel context.CancelFunc } +func (*MQTTConsumer) SampleConfig() string { + return sampleConfig +} + func (m *MQTTConsumer) SetParser(parser parsers.Parser) { m.parser = parser } diff --git a/plugins/inputs/mqtt_consumer/mqtt_consumer_sample_config.go b/plugins/inputs/mqtt_consumer/mqtt_consumer_sample_config.go deleted file mode 100644 index 2509c01bcffcf..0000000000000 --- a/plugins/inputs/mqtt_consumer/mqtt_consumer_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package mqtt_consumer - -func (m *MQTTConsumer) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/inputs/multifile/README.md b/plugins/inputs/multifile/README.md index 3df7b32cb4fd3..23ce116abcde2 100644 --- a/plugins/inputs/multifile/README.md +++ b/plugins/inputs/multifile/README.md @@ -9,7 +9,7 @@ useful creating custom metrics from the `/sys` or `/proc` filesystems. ## Configuration -```toml +```toml @sample.conf # Aggregates the contents of multiple files into a single point [[inputs.multifile]] ## Base directory where telegraf will look for files. diff --git a/plugins/inputs/multifile/multifile.go b/plugins/inputs/multifile/multifile.go index fd2f2fa3e2e16..c4026f8e91e6d 100644 --- a/plugins/inputs/multifile/multifile.go +++ b/plugins/inputs/multifile/multifile.go @@ -1,7 +1,9 @@ +//go:generate ../../../tools/readme_config_includer/generator package multifile import ( "bytes" + _ "embed" "fmt" "math" "os" @@ -13,12 +15,14 @@ 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 MultiFile struct { BaseDir string FailEarly bool Files []File `toml:"file"` - - initialized bool } type File struct { @@ -27,11 +31,11 @@ type File struct { Conversion string } -func (m *MultiFile) init() { - if m.initialized { - return - } +func (*MultiFile) SampleConfig() string { + return sampleConfig +} +func (m *MultiFile) Init() error { for i, file := range m.Files { if m.BaseDir != "" { m.Files[i].Name = path.Join(m.BaseDir, file.Name) @@ -40,12 +44,10 @@ func (m *MultiFile) init() { m.Files[i].Dest = path.Base(file.Name) } } - - m.initialized = true + return nil } func (m *MultiFile) Gather(acc telegraf.Accumulator) error { - m.init() now := time.Now() fields := make(map[string]interface{}) tags := make(map[string]string) diff --git a/plugins/inputs/multifile/multifile_sample_config.go b/plugins/inputs/multifile/multifile_sample_config.go deleted file mode 100644 index ce2ae8009021f..0000000000000 --- a/plugins/inputs/multifile/multifile_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package multifile - -func (m *MultiFile) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/inputs/multifile/multifile_test.go b/plugins/inputs/multifile/multifile_test.go index 214cebd136f9c..13c9457b11f03 100644 --- a/plugins/inputs/multifile/multifile_test.go +++ b/plugins/inputs/multifile/multifile_test.go @@ -29,9 +29,8 @@ func TestFileTypes(t *testing.T) { var acc testutil.Accumulator - err := m.Gather(&acc) - - require.NoError(t, err) + require.NoError(t, m.Init()) + require.NoError(t, m.Gather(&acc)) require.Equal(t, map[string]string{"exampletag": "test"}, acc.Metrics[0].Tags) require.Equal(t, map[string]interface{}{ "examplebool": true, @@ -57,6 +56,7 @@ func FailEarly(failEarly bool, t *testing.T) error { var acc testutil.Accumulator + require.NoError(t, m.Init()) err := m.Gather(&acc) if err == nil { diff --git a/plugins/inputs/mysql/README.md b/plugins/inputs/mysql/README.md index 3e1ed6b47fde6..54199f1706304 100644 --- a/plugins/inputs/mysql/README.md +++ b/plugins/inputs/mysql/README.md @@ -20,7 +20,7 @@ This plugin gathers the statistic data from MySQL server ## Configuration -```toml +```toml @sample.conf # Read metrics from one or many mysql servers [[inputs.mysql]] ## specify servers via a url matching: diff --git a/plugins/inputs/mysql/mysql.go b/plugins/inputs/mysql/mysql.go index 41bc76c813872..71b418931f57e 100644 --- a/plugins/inputs/mysql/mysql.go +++ b/plugins/inputs/mysql/mysql.go @@ -1,7 +1,9 @@ +//go:generate ../../../tools/readme_config_includer/generator package mysql import ( "database/sql" + _ "embed" "fmt" "strconv" "strings" @@ -17,6 +19,10 @@ import ( v2 "github.com/influxdata/telegraf/plugins/inputs/mysql/v2" ) +// DO NOT REMOVE THE NEXT TWO LINES! This is required to embedd the sampleConfig data. +//go:embed sample.conf +var sampleConfig string + type Mysql struct { Servers []string `toml:"servers"` PerfEventsStatementsDigestTextLimit int64 `toml:"perf_events_statements_digest_text_limit"` @@ -61,6 +67,10 @@ const ( const localhost = "" +func (*Mysql) SampleConfig() string { + return sampleConfig +} + func (m *Mysql) InitMysql() { if len(m.IntervalSlow) > 0 { interval, err := time.ParseDuration(m.IntervalSlow) diff --git a/plugins/inputs/mysql/mysql_sample_config.go b/plugins/inputs/mysql/mysql_sample_config.go deleted file mode 100644 index 8551b8e38fa51..0000000000000 --- a/plugins/inputs/mysql/mysql_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package mysql - -func (m *Mysql) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/inputs/nats/README.md b/plugins/inputs/nats/README.md index 7ddbfe7be3717..58deef1320715 100644 --- a/plugins/inputs/nats/README.md +++ b/plugins/inputs/nats/README.md @@ -5,7 +5,7 @@ the NATS [monitoring http server](https://www.nats.io/documentation/server/gnats ## Configuration -```toml +```toml @sample.conf # Provides metrics about the state of a NATS server [[inputs.nats]] ## The address of the monitoring endpoint of the NATS server diff --git a/plugins/inputs/nats/nats.go b/plugins/inputs/nats/nats.go index 98914bb414ae7..f7dbdb516befd 100644 --- a/plugins/inputs/nats/nats.go +++ b/plugins/inputs/nats/nats.go @@ -1,9 +1,11 @@ +//go:generate ../../../tools/readme_config_includer/generator //go:build !freebsd || (freebsd && cgo) // +build !freebsd freebsd,cgo package nats import ( + _ "embed" "encoding/json" "io" "net/http" @@ -18,6 +20,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 Nats struct { Server string ResponseTimeout config.Duration @@ -25,6 +31,10 @@ type Nats struct { client *http.Client } +func (*Nats) SampleConfig() string { + return sampleConfig +} + func (n *Nats) Gather(acc telegraf.Accumulator) error { address, err := url.Parse(n.Server) if err != nil { diff --git a/plugins/inputs/nats/nats_sample_config.go b/plugins/inputs/nats/nats_sample_config.go deleted file mode 100644 index 09bf691139469..0000000000000 --- a/plugins/inputs/nats/nats_sample_config.go +++ /dev/null @@ -1,11 +0,0 @@ -//go:build !freebsd || (freebsd && cgo) -// +build !freebsd freebsd,cgo - -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package nats - -func (n *Nats) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/inputs/nats_consumer/README.md b/plugins/inputs/nats_consumer/README.md index aa73c0355e8bc..b3865dca74850 100644 --- a/plugins/inputs/nats_consumer/README.md +++ b/plugins/inputs/nats_consumer/README.md @@ -8,7 +8,7 @@ instances of telegraf can read from a NATS cluster in parallel. ## Configuration -```toml +```toml @sample.conf # Read metrics from NATS subject(s) [[inputs.nats_consumer]] ## urls of NATS servers diff --git a/plugins/inputs/nats_consumer/nats_consumer.go b/plugins/inputs/nats_consumer/nats_consumer.go index 715206fe4eefe..67a32cf95db59 100644 --- a/plugins/inputs/nats_consumer/nats_consumer.go +++ b/plugins/inputs/nats_consumer/nats_consumer.go @@ -1,18 +1,25 @@ +//go:generate ../../../tools/readme_config_includer/generator package nats_consumer import ( "context" + _ "embed" "fmt" "strings" "sync" + "github.com/nats-io/nats.go" + "github.com/influxdata/telegraf" "github.com/influxdata/telegraf/plugins/common/tls" "github.com/influxdata/telegraf/plugins/inputs" "github.com/influxdata/telegraf/plugins/parsers" - "github.com/nats-io/nats.go" ) +// DO NOT REMOVE THE NEXT TWO LINES! This is required to embedd the sampleConfig data. +//go:embed sample.conf +var sampleConfig string + var ( defaultMaxUndeliveredMessages = 1000 ) @@ -64,6 +71,10 @@ type natsConsumer struct { cancel context.CancelFunc } +func (*natsConsumer) SampleConfig() string { + return sampleConfig +} + func (n *natsConsumer) SetParser(parser parsers.Parser) { n.parser = parser } diff --git a/plugins/inputs/nats_consumer/nats_consumer_sample_config.go b/plugins/inputs/nats_consumer/nats_consumer_sample_config.go deleted file mode 100644 index baa02fdb27856..0000000000000 --- a/plugins/inputs/nats_consumer/nats_consumer_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package nats_consumer - -func (n *natsConsumer) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/inputs/neptune_apex/README.md b/plugins/inputs/neptune_apex/README.md index e43dbe084ec8b..5ded8abd18932 100644 --- a/plugins/inputs/neptune_apex/README.md +++ b/plugins/inputs/neptune_apex/README.md @@ -8,7 +8,7 @@ The [Neptune Apex](https://www.neptunesystems.com/) input plugin collects real-t ## Configuration -```toml +```toml @sample.conf # Neptune Apex data collector [[inputs.neptune_apex]] ## The Neptune Apex plugin reads the publicly available status.xml data from a local Apex. diff --git a/plugins/inputs/neptune_apex/neptune_apex.go b/plugins/inputs/neptune_apex/neptune_apex.go index 4a2003c045b2a..4c1c0bbb74ec6 100644 --- a/plugins/inputs/neptune_apex/neptune_apex.go +++ b/plugins/inputs/neptune_apex/neptune_apex.go @@ -1,8 +1,10 @@ +//go:generate ../../../tools/readme_config_includer/generator // Package neptune_apex implements an input plugin for the Neptune Apex // aquarium controller. package neptune_apex import ( + _ "embed" "encoding/xml" "fmt" "io" @@ -18,6 +20,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 + // Measurement is constant across all metrics. const Measurement = "neptune_apex" @@ -55,6 +61,10 @@ type NeptuneApex struct { httpClient *http.Client } +func (*NeptuneApex) SampleConfig() string { + return sampleConfig +} + // Gather implements telegraf.Input.Gather func (n *NeptuneApex) Gather(acc telegraf.Accumulator) error { var wg sync.WaitGroup diff --git a/plugins/inputs/neptune_apex/neptune_apex_sample_config.go b/plugins/inputs/neptune_apex/neptune_apex_sample_config.go deleted file mode 100644 index 809c69f6c8733..0000000000000 --- a/plugins/inputs/neptune_apex/neptune_apex_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package neptune_apex - -func (*NeptuneApex) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/inputs/net/README.md b/plugins/inputs/net/README.md index 243293b93532d..798861b253ec5 100644 --- a/plugins/inputs/net/README.md +++ b/plugins/inputs/net/README.md @@ -4,7 +4,7 @@ This plugin gathers metrics about network interface and protocol usage (Linux on ## Configuration -```toml +```toml @sample.conf # Gather metrics about network interfaces [[inputs.net]] ## By default, telegraf gathers stats from any up interface (excluding loopback) diff --git a/plugins/inputs/net/net.go b/plugins/inputs/net/net.go index 7403349f17a21..0615ae845c214 100644 --- a/plugins/inputs/net/net.go +++ b/plugins/inputs/net/net.go @@ -1,6 +1,8 @@ +//go:generate ../../../tools/readme_config_includer/generator package net import ( + _ "embed" "fmt" "net" "strings" @@ -11,6 +13,10 @@ import ( "github.com/influxdata/telegraf/plugins/inputs/system" ) +// DO NOT REMOVE THE NEXT TWO LINES! This is required to embedd the sampleConfig data. +//go:embed sample.conf +var sampleConfig string + type NetIOStats struct { filter filter.Filter ps system.PS @@ -20,6 +26,10 @@ type NetIOStats struct { Interfaces []string } +func (*NetIOStats) SampleConfig() string { + return sampleConfig +} + func (n *NetIOStats) Gather(acc telegraf.Accumulator) error { netio, err := n.ps.NetIO() if err != nil { diff --git a/plugins/inputs/net/net_sample_config.go b/plugins/inputs/net/net_sample_config.go deleted file mode 100644 index 04d2950d2de20..0000000000000 --- a/plugins/inputs/net/net_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package net - -func (n *NetIOStats) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/inputs/net_response/README.md b/plugins/inputs/net_response/README.md index e64a7ebf605cc..ffae42a3d54af 100644 --- a/plugins/inputs/net_response/README.md +++ b/plugins/inputs/net_response/README.md @@ -5,7 +5,7 @@ verify text in the response. ## Configuration -```toml +```toml @sample.conf # Collect response time of a TCP or UDP connection [[inputs.net_response]] ## Protocol, must be "tcp" or "udp" diff --git a/plugins/inputs/net_response/net_response.go b/plugins/inputs/net_response/net_response.go index 1e8b6cf393f8d..a768818cc4a0e 100644 --- a/plugins/inputs/net_response/net_response.go +++ b/plugins/inputs/net_response/net_response.go @@ -1,7 +1,9 @@ +//go:generate ../../../tools/readme_config_includer/generator package net_response import ( "bufio" + _ "embed" "errors" "net" "net/textproto" @@ -13,6 +15,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 ResultType uint64 const ( @@ -33,6 +39,10 @@ type NetResponse struct { Protocol string } +func (*NetResponse) SampleConfig() string { + return sampleConfig +} + // TCPGather will execute if there are TCP tests defined in the configuration. // It will return a map[string]interface{} for fields and a map[string]string for tags func (n *NetResponse) TCPGather() (map[string]string, map[string]interface{}, error) { diff --git a/plugins/inputs/net_response/net_response_sample_config.go b/plugins/inputs/net_response/net_response_sample_config.go deleted file mode 100644 index ad4c2a9c4665e..0000000000000 --- a/plugins/inputs/net_response/net_response_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package net_response - -func (*NetResponse) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/inputs/netstat/netstat.go b/plugins/inputs/netstat/netstat.go index a074e5c076754..20b83ba489870 100644 --- a/plugins/inputs/netstat/netstat.go +++ b/plugins/inputs/netstat/netstat.go @@ -1,6 +1,8 @@ +//go:generate ../../../tools/readme_config_includer/generator package netstat import ( + _ "embed" "fmt" "syscall" @@ -9,10 +11,18 @@ import ( "github.com/influxdata/telegraf/plugins/inputs/system" ) +// DO NOT REMOVE THE NEXT TWO LINES! This is required to embedd the sampleConfig data. +//go:embed sample.conf +var sampleConfig string + type NetStats struct { PS system.PS } +func (*NetStats) SampleConfig() string { + return sampleConfig +} + func (ns *NetStats) Gather(acc telegraf.Accumulator) error { netconns, err := ns.PS.NetConnections() if err != nil { diff --git a/plugins/inputs/netstat/netstat_sample_config.go b/plugins/inputs/netstat/netstat_sample_config.go deleted file mode 100644 index 5b52405c1b4c7..0000000000000 --- a/plugins/inputs/netstat/netstat_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package netstat - -func (n *NetStats) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/inputs/nfsclient/README.md b/plugins/inputs/nfsclient/README.md index e5cca8bac56dd..ef631ccff1518 100644 --- a/plugins/inputs/nfsclient/README.md +++ b/plugins/inputs/nfsclient/README.md @@ -3,11 +3,11 @@ The NFS Client input plugin collects data from /proc/self/mountstats. By default, only a limited number of general system-level metrics are collected, including basic read/write counts. If `fullstat` is set, a great deal of additional metrics are collected, detailed below. -**NOTE** Many of the metrics, even if tagged with a mount point, are really _per-server_. Thus, if you mount these two shares: `nfs01:/vol/foo/bar` and `nfs01:/vol/foo/baz`, there will be two near identical entries in /proc/self/mountstats. This is a limitation of the metrics exposed by the kernel, not the telegraf plugin. +__NOTE__ Many of the metrics, even if tagged with a mount point, are really _per-server_. Thus, if you mount these two shares: `nfs01:/vol/foo/bar` and `nfs01:/vol/foo/baz`, there will be two near identical entries in /proc/self/mountstats. This is a limitation of the metrics exposed by the kernel, not the telegraf plugin. ## Configuration -```toml +```toml @sample.conf # Read per-mount NFS client metrics from /proc/self/mountstats [[inputs.nfsclient]] ## Read more low-level metrics (optional, defaults to false) @@ -39,13 +39,13 @@ If `fullstat` is set, a great deal of additional metrics are collected, detailed ### Configuration Options -- **fullstat** bool: Collect per-operation type metrics. Defaults to false. -- **include_mounts** list(string): gather metrics for only these mounts. Default is to watch all mounts. -- **exclude_mounts** list(string): gather metrics for all mounts, except those listed in this option. Excludes take precedence over includes. -- **include_operations** list(string): List of specific NFS operations to track. See /proc/self/mountstats (the "per-op statistics" section) for complete lists of valid options for NFSv3 and NFSV4. The default is to gather all metrics, but this is almost certainly *not* what you want (there are 22 operations for NFSv3, and well over 50 for NFSv4). A suggested 'minimal' list of operations to collect for basic usage: `['READ','WRITE','ACCESS','GETATTR','READDIR','LOOKUP','LOOKUP']` -- **exclude_operations** list(string): Gather all metrics, except those listed. Excludes take precedence over includes. +- __fullstat__ bool: Collect per-operation type metrics. Defaults to false. +- __include_mounts__ list(string): gather metrics for only these mounts. Default is to watch all mounts. +- __exclude_mounts__ list(string): gather metrics for all mounts, except those listed in this option. Excludes take precedence over includes. +- __include_operations__ list(string): List of specific NFS operations to track. See /proc/self/mountstats (the "per-op statistics" section) for complete lists of valid options for NFSv3 and NFSV4. The default is to gather all metrics, but this is almost certainly _not_ what you want (there are 22 operations for NFSv3, and well over 50 for NFSv4). A suggested 'minimal' list of operations to collect for basic usage: `['READ','WRITE','ACCESS','GETATTR','READDIR','LOOKUP','LOOKUP']` +- __exclude_operations__ list(string): Gather all metrics, except those listed. Excludes take precedence over includes. -*N.B.* the `include_mounts` and `exclude_mounts` arguments are both applied to the local mount location (e.g. /mnt/NFS), not the server export (e.g. nfsserver:/vol/NFS). Go regexp patterns can be used in either. +_N.B._ the `include_mounts` and `exclude_mounts` arguments are both applied to the local mount location (e.g. /mnt/NFS), not the server export (e.g. nfsserver:/vol/NFS). Go regexp patterns can be used in either. ### References @@ -59,7 +59,7 @@ If `fullstat` is set, a great deal of additional metrics are collected, detailed ### Fields - nfsstat - - bytes (integer, bytes) - The total number of bytes exchanged doing this operation. This is bytes sent *and* received, including overhead *and* payload. (bytes = OP_bytes_sent + OP_bytes_recv. See nfs_ops below) + - bytes (integer, bytes) - The total number of bytes exchanged doing this operation. This is bytes sent _and_ received, including overhead _and_ payload. (bytes = OP_bytes_sent + OP_bytes_recv. See nfs_ops below) - ops (integer, count) - The number of operations of this type executed. - retrans (integer, count) - The number of times an operation had to be retried (retrans = OP_trans - OP_ops. See nfs_ops below) - exe (integer, miliseconds) - The number of miliseconds it took to process the operations. diff --git a/plugins/inputs/nfsclient/nfsclient.go b/plugins/inputs/nfsclient/nfsclient.go index 5936e8b66ba4b..4e452711c438e 100644 --- a/plugins/inputs/nfsclient/nfsclient.go +++ b/plugins/inputs/nfsclient/nfsclient.go @@ -1,7 +1,9 @@ +//go:generate ../../../tools/readme_config_includer/generator package nfsclient import ( "bufio" + _ "embed" "fmt" "os" "regexp" @@ -13,6 +15,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 NFSClient struct { Fullstat bool `toml:"fullstat"` IncludeMounts []string `toml:"include_mounts"` @@ -285,6 +291,10 @@ func (n *NFSClient) getMountStatsPath() string { return path } +func (*NFSClient) SampleConfig() string { + return sampleConfig +} + func (n *NFSClient) Gather(acc telegraf.Accumulator) error { file, err := os.Open(n.mountstatsPath) if err != nil { diff --git a/plugins/inputs/nfsclient/nfsclient_sample_config.go b/plugins/inputs/nfsclient/nfsclient_sample_config.go deleted file mode 100644 index 4fd51e37de0a8..0000000000000 --- a/plugins/inputs/nfsclient/nfsclient_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package nfsclient - -func (n *NFSClient) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/inputs/nginx/README.md b/plugins/inputs/nginx/README.md index 4859aa74c96f9..685c20097f9b6 100644 --- a/plugins/inputs/nginx/README.md +++ b/plugins/inputs/nginx/README.md @@ -2,7 +2,7 @@ ## Configuration -```toml +```toml @sample.conf # Read Nginx's basic status information (ngx_http_stub_status_module) [[inputs.nginx]] ## An array of Nginx stub_status URI to gather stats. diff --git a/plugins/inputs/nginx/nginx.go b/plugins/inputs/nginx/nginx.go index ed3d2c22356fa..c89706c0e39a9 100644 --- a/plugins/inputs/nginx/nginx.go +++ b/plugins/inputs/nginx/nginx.go @@ -1,7 +1,9 @@ +//go:generate ../../../tools/readme_config_includer/generator package nginx import ( "bufio" + _ "embed" "fmt" "net" "net/http" @@ -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 Nginx struct { Urls []string ResponseTimeout config.Duration @@ -26,6 +32,10 @@ type Nginx struct { client *http.Client } +func (*Nginx) SampleConfig() string { + return sampleConfig +} + func (n *Nginx) Gather(acc telegraf.Accumulator) error { var wg sync.WaitGroup diff --git a/plugins/inputs/nginx/nginx_sample_config.go b/plugins/inputs/nginx/nginx_sample_config.go deleted file mode 100644 index b531aa6a007e0..0000000000000 --- a/plugins/inputs/nginx/nginx_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package nginx - -func (n *Nginx) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/inputs/nginx_plus/README.md b/plugins/inputs/nginx_plus/README.md index a56908a1d05d5..f92c65e4a8bac 100644 --- a/plugins/inputs/nginx_plus/README.md +++ b/plugins/inputs/nginx_plus/README.md @@ -7,7 +7,7 @@ Structures for Nginx Plus have been built based on history of ## Configuration -```toml +```toml @sample.conf # Read Nginx Plus' advanced status information [[inputs.nginx_plus]] ## An array of Nginx status URIs to gather stats. diff --git a/plugins/inputs/nginx_plus/nginx_plus.go b/plugins/inputs/nginx_plus/nginx_plus.go index 276d6e5b8f398..21e2862ca5d9f 100644 --- a/plugins/inputs/nginx_plus/nginx_plus.go +++ b/plugins/inputs/nginx_plus/nginx_plus.go @@ -1,7 +1,9 @@ +//go:generate ../../../tools/readme_config_includer/generator package nginx_plus import ( "bufio" + _ "embed" "encoding/json" "fmt" "net" @@ -18,6 +20,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 NginxPlus struct { Urls []string `toml:"urls"` ResponseTimeout config.Duration `toml:"response_timeout"` @@ -26,6 +32,10 @@ type NginxPlus struct { client *http.Client } +func (*NginxPlus) SampleConfig() string { + return sampleConfig +} + func (n *NginxPlus) Gather(acc telegraf.Accumulator) error { var wg sync.WaitGroup diff --git a/plugins/inputs/nginx_plus/nginx_plus_sample_config.go b/plugins/inputs/nginx_plus/nginx_plus_sample_config.go deleted file mode 100644 index c8de4f6087287..0000000000000 --- a/plugins/inputs/nginx_plus/nginx_plus_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package nginx_plus - -func (n *NginxPlus) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/inputs/nginx_plus_api/README.md b/plugins/inputs/nginx_plus_api/README.md index 516e68126081a..04a7a413be4c5 100644 --- a/plugins/inputs/nginx_plus_api/README.md +++ b/plugins/inputs/nginx_plus_api/README.md @@ -4,7 +4,7 @@ Nginx Plus is a commercial version of the open source web server Nginx. The use ## Configuration -```toml +```toml @sample.conf # Read Nginx Plus API advanced status information [[inputs.nginx_plus_api]] ## An array of Nginx API URIs to gather stats. diff --git a/plugins/inputs/nginx_plus_api/nginx_plus_api.go b/plugins/inputs/nginx_plus_api/nginx_plus_api.go index 95d037a0f0a8f..c5c035a3c0c45 100644 --- a/plugins/inputs/nginx_plus_api/nginx_plus_api.go +++ b/plugins/inputs/nginx_plus_api/nginx_plus_api.go @@ -1,6 +1,8 @@ +//go:generate ../../../tools/readme_config_includer/generator package nginx_plus_api import ( + _ "embed" "fmt" "net/http" "net/url" @@ -13,6 +15,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 NginxPlusAPI struct { Urls []string `toml:"urls"` APIVersion int64 `toml:"api_version"` @@ -43,6 +49,10 @@ const ( streamUpstreamsPath = "stream/upstreams" ) +func (*NginxPlusAPI) SampleConfig() string { + return sampleConfig +} + func (n *NginxPlusAPI) Gather(acc telegraf.Accumulator) error { var wg sync.WaitGroup diff --git a/plugins/inputs/nginx_plus_api/nginx_plus_api_sample_config.go b/plugins/inputs/nginx_plus_api/nginx_plus_api_sample_config.go deleted file mode 100644 index 3116e786982c2..0000000000000 --- a/plugins/inputs/nginx_plus_api/nginx_plus_api_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package nginx_plus_api - -func (n *NginxPlusAPI) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/inputs/nginx_sts/README.md b/plugins/inputs/nginx_sts/README.md index bacc1a32ad0cc..a935da4637a77 100644 --- a/plugins/inputs/nginx_sts/README.md +++ b/plugins/inputs/nginx_sts/README.md @@ -11,7 +11,7 @@ Telegraf minimum version: Telegraf 1.15.0 ## Configuration -```toml +```toml @sample.conf # Read Nginx virtual host traffic status module information (nginx-module-sts) [[inputs.nginx_sts]] ## An array of ngx_http_status_module or status URI to gather stats. diff --git a/plugins/inputs/nginx_sts/nginx_sts.go b/plugins/inputs/nginx_sts/nginx_sts.go index 7d232791096f5..7033095080dc0 100644 --- a/plugins/inputs/nginx_sts/nginx_sts.go +++ b/plugins/inputs/nginx_sts/nginx_sts.go @@ -1,7 +1,9 @@ +//go:generate ../../../tools/readme_config_includer/generator package nginx_sts import ( "bufio" + _ "embed" "encoding/json" "fmt" "net" @@ -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 NginxSTS struct { Urls []string `toml:"urls"` ResponseTimeout config.Duration `toml:"response_timeout"` @@ -25,6 +31,10 @@ type NginxSTS struct { client *http.Client } +func (*NginxSTS) SampleConfig() string { + return sampleConfig +} + func (n *NginxSTS) Gather(acc telegraf.Accumulator) error { var wg sync.WaitGroup diff --git a/plugins/inputs/nginx_sts/nginx_sts_sample_config.go b/plugins/inputs/nginx_sts/nginx_sts_sample_config.go deleted file mode 100644 index a2b87daea77a2..0000000000000 --- a/plugins/inputs/nginx_sts/nginx_sts_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package nginx_sts - -func (n *NginxSTS) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/inputs/nginx_upstream_check/README.md b/plugins/inputs/nginx_upstream_check/README.md index 6321f3f482c01..058672b255df5 100644 --- a/plugins/inputs/nginx_upstream_check/README.md +++ b/plugins/inputs/nginx_upstream_check/README.md @@ -10,7 +10,7 @@ checks. This information can be exported in JSON format and parsed by this input ## Configuration -```toml +```toml @sample.conf # Read nginx_upstream_check module status information (https://github.com/yaoweibin/nginx_upstream_check_module) [[inputs.nginx_upstream_check]] ## An URL where Nginx Upstream check module is enabled diff --git a/plugins/inputs/nginx_upstream_check/nginx_upstream_check.go b/plugins/inputs/nginx_upstream_check/nginx_upstream_check.go index d925ce87e32d5..2cd1ca8cdcc46 100644 --- a/plugins/inputs/nginx_upstream_check/nginx_upstream_check.go +++ b/plugins/inputs/nginx_upstream_check/nginx_upstream_check.go @@ -1,6 +1,8 @@ +//go:generate ../../../tools/readme_config_includer/generator package nginx_upstream_check import ( + _ "embed" "encoding/json" "fmt" "io" @@ -15,6 +17,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 NginxUpstreamCheck struct { URL string `toml:"url"` @@ -125,6 +131,10 @@ func (check *NginxUpstreamCheck) gatherJSONData(address string, value interface{ return nil } +func (*NginxUpstreamCheck) SampleConfig() string { + return sampleConfig +} + func (check *NginxUpstreamCheck) Gather(accumulator telegraf.Accumulator) error { if check.client == nil { client, err := check.createHTTPClient() diff --git a/plugins/inputs/nginx_upstream_check/nginx_upstream_check_sample_config.go b/plugins/inputs/nginx_upstream_check/nginx_upstream_check_sample_config.go deleted file mode 100644 index 33397b16414dd..0000000000000 --- a/plugins/inputs/nginx_upstream_check/nginx_upstream_check_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package nginx_upstream_check - -func (check *NginxUpstreamCheck) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/inputs/nginx_vts/README.md b/plugins/inputs/nginx_vts/README.md index 9d446f8c5e474..58f122e7e9e41 100644 --- a/plugins/inputs/nginx_vts/README.md +++ b/plugins/inputs/nginx_vts/README.md @@ -5,7 +5,7 @@ For module configuration details please see its [documentation](https://github.c ## Configuration -```toml +```toml @sample.conf # Read Nginx virtual host traffic status module information (nginx-module-vts) [[inputs.nginx_vts]] ## An array of ngx_http_status_module or status URI to gather stats. diff --git a/plugins/inputs/nginx_vts/nginx_vts.go b/plugins/inputs/nginx_vts/nginx_vts.go index 29343dd7e6ac5..eaf765c9d2b61 100644 --- a/plugins/inputs/nginx_vts/nginx_vts.go +++ b/plugins/inputs/nginx_vts/nginx_vts.go @@ -1,7 +1,9 @@ +//go:generate ../../../tools/readme_config_includer/generator package nginx_vts import ( "bufio" + _ "embed" "encoding/json" "fmt" "net" @@ -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 NginxVTS struct { Urls []string `toml:"urls"` ResponseTimeout config.Duration `toml:"response_timeout"` @@ -25,6 +31,10 @@ type NginxVTS struct { client *http.Client } +func (*NginxVTS) SampleConfig() string { + return sampleConfig +} + func (n *NginxVTS) Gather(acc telegraf.Accumulator) error { var wg sync.WaitGroup diff --git a/plugins/inputs/nginx_vts/nginx_vts_sample_config.go b/plugins/inputs/nginx_vts/nginx_vts_sample_config.go deleted file mode 100644 index 5eabb07e07676..0000000000000 --- a/plugins/inputs/nginx_vts/nginx_vts_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package nginx_vts - -func (n *NginxVTS) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/inputs/nomad/README.md b/plugins/inputs/nomad/README.md index 508f5d64bb969..cc3aae3845795 100644 --- a/plugins/inputs/nomad/README.md +++ b/plugins/inputs/nomad/README.md @@ -6,7 +6,7 @@ The Nomad plugin must grab metrics from every Nomad agent of the cluster. Telegr ## Configuration -```toml +```toml @sample.conf # Read metrics from the Nomad API [[inputs.nomad]] ## URL for the Nomad agent diff --git a/plugins/inputs/nomad/nomad.go b/plugins/inputs/nomad/nomad.go index debd07c126fda..85d5f6b1d93fe 100644 --- a/plugins/inputs/nomad/nomad.go +++ b/plugins/inputs/nomad/nomad.go @@ -1,6 +1,8 @@ +//go:generate ../../../tools/readme_config_includer/generator package nomad import ( + _ "embed" "encoding/json" "fmt" "net/http" @@ -12,6 +14,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 + // Nomad configuration object type Nomad struct { URL string `toml:"url"` @@ -33,6 +39,10 @@ func init() { }) } +func (*Nomad) SampleConfig() string { + return sampleConfig +} + func (n *Nomad) Init() error { if n.URL == "" { n.URL = "http://127.0.0.1:4646" diff --git a/plugins/inputs/nomad/nomad_sample_config.go b/plugins/inputs/nomad/nomad_sample_config.go deleted file mode 100644 index b8750dfc0e295..0000000000000 --- a/plugins/inputs/nomad/nomad_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package nomad - -func (n *Nomad) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/inputs/nsd/README.md b/plugins/inputs/nsd/README.md index 51c45b1f4fb66..f2364e3217661 100644 --- a/plugins/inputs/nsd/README.md +++ b/plugins/inputs/nsd/README.md @@ -6,7 +6,7 @@ server. ## Configuration -```toml +```toml @sample.conf # A plugin to collect stats from the NSD DNS resolver [[inputs.nsd]] ## Address of server to connect to, optionally ':port'. Defaults to the diff --git a/plugins/inputs/nsd/nsd.go b/plugins/inputs/nsd/nsd.go index 4b633148c63b1..95c508d595091 100644 --- a/plugins/inputs/nsd/nsd.go +++ b/plugins/inputs/nsd/nsd.go @@ -1,8 +1,10 @@ +//go:generate ../../../tools/readme_config_includer/generator package nsd import ( "bufio" "bytes" + _ "embed" "fmt" "net" "os/exec" @@ -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 runner func(cmdName string, timeout config.Duration, useSudo bool, Server string, ConfigFile string) (*bytes.Buffer, error) // NSD is used to store configuration values @@ -66,6 +72,10 @@ func nsdRunner(cmdName string, timeout config.Duration, useSudo bool, server str return &out, nil } +func (*NSD) SampleConfig() string { + return sampleConfig +} + // Gather collects stats from nsd-control and adds them to the Accumulator func (s *NSD) Gather(acc telegraf.Accumulator) error { out, err := s.run(s.Binary, s.Timeout, s.UseSudo, s.Server, s.ConfigFile) diff --git a/plugins/inputs/nsd/nsd_sample_config.go b/plugins/inputs/nsd/nsd_sample_config.go deleted file mode 100644 index ed25231c7fcf9..0000000000000 --- a/plugins/inputs/nsd/nsd_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package nsd - -func (s *NSD) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/inputs/nsq/README.md b/plugins/inputs/nsq/README.md index 6d25a9c4207f8..4ea42bf885e5b 100644 --- a/plugins/inputs/nsq/README.md +++ b/plugins/inputs/nsq/README.md @@ -2,7 +2,7 @@ ## Configuration -```toml +```toml @sample.conf # Read NSQ topic and channel statistics. [[inputs.nsq]] ## An array of NSQD HTTP API endpoints diff --git a/plugins/inputs/nsq/nsq.go b/plugins/inputs/nsq/nsq.go index dec8ccd741c2f..9d86c02e71368 100644 --- a/plugins/inputs/nsq/nsq.go +++ b/plugins/inputs/nsq/nsq.go @@ -1,3 +1,4 @@ +//go:generate ../../../tools/readme_config_includer/generator // The MIT License (MIT) // // Copyright (c) 2015 Jeff Nickoloff (jeff@allingeek.com) @@ -23,6 +24,7 @@ package nsq import ( + _ "embed" "encoding/json" "fmt" "io" @@ -37,6 +39,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 + // Might add Lookupd endpoints for cluster discovery type NSQ struct { Endpoints []string @@ -58,6 +64,10 @@ func New() *NSQ { return &NSQ{} } +func (*NSQ) SampleConfig() string { + return sampleConfig +} + func (n *NSQ) Gather(acc telegraf.Accumulator) error { var err error diff --git a/plugins/inputs/nsq/nsq_sample_config.go b/plugins/inputs/nsq/nsq_sample_config.go deleted file mode 100644 index 75efaba5a5793..0000000000000 --- a/plugins/inputs/nsq/nsq_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package nsq - -func (n *NSQ) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/inputs/nsq_consumer/README.md b/plugins/inputs/nsq_consumer/README.md index b10bfbf6f7b68..d2fc086ed26c1 100644 --- a/plugins/inputs/nsq_consumer/README.md +++ b/plugins/inputs/nsq_consumer/README.md @@ -5,7 +5,7 @@ of the supported [input data formats][]. ## Configuration -```toml +```toml @sample.conf # Read metrics from NSQD topic(s) [[inputs.nsq_consumer]] ## Server option still works but is deprecated, we just prepend it to the nsqd array. diff --git a/plugins/inputs/nsq_consumer/nsq_consumer.go b/plugins/inputs/nsq_consumer/nsq_consumer.go index 086c71722aac0..d7d174cf3611d 100644 --- a/plugins/inputs/nsq_consumer/nsq_consumer.go +++ b/plugins/inputs/nsq_consumer/nsq_consumer.go @@ -1,16 +1,23 @@ +//go:generate ../../../tools/readme_config_includer/generator package nsq_consumer import ( "context" + _ "embed" "fmt" "sync" + nsq "github.com/nsqio/go-nsq" + "github.com/influxdata/telegraf" "github.com/influxdata/telegraf/plugins/inputs" "github.com/influxdata/telegraf/plugins/parsers" - nsq "github.com/nsqio/go-nsq" ) +// 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 ) @@ -49,6 +56,10 @@ type NSQConsumer struct { cancel context.CancelFunc } +func (*NSQConsumer) SampleConfig() string { + return sampleConfig +} + // SetParser takes the data_format from the config and finds the right parser for that format func (n *NSQConsumer) SetParser(parser parsers.Parser) { n.parser = parser diff --git a/plugins/inputs/nsq_consumer/nsq_consumer_sample_config.go b/plugins/inputs/nsq_consumer/nsq_consumer_sample_config.go deleted file mode 100644 index 58597d2b66199..0000000000000 --- a/plugins/inputs/nsq_consumer/nsq_consumer_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package nsq_consumer - -func (n *NSQConsumer) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/inputs/nstat/README.md b/plugins/inputs/nstat/README.md index 72d4ffb4016c8..b233819bc92cd 100644 --- a/plugins/inputs/nstat/README.md +++ b/plugins/inputs/nstat/README.md @@ -29,7 +29,7 @@ So if nothing is given, no paths in config and in env vars, the plugin takes the The sample config file -```toml +```toml @sample.conf # Collect kernel snmp counters and network interface statistics [[inputs.nstat]] ## file paths for proc files. If empty default paths will be used: diff --git a/plugins/inputs/nstat/nstat.go b/plugins/inputs/nstat/nstat.go index 2feddb3b6fb6d..c811f0658f376 100644 --- a/plugins/inputs/nstat/nstat.go +++ b/plugins/inputs/nstat/nstat.go @@ -1,7 +1,9 @@ +//go:generate ../../../tools/readme_config_includer/generator package nstat import ( "bytes" + _ "embed" "os" "strconv" @@ -9,6 +11,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 + var ( zeroByte = []byte("0") newLineByte = []byte("\n") @@ -38,6 +44,10 @@ type Nstat struct { DumpZeros bool `toml:"dump_zeros"` } +func (*Nstat) SampleConfig() string { + return sampleConfig +} + func (ns *Nstat) Gather(acc telegraf.Accumulator) error { // load paths, get from env if config values are empty ns.loadPaths() diff --git a/plugins/inputs/nstat/nstat_sample_config.go b/plugins/inputs/nstat/nstat_sample_config.go deleted file mode 100644 index ffed972bcfd07..0000000000000 --- a/plugins/inputs/nstat/nstat_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package nstat - -func (ns *Nstat) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/inputs/ntpq/README.md b/plugins/inputs/ntpq/README.md index 79838b5c002e9..1ec26b5165c41 100644 --- a/plugins/inputs/ntpq/README.md +++ b/plugins/inputs/ntpq/README.md @@ -26,7 +26,7 @@ server (RMS of difference of multiple time samples, milliseconds); ## Configuration -```toml +```toml @sample.conf # Get standard NTP query metrics, requires ntpq executable. [[inputs.ntpq]] ## If false, set the -n ntpq flag. Can reduce metric gather time. diff --git a/plugins/inputs/ntpq/ntpq.go b/plugins/inputs/ntpq/ntpq.go index 91ba1c4446bfa..53fd42f4f08e5 100644 --- a/plugins/inputs/ntpq/ntpq.go +++ b/plugins/inputs/ntpq/ntpq.go @@ -1,8 +1,10 @@ +//go:generate ../../../tools/readme_config_includer/generator package ntpq import ( "bufio" "bytes" + _ "embed" "fmt" "os/exec" "regexp" @@ -13,6 +15,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 + // Mapping of ntpq header names to tag keys var tagHeaders = map[string]string{ "remote": "remote", @@ -30,6 +36,10 @@ type NTPQ struct { DNSLookup bool `toml:"dns_lookup"` } +func (*NTPQ) SampleConfig() string { + return sampleConfig +} + func (n *NTPQ) Gather(acc telegraf.Accumulator) error { out, err := n.runQ() if err != nil { diff --git a/plugins/inputs/ntpq/ntpq_sample_config.go b/plugins/inputs/ntpq/ntpq_sample_config.go deleted file mode 100644 index 71afaf57eb479..0000000000000 --- a/plugins/inputs/ntpq/ntpq_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package ntpq - -func (n *NTPQ) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/inputs/nvidia_smi/README.md b/plugins/inputs/nvidia_smi/README.md index 2ca257c2790ba..d52b7d6eb33e2 100644 --- a/plugins/inputs/nvidia_smi/README.md +++ b/plugins/inputs/nvidia_smi/README.md @@ -4,7 +4,7 @@ This plugin uses a query on the [`nvidia-smi`](https://developer.nvidia.com/nvid ## Configuration -```toml +```toml @sample.conf # Pulls statistics from nvidia GPUs attached to the host [[inputs.nvidia_smi]] ## Optional: path to nvidia-smi binary, defaults "/usr/bin/nvidia-smi" diff --git a/plugins/inputs/nvidia_smi/nvidia_smi.go b/plugins/inputs/nvidia_smi/nvidia_smi.go index bc4b571575b12..d9c297e368b5b 100644 --- a/plugins/inputs/nvidia_smi/nvidia_smi.go +++ b/plugins/inputs/nvidia_smi/nvidia_smi.go @@ -1,6 +1,8 @@ +//go:generate ../../../tools/readme_config_includer/generator package nvidia_smi import ( + _ "embed" "encoding/xml" "fmt" "os" @@ -15,6 +17,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 + const measurement = "nvidia_smi" // NvidiaSMI holds the methods for this plugin @@ -23,6 +29,10 @@ type NvidiaSMI struct { Timeout config.Duration } +func (*NvidiaSMI) SampleConfig() string { + return sampleConfig +} + func (smi *NvidiaSMI) Init() error { if _, err := os.Stat(smi.BinPath); os.IsNotExist(err) { binPath, err := exec.LookPath("nvidia-smi") diff --git a/plugins/inputs/nvidia_smi/nvidia_smi_sample_config.go b/plugins/inputs/nvidia_smi/nvidia_smi_sample_config.go deleted file mode 100644 index 9919a1f1b0915..0000000000000 --- a/plugins/inputs/nvidia_smi/nvidia_smi_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package nvidia_smi - -func (smi *NvidiaSMI) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/inputs/opcua/README.md b/plugins/inputs/opcua/README.md index e8505c6943c1f..cfc12760075c1 100644 --- a/plugins/inputs/opcua/README.md +++ b/plugins/inputs/opcua/README.md @@ -7,7 +7,7 @@ Plugin minimum tested version: 1.16 ## Configuration -```toml +```toml @sample.conf # Retrieve data from OPCUA devices [[inputs.opcua]] ## Metric name diff --git a/plugins/inputs/opcua/opcua.go b/plugins/inputs/opcua/opcua.go index 66fbdcb68c91f..44b8a6f291584 100644 --- a/plugins/inputs/opcua/opcua.go +++ b/plugins/inputs/opcua/opcua.go @@ -1,7 +1,9 @@ +//go:generate ../../../tools/readme_config_includer/generator package opcua import ( "context" + _ "embed" "fmt" "net/url" "sort" @@ -19,6 +21,10 @@ import ( "github.com/influxdata/telegraf/selfstat" ) +// DO NOT REMOVE THE NEXT TWO LINES! This is required to embedd the sampleConfig data. +//go:embed sample.conf +var sampleConfig string + type OpcuaWorkarounds struct { AdditionalValidStatusCodes []string `toml:"additional_valid_status_codes"` } @@ -106,6 +112,10 @@ const ( Connected ) +func (*OpcUA) SampleConfig() string { + return sampleConfig +} + // Init will initialize all tags func (o *OpcUA) Init() error { o.state = Disconnected diff --git a/plugins/inputs/opcua/opcua_sample_config.go b/plugins/inputs/opcua/opcua_sample_config.go deleted file mode 100644 index 4d8f96ceabd4a..0000000000000 --- a/plugins/inputs/opcua/opcua_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package opcua - -func (o *OpcUA) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/inputs/openldap/README.md b/plugins/inputs/openldap/README.md index 2acc0366143f8..adb7d2dd3f21c 100644 --- a/plugins/inputs/openldap/README.md +++ b/plugins/inputs/openldap/README.md @@ -6,7 +6,7 @@ This plugin gathers metrics from OpenLDAP's cn=Monitor backend. To use this plugin you must enable the [slapd monitoring](https://www.openldap.org/devel/admin/monitoringslapd.html) backend. -```toml +```toml @sample.conf # OpenLDAP cn=Monitor plugin [[inputs.openldap]] host = "localhost" diff --git a/plugins/inputs/openldap/openldap.go b/plugins/inputs/openldap/openldap.go index 45ae42a350b0b..198023b90b8a5 100644 --- a/plugins/inputs/openldap/openldap.go +++ b/plugins/inputs/openldap/openldap.go @@ -1,6 +1,8 @@ +//go:generate ../../../tools/readme_config_includer/generator package openldap import ( + _ "embed" "fmt" "strconv" "strings" @@ -12,6 +14,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 Openldap struct { Host string Port int @@ -57,6 +63,10 @@ func NewOpenldap() *Openldap { } } +func (*Openldap) SampleConfig() string { + return sampleConfig +} + // gather metrics func (o *Openldap) Gather(acc telegraf.Accumulator) error { if o.TLS == "" { diff --git a/plugins/inputs/openldap/openldap_sample_config.go b/plugins/inputs/openldap/openldap_sample_config.go deleted file mode 100644 index f9705bd7947f1..0000000000000 --- a/plugins/inputs/openldap/openldap_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package openldap - -func (o *Openldap) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/inputs/openntpd/README.md b/plugins/inputs/openntpd/README.md index c8cb7edabbc2e..25eaddd47fdf2 100644 --- a/plugins/inputs/openntpd/README.md +++ b/plugins/inputs/openntpd/README.md @@ -22,7 +22,7 @@ server (RMS of difference of multiple time samples, milliseconds); ## Configuration -```toml +```toml @sample.conf # Get standard NTP query metrics from OpenNTPD. [[inputs.openntpd]] ## Run ntpctl binary with sudo. diff --git a/plugins/inputs/openntpd/openntpd.go b/plugins/inputs/openntpd/openntpd.go index b5c293cc39473..d599342f95b27 100644 --- a/plugins/inputs/openntpd/openntpd.go +++ b/plugins/inputs/openntpd/openntpd.go @@ -1,8 +1,10 @@ +//go:generate ../../../tools/readme_config_includer/generator package openntpd import ( "bufio" "bytes" + _ "embed" "fmt" "os/exec" "strconv" @@ -15,6 +17,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 + // Mapping of the ntpctl tag key to the index in the command output var tagI = map[string]int{ "stratum": 2, @@ -70,6 +76,10 @@ func openntpdRunner(cmdName string, timeout config.Duration, useSudo bool) (*byt return &out, nil } +func (*Openntpd) SampleConfig() string { + return sampleConfig +} + func (n *Openntpd) Gather(acc telegraf.Accumulator) error { out, err := n.run(n.Binary, n.Timeout, n.UseSudo) if err != nil { diff --git a/plugins/inputs/openntpd/openntpd_sample_config.go b/plugins/inputs/openntpd/openntpd_sample_config.go deleted file mode 100644 index a6a5964d08329..0000000000000 --- a/plugins/inputs/openntpd/openntpd_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package openntpd - -func (n *Openntpd) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/inputs/opensmtpd/README.md b/plugins/inputs/opensmtpd/README.md index 5aaad1a35969e..d1ad9bca62fa6 100644 --- a/plugins/inputs/opensmtpd/README.md +++ b/plugins/inputs/opensmtpd/README.md @@ -4,7 +4,7 @@ This plugin gathers stats from [OpenSMTPD - a FREE implementation of the server- ## Configuration -```toml +```toml @sample.conf # A plugin to collect stats from Opensmtpd - a validating, recursive, and caching DNS resolver [[inputs.opensmtpd]] ## If running as a restricted user you can prepend sudo for additional access: diff --git a/plugins/inputs/opensmtpd/opensmtpd.go b/plugins/inputs/opensmtpd/opensmtpd.go index 7159e47a60111..cbd2c68681694 100644 --- a/plugins/inputs/opensmtpd/opensmtpd.go +++ b/plugins/inputs/opensmtpd/opensmtpd.go @@ -1,8 +1,10 @@ +//go:generate ../../../tools/readme_config_includer/generator package opensmtpd import ( "bufio" "bytes" + _ "embed" "fmt" "os/exec" "strconv" @@ -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 runner func(cmdName string, timeout config.Duration, useSudo bool) (*bytes.Buffer, error) // Opensmtpd is used to store configuration values @@ -54,6 +60,10 @@ func opensmtpdRunner(cmdName string, timeout config.Duration, useSudo bool) (*by // Gather collects the configured stats from smtpctl and adds them to the // Accumulator // +func (*Opensmtpd) SampleConfig() string { + return sampleConfig +} + // All the dots in stat name will replaced by underscores. Histogram statistics will not be collected. func (s *Opensmtpd) Gather(acc telegraf.Accumulator) error { // Always exclude uptime.human statistics diff --git a/plugins/inputs/opensmtpd/opensmtpd_sample_config.go b/plugins/inputs/opensmtpd/opensmtpd_sample_config.go deleted file mode 100644 index d4f3cc03dbf69..0000000000000 --- a/plugins/inputs/opensmtpd/opensmtpd_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package opensmtpd - -func (s *Opensmtpd) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/inputs/openstack/README.md b/plugins/inputs/openstack/README.md index 0a70426d61254..6b53f45bf5246 100644 --- a/plugins/inputs/openstack/README.md +++ b/plugins/inputs/openstack/README.md @@ -50,7 +50,7 @@ Also, consider polling OpenStack services at different intervals depending on yo ### Configuration -```toml +```toml @sample.conf # Collects performance metrics from OpenStack services [[inputs.openstack]] ## The recommended interval to poll is '30m' diff --git a/plugins/inputs/openstack/openstack.go b/plugins/inputs/openstack/openstack.go index 1da597946bfe3..38b6bc841410d 100644 --- a/plugins/inputs/openstack/openstack.go +++ b/plugins/inputs/openstack/openstack.go @@ -1,3 +1,4 @@ +//go:generate ../../../tools/readme_config_includer/generator // Package openstack implements an OpenStack input plugin for Telegraf // // The OpenStack input plug is a simple two phase metric collector. In the first @@ -10,6 +11,7 @@ package openstack import ( "context" + _ "embed" "fmt" "regexp" "sort" @@ -35,12 +37,17 @@ import ( "github.com/gophercloud/gophercloud/openstack/networking/v2/ports" "github.com/gophercloud/gophercloud/openstack/networking/v2/subnets" "github.com/gophercloud/gophercloud/openstack/orchestration/v1/stacks" + "github.com/influxdata/telegraf" "github.com/influxdata/telegraf/internal/choice" httpconfig "github.com/influxdata/telegraf/plugins/common/http" "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 + var ( typePort = regexp.MustCompile(`_rx$|_rx_drop$|_rx_errors$|_rx_packets$|_tx$|_tx_drop$|_tx_errors$|_tx_packets$`) typeCPU = regexp.MustCompile(`cpu[0-9]{1,2}_time$`) @@ -105,6 +112,10 @@ func (o *OpenStack) convertTimeFormat(t time.Time) interface{} { return t.UnixNano() } +func (*OpenStack) SampleConfig() string { + return sampleConfig +} + // initialize performs any necessary initialization functions func (o *OpenStack) Init() error { if len(o.EnabledServices) == 0 { diff --git a/plugins/inputs/openstack/openstack_sample_config.go b/plugins/inputs/openstack/openstack_sample_config.go deleted file mode 100644 index 7168ea6e24b29..0000000000000 --- a/plugins/inputs/openstack/openstack_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package openstack - -func (o *OpenStack) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/inputs/opentelemetry/README.md b/plugins/inputs/opentelemetry/README.md index f876cf73a84dc..21522390a370d 100644 --- a/plugins/inputs/opentelemetry/README.md +++ b/plugins/inputs/opentelemetry/README.md @@ -4,7 +4,7 @@ This plugin receives traces, metrics and logs from [OpenTelemetry](https://opent ## Configuration -```toml +```toml @sample.conf # Receive OpenTelemetry traces, metrics, and logs over gRPC [[inputs.opentelemetry]] ## Override the default (0.0.0.0:4317) destination OpenTelemetry gRPC service diff --git a/plugins/inputs/opentelemetry/opentelemetry.go b/plugins/inputs/opentelemetry/opentelemetry.go index 798c9fe7d9431..944c83f99c484 100644 --- a/plugins/inputs/opentelemetry/opentelemetry.go +++ b/plugins/inputs/opentelemetry/opentelemetry.go @@ -1,22 +1,29 @@ +//go:generate ../../../tools/readme_config_includer/generator package opentelemetry import ( + _ "embed" "fmt" - "go.opentelemetry.io/collector/pdata/plog/plogotlp" - "go.opentelemetry.io/collector/pdata/pmetric/pmetricotlp" - "go.opentelemetry.io/collector/pdata/ptrace/ptraceotlp" "net" "sync" "time" + "go.opentelemetry.io/collector/pdata/plog/plogotlp" + "go.opentelemetry.io/collector/pdata/pmetric/pmetricotlp" + "go.opentelemetry.io/collector/pdata/ptrace/ptraceotlp" + "google.golang.org/grpc" + "google.golang.org/grpc/credentials" + "github.com/influxdata/telegraf" "github.com/influxdata/telegraf/config" "github.com/influxdata/telegraf/plugins/common/tls" "github.com/influxdata/telegraf/plugins/inputs" - "google.golang.org/grpc" - "google.golang.org/grpc/credentials" ) +// DO NOT REMOVE THE NEXT TWO LINES! This is required to embedd the sampleConfig data. +//go:embed sample.conf +var sampleConfig string + type OpenTelemetry struct { ServiceAddress string `toml:"service_address"` MetricsSchema string `toml:"metrics_schema"` @@ -32,6 +39,10 @@ type OpenTelemetry struct { wg sync.WaitGroup } +func (*OpenTelemetry) SampleConfig() string { + return sampleConfig +} + func (o *OpenTelemetry) Gather(_ telegraf.Accumulator) error { return nil } diff --git a/plugins/inputs/opentelemetry/opentelemetry_sample_config.go b/plugins/inputs/opentelemetry/opentelemetry_sample_config.go deleted file mode 100644 index 82380c71d9cac..0000000000000 --- a/plugins/inputs/opentelemetry/opentelemetry_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package opentelemetry - -func (o *OpenTelemetry) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/inputs/openweathermap/README.md b/plugins/inputs/openweathermap/README.md index dc2d44a121eae..f6884371f9ae2 100644 --- a/plugins/inputs/openweathermap/README.md +++ b/plugins/inputs/openweathermap/README.md @@ -12,7 +12,7 @@ condition ID, icon, and main is at [weather conditions][]. ## Configuration -```toml +```toml @sample.conf # Read current weather and forecasts data from openweathermap.org [[inputs.openweathermap]] ## OpenWeatherMap API key. diff --git a/plugins/inputs/openweathermap/openweathermap.go b/plugins/inputs/openweathermap/openweathermap.go index 7876d81ddc16c..73a3f2e178492 100644 --- a/plugins/inputs/openweathermap/openweathermap.go +++ b/plugins/inputs/openweathermap/openweathermap.go @@ -1,6 +1,8 @@ +//go:generate ../../../tools/readme_config_includer/generator package openweathermap import ( + _ "embed" "encoding/json" "fmt" "io" @@ -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 + const ( // https://openweathermap.org/current#severalid // Call for several city IDs @@ -42,6 +48,10 @@ type OpenWeatherMap struct { baseParsedURL *url.URL } +func (*OpenWeatherMap) SampleConfig() string { + return sampleConfig +} + func (n *OpenWeatherMap) Gather(acc telegraf.Accumulator) error { var wg sync.WaitGroup var strs []string diff --git a/plugins/inputs/openweathermap/openweathermap_sample_config.go b/plugins/inputs/openweathermap/openweathermap_sample_config.go deleted file mode 100644 index e6444a6b1e910..0000000000000 --- a/plugins/inputs/openweathermap/openweathermap_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package openweathermap - -func (n *OpenWeatherMap) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/inputs/passenger/README.md b/plugins/inputs/passenger/README.md index 4300fd362dc24..343f44139f836 100644 --- a/plugins/inputs/passenger/README.md +++ b/plugins/inputs/passenger/README.md @@ -22,7 +22,7 @@ manage your series cardinality: ## Configuration -```toml +```toml @sample.conf # Read metrics of passenger using passenger-status [[inputs.passenger]] ## Path of passenger-status. diff --git a/plugins/inputs/passenger/passenger.go b/plugins/inputs/passenger/passenger.go index 1259b7716b376..96730328f6b9d 100644 --- a/plugins/inputs/passenger/passenger.go +++ b/plugins/inputs/passenger/passenger.go @@ -1,18 +1,25 @@ +//go:generate ../../../tools/readme_config_includer/generator package passenger import ( "bytes" + _ "embed" "encoding/xml" "fmt" "os/exec" "strconv" "strings" + "golang.org/x/net/html/charset" + "github.com/influxdata/telegraf" "github.com/influxdata/telegraf/plugins/inputs" - "golang.org/x/net/html/charset" ) +// DO NOT REMOVE THE NEXT TWO LINES! This is required to embedd the sampleConfig data. +//go:embed sample.conf +var sampleConfig string + type passenger struct { Command string } @@ -125,6 +132,10 @@ func (p *process) getUptime() int64 { return uptime } +func (*passenger) SampleConfig() string { + return sampleConfig +} + func (p *passenger) Gather(acc telegraf.Accumulator) error { if p.Command == "" { p.Command = "passenger-status -v --show=xml" diff --git a/plugins/inputs/passenger/passenger_sample_config.go b/plugins/inputs/passenger/passenger_sample_config.go deleted file mode 100644 index 7a793b01c313c..0000000000000 --- a/plugins/inputs/passenger/passenger_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package passenger - -func (p *passenger) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/inputs/pf/README.md b/plugins/inputs/pf/README.md index 8f97af524df18..71c532829c97a 100644 --- a/plugins/inputs/pf/README.md +++ b/plugins/inputs/pf/README.md @@ -19,7 +19,7 @@ telegraf ALL=(root) NOPASSWD: /sbin/pfctl -s info ## Configuration -```toml +```toml @sample.conf # Gather counters from PF [[inputs.pf]] ## PF require root access on most systems. diff --git a/plugins/inputs/pf/pf.go b/plugins/inputs/pf/pf.go index 40a8efb4ba523..33b576231a583 100644 --- a/plugins/inputs/pf/pf.go +++ b/plugins/inputs/pf/pf.go @@ -1,7 +1,9 @@ +//go:generate ../../../tools/readme_config_includer/generator package pf import ( "bufio" + _ "embed" "fmt" "os/exec" "regexp" @@ -12,6 +14,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 + const measurement = "pf" const pfctlCommand = "pfctl" @@ -23,6 +29,10 @@ type PF struct { infoFunc func() (string, error) } +func (*PF) SampleConfig() string { + return sampleConfig +} + // Gather is the entrypoint for the plugin. func (pf *PF) Gather(acc telegraf.Accumulator) error { if pf.PfctlCommand == "" { @@ -208,7 +218,7 @@ func (pf *PF) buildPfctlCmd() (string, []string, error) { func init() { inputs.Add("pf", func() telegraf.Input { - pf := new(PF) + pf := &PF{} pf.infoFunc = pf.callPfctl return pf }) diff --git a/plugins/inputs/pf/pf_sample_config.go b/plugins/inputs/pf/pf_sample_config.go deleted file mode 100644 index ab7663d765b79..0000000000000 --- a/plugins/inputs/pf/pf_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package pf - -func (pf *PF) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/inputs/pgbouncer/README.md b/plugins/inputs/pgbouncer/README.md index 4539651cc76c9..df323da9f20c2 100644 --- a/plugins/inputs/pgbouncer/README.md +++ b/plugins/inputs/pgbouncer/README.md @@ -9,7 +9,7 @@ More information about the meaning of these metrics can be found in the ## Configuration -```toml +```toml @sample.conf # Read metrics from one or many pgbouncer servers [[inputs.pgbouncer]] ## specify address via a url matching: diff --git a/plugins/inputs/pgbouncer/pgbouncer.go b/plugins/inputs/pgbouncer/pgbouncer.go index a3d5e10828f4c..f4a86ab149343 100644 --- a/plugins/inputs/pgbouncer/pgbouncer.go +++ b/plugins/inputs/pgbouncer/pgbouncer.go @@ -1,16 +1,24 @@ +//go:generate ../../../tools/readme_config_includer/generator package pgbouncer import ( "bytes" + _ "embed" "strconv" + // Required for SQL framework driver + _ "github.com/jackc/pgx/v4/stdlib" + "github.com/influxdata/telegraf" "github.com/influxdata/telegraf/config" "github.com/influxdata/telegraf/plugins/inputs" "github.com/influxdata/telegraf/plugins/inputs/postgresql" - _ "github.com/jackc/pgx/v4/stdlib" // register driver ) +// DO NOT REMOVE THE NEXT TWO LINES! This is required to embedd the sampleConfig data. +//go:embed sample.conf +var sampleConfig string + type PgBouncer struct { postgresql.Service } @@ -19,6 +27,10 @@ var ignoredColumns = map[string]bool{"user": true, "database": true, "pool_mode" "avg_req": true, "avg_recv": true, "avg_sent": true, "avg_query": true, } +func (*PgBouncer) SampleConfig() string { + return sampleConfig +} + func (p *PgBouncer) Gather(acc telegraf.Accumulator) error { var ( err error diff --git a/plugins/inputs/pgbouncer/pgbouncer_sample_config.go b/plugins/inputs/pgbouncer/pgbouncer_sample_config.go deleted file mode 100644 index 6150e515e0114..0000000000000 --- a/plugins/inputs/pgbouncer/pgbouncer_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package pgbouncer - -func (p *PgBouncer) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/inputs/phpfpm/README.md b/plugins/inputs/phpfpm/README.md index 8e7a6960ccf40..a1b3759c6ea63 100644 --- a/plugins/inputs/phpfpm/README.md +++ b/plugins/inputs/phpfpm/README.md @@ -4,7 +4,7 @@ Get phpfpm stats using either HTTP status page or fpm socket. ## Configuration -```toml +```toml @sample.conf # Read metrics of phpfpm, via HTTP status page or socket [[inputs.phpfpm]] ## An array of addresses to gather stats about. Specify an ip or hostname diff --git a/plugins/inputs/phpfpm/phpfpm.go b/plugins/inputs/phpfpm/phpfpm.go index 52ef1f7f8bc78..c0b1c1375fede 100644 --- a/plugins/inputs/phpfpm/phpfpm.go +++ b/plugins/inputs/phpfpm/phpfpm.go @@ -1,8 +1,10 @@ +//go:generate ../../../tools/readme_config_includer/generator package phpfpm import ( "bufio" "bytes" + _ "embed" "fmt" "io" "net/http" @@ -19,6 +21,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 + const ( PfPool = "pool" PfProcessManager = "process manager" @@ -46,6 +52,10 @@ type phpfpm struct { client *http.Client } +func (*phpfpm) SampleConfig() string { + return sampleConfig +} + func (p *phpfpm) Init() error { tlsCfg, err := p.ClientConfig.TLSConfig() if err != nil { diff --git a/plugins/inputs/phpfpm/phpfpm_sample_config.go b/plugins/inputs/phpfpm/phpfpm_sample_config.go deleted file mode 100644 index 82460af25b05d..0000000000000 --- a/plugins/inputs/phpfpm/phpfpm_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package phpfpm - -func (p *phpfpm) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/inputs/ping/README.md b/plugins/inputs/ping/README.md index 2d56ae1f69874..2876ddafb6693 100644 --- a/plugins/inputs/ping/README.md +++ b/plugins/inputs/ping/README.md @@ -24,7 +24,7 @@ native Go by the Telegraf process, eliminating the need to execute the system ## Configuration -```toml +```toml @sample.conf # Ping given url(s) and return statistics [[inputs.ping]] ## Hosts to send ping packets to. diff --git a/plugins/inputs/ping/ping.go b/plugins/inputs/ping/ping.go index d2e07df83bbf2..ab755b0b9865a 100644 --- a/plugins/inputs/ping/ping.go +++ b/plugins/inputs/ping/ping.go @@ -1,6 +1,8 @@ +//go:generate ../../../tools/readme_config_includer/generator package ping import ( + _ "embed" "errors" "fmt" "math" @@ -19,6 +21,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 + const ( defaultPingDataBytesSize = 56 ) @@ -97,6 +103,10 @@ type stats struct { roundTripTimeStats } +func (*Ping) SampleConfig() string { + return sampleConfig +} + func (p *Ping) Gather(acc telegraf.Accumulator) error { for _, host := range p.Urls { p.wg.Add(1) diff --git a/plugins/inputs/ping/ping_sample_config.go b/plugins/inputs/ping/ping_sample_config.go deleted file mode 100644 index 7fb1867b88954..0000000000000 --- a/plugins/inputs/ping/ping_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package ping - -func (*Ping) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/inputs/postfix/README.md b/plugins/inputs/postfix/README.md index 9388a92259d82..069bd74538629 100644 --- a/plugins/inputs/postfix/README.md +++ b/plugins/inputs/postfix/README.md @@ -9,7 +9,7 @@ item in seconds). ## Configuration -```toml +```toml @sample.conf # Measure postfix queue statistics [[inputs.postfix]] ## Postfix queue directory. If not provided, telegraf will try to use diff --git a/plugins/inputs/postfix/postfix.go b/plugins/inputs/postfix/postfix.go index f4faeff8490a9..fbbe6522dfc74 100644 --- a/plugins/inputs/postfix/postfix.go +++ b/plugins/inputs/postfix/postfix.go @@ -1,3 +1,4 @@ +//go:generate ../../../tools/readme_config_includer/generator //go:build !windows // +build !windows @@ -6,6 +7,7 @@ package postfix import ( + _ "embed" "fmt" "os" "os/exec" @@ -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 + func getQueueDirectory() (string, error) { qd, err := exec.Command("postconf", "-h", "queue_directory").Output() if err != nil { @@ -75,6 +81,10 @@ type Postfix struct { QueueDirectory string } +func (*Postfix) SampleConfig() string { + return sampleConfig +} + func (p *Postfix) Gather(acc telegraf.Accumulator) error { if p.QueueDirectory == "" { var err error diff --git a/plugins/inputs/postfix/postfix_sample_config.go b/plugins/inputs/postfix/postfix_sample_config.go deleted file mode 100644 index 8ec9ad99dc4c3..0000000000000 --- a/plugins/inputs/postfix/postfix_sample_config.go +++ /dev/null @@ -1,11 +0,0 @@ -//go:build !windows -// +build !windows - -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package postfix - -func (p *Postfix) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/inputs/postgresql/README.md b/plugins/inputs/postgresql/README.md index ecc256a0ac585..9cb1f3fd4d398 100644 --- a/plugins/inputs/postgresql/README.md +++ b/plugins/inputs/postgresql/README.md @@ -32,7 +32,7 @@ More information about the meaning of these metrics can be found in the [Postgre ## Configuration -```toml +```toml @sample.conf # Read metrics from one or many postgresql servers [[inputs.postgresql]] ## specify address via a url matching: diff --git a/plugins/inputs/postgresql/postgresql.go b/plugins/inputs/postgresql/postgresql.go index d7769e7d3dd0d..9a3beef1e36de 100644 --- a/plugins/inputs/postgresql/postgresql.go +++ b/plugins/inputs/postgresql/postgresql.go @@ -1,11 +1,12 @@ +//go:generate ../../../tools/readme_config_includer/generator package postgresql import ( "bytes" + _ "embed" "fmt" "strings" - // register in driver. _ "github.com/jackc/pgx/v4/stdlib" "github.com/influxdata/telegraf" @@ -13,6 +14,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 Postgresql struct { Service Databases []string `toml:"databases"` @@ -22,6 +27,10 @@ type Postgresql struct { var ignoredColumns = map[string]bool{"stats_reset": true} +func (*Postgresql) SampleConfig() string { + return sampleConfig +} + func (p *Postgresql) IgnoredColumns() map[string]bool { return ignoredColumns } diff --git a/plugins/inputs/postgresql/postgresql_sample_config.go b/plugins/inputs/postgresql/postgresql_sample_config.go deleted file mode 100644 index f574107d4b527..0000000000000 --- a/plugins/inputs/postgresql/postgresql_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package postgresql - -func (p *Postgresql) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/inputs/postgresql_extensible/README.md b/plugins/inputs/postgresql_extensible/README.md index 79789f8a51e99..6ac81a6dcbc21 100644 --- a/plugins/inputs/postgresql_extensible/README.md +++ b/plugins/inputs/postgresql_extensible/README.md @@ -13,7 +13,7 @@ The example below has two queries are specified, with the following parameters: ## Configuration -```toml +```toml @sample.conf # Read metrics from one or many postgresql servers [[inputs.postgresql_extensible]] # specify address via a url matching: diff --git a/plugins/inputs/postgresql_extensible/postgresql_extensible.go b/plugins/inputs/postgresql_extensible/postgresql_extensible.go index bbd647e08c406..844fc2bb5d411 100644 --- a/plugins/inputs/postgresql_extensible/postgresql_extensible.go +++ b/plugins/inputs/postgresql_extensible/postgresql_extensible.go @@ -1,14 +1,17 @@ +//go:generate ../../../tools/readme_config_includer/generator package postgresql_extensible import ( "bytes" + _ "embed" "fmt" "io" "os" "strings" "time" - _ "github.com/jackc/pgx/v4/stdlib" //to register stdlib from PostgreSQL Driver and Toolkit + // Required for SQL framework driver + _ "github.com/jackc/pgx/v4/stdlib" "github.com/influxdata/telegraf" "github.com/influxdata/telegraf/config" @@ -16,6 +19,10 @@ import ( "github.com/influxdata/telegraf/plugins/inputs/postgresql" ) +// DO NOT REMOVE THE NEXT TWO LINES! This is required to embedd the sampleConfig data. +//go:embed sample.conf +var sampleConfig string + type Postgresql struct { postgresql.Service Databases []string `deprecated:"1.22.4;use the sqlquery option to specify database to use"` @@ -40,6 +47,10 @@ type query []struct { var ignoredColumns = map[string]bool{"stats_reset": true} +func (*Postgresql) SampleConfig() string { + return sampleConfig +} + func (p *Postgresql) Init() error { var err error for i := range p.Query { diff --git a/plugins/inputs/postgresql_extensible/postgresql_extensible_sample_config.go b/plugins/inputs/postgresql_extensible/postgresql_extensible_sample_config.go deleted file mode 100644 index 34efab6ca43e5..0000000000000 --- a/plugins/inputs/postgresql_extensible/postgresql_extensible_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package postgresql_extensible - -func (p *Postgresql) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/inputs/powerdns/README.md b/plugins/inputs/powerdns/README.md index 6222bf6cadcb6..56e1efcdb1446 100644 --- a/plugins/inputs/powerdns/README.md +++ b/plugins/inputs/powerdns/README.md @@ -4,7 +4,7 @@ The powerdns plugin gathers metrics about PowerDNS using unix socket. ## Configuration -```toml +```toml @sample.conf # Read metrics from one or many PowerDNS servers [[inputs.powerdns]] # An array of sockets to gather stats about. diff --git a/plugins/inputs/powerdns/powerdns.go b/plugins/inputs/powerdns/powerdns.go index 04aaca5272fbc..422cfdbc8e492 100644 --- a/plugins/inputs/powerdns/powerdns.go +++ b/plugins/inputs/powerdns/powerdns.go @@ -1,7 +1,9 @@ +//go:generate ../../../tools/readme_config_includer/generator package powerdns import ( "bufio" + _ "embed" "fmt" "io" "net" @@ -13,6 +15,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 Powerdns struct { UnixSockets []string @@ -21,6 +27,10 @@ type Powerdns struct { var defaultTimeout = 5 * time.Second +func (*Powerdns) SampleConfig() string { + return sampleConfig +} + func (p *Powerdns) Gather(acc telegraf.Accumulator) error { if len(p.UnixSockets) == 0 { return p.gatherServer("/var/run/pdns.controlsocket", acc) diff --git a/plugins/inputs/powerdns/powerdns_sample_config.go b/plugins/inputs/powerdns/powerdns_sample_config.go deleted file mode 100644 index 71409d7acbce9..0000000000000 --- a/plugins/inputs/powerdns/powerdns_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package powerdns - -func (p *Powerdns) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/inputs/powerdns_recursor/README.md b/plugins/inputs/powerdns_recursor/README.md index 0b713859f6cc9..377e1ef0e8ce3 100644 --- a/plugins/inputs/powerdns_recursor/README.md +++ b/plugins/inputs/powerdns_recursor/README.md @@ -5,7 +5,7 @@ the unix controlsocket. ## Configuration -```toml +```toml @sample.conf # Read metrics from one or many PowerDNS Recursor servers [[inputs.powerdns_recursor]] ## Path to the Recursor control socket. diff --git a/plugins/inputs/powerdns_recursor/powerdns_recursor.go b/plugins/inputs/powerdns_recursor/powerdns_recursor.go index ad7cea4ac44a9..f4596c879c986 100644 --- a/plugins/inputs/powerdns_recursor/powerdns_recursor.go +++ b/plugins/inputs/powerdns_recursor/powerdns_recursor.go @@ -1,7 +1,9 @@ +//go:generate ../../../tools/readme_config_includer/generator package powerdns_recursor import ( "bufio" + _ "embed" "errors" "fmt" "math/rand" @@ -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 PowerdnsRecursor struct { UnixSockets []string `toml:"unix_sockets"` SocketDir string `toml:"socket_dir"` @@ -28,6 +34,10 @@ type PowerdnsRecursor struct { var defaultTimeout = 5 * time.Second +func (*PowerdnsRecursor) SampleConfig() string { + return sampleConfig +} + func (p *PowerdnsRecursor) Init() error { if p.SocketMode != "" { mode, err := strconv.ParseUint(p.SocketMode, 8, 32) diff --git a/plugins/inputs/powerdns_recursor/powerdns_recursor_sample_config.go b/plugins/inputs/powerdns_recursor/powerdns_recursor_sample_config.go deleted file mode 100644 index 7f3e28320f334..0000000000000 --- a/plugins/inputs/powerdns_recursor/powerdns_recursor_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package powerdns_recursor - -func (p *PowerdnsRecursor) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/inputs/processes/README.md b/plugins/inputs/processes/README.md index ac561f9361660..6de14cb58c824 100644 --- a/plugins/inputs/processes/README.md +++ b/plugins/inputs/processes/README.md @@ -10,7 +10,7 @@ it requires access to execute `ps`. ## Configuration -```toml +```toml @sample.conf # Get the number of processes and group them by status [[inputs.processes]] # no configuration diff --git a/plugins/inputs/processes/processes.go b/plugins/inputs/processes/processes.go index 5f0a008e08acd..35c778e134221 100644 --- a/plugins/inputs/processes/processes.go +++ b/plugins/inputs/processes/processes.go @@ -1 +1,11 @@ package processes + +import _ "embed" + +// DO NOT REMOVE THE NEXT TWO LINES! This is required to embedd the sampleConfig data. +//go:embed sample.conf +var sampleConfig string + +func (*Processes) SampleConfig() string { + return sampleConfig +} diff --git a/plugins/inputs/processes/processes_notwindows.go b/plugins/inputs/processes/processes_notwindows.go index 070dce65fe2a0..9395d34436238 100644 --- a/plugins/inputs/processes/processes_notwindows.go +++ b/plugins/inputs/processes/processes_notwindows.go @@ -1,3 +1,4 @@ +//go:generate ../../../tools/readme_config_includer/generator //go:build !windows // +build !windows @@ -151,7 +152,7 @@ func (p *Processes) gatherFromProc(fields map[string]interface{}) error { stats := bytes.Fields(data) if len(stats) < 3 { - return fmt.Errorf("Something is terribly wrong with %s", filename) + return fmt.Errorf("something is terribly wrong with %s", filename) } switch stats[0][0] { case 'R': diff --git a/plugins/inputs/processes/processes_sample_config.go b/plugins/inputs/processes/processes_sample_config.go deleted file mode 100644 index 2ee5d74062a48..0000000000000 --- a/plugins/inputs/processes/processes_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package processes - -func (p *Processes) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/inputs/procstat/README.md b/plugins/inputs/procstat/README.md index 5dd673cfd8564..4b447db592652 100644 --- a/plugins/inputs/procstat/README.md +++ b/plugins/inputs/procstat/README.md @@ -16,7 +16,7 @@ Processes can be selected for monitoring using one of several methods: ## Configuration -```toml +```toml @sample.conf # Monitor process cpu and memory usage [[inputs.procstat]] ## PID file to monitor process diff --git a/plugins/inputs/procstat/procstat.go b/plugins/inputs/procstat/procstat.go index e2027053475ed..89226fe306df7 100644 --- a/plugins/inputs/procstat/procstat.go +++ b/plugins/inputs/procstat/procstat.go @@ -1,7 +1,9 @@ +//go:generate ../../../tools/readme_config_includer/generator package procstat import ( "bytes" + _ "embed" "fmt" "os" "os/exec" @@ -11,11 +13,16 @@ import ( "strings" "time" + "github.com/shirou/gopsutil/v3/process" + "github.com/influxdata/telegraf" "github.com/influxdata/telegraf/plugins/inputs" - "github.com/shirou/gopsutil/v3/process" ) +// DO NOT REMOVE THE NEXT TWO LINES! This is required to embedd the sampleConfig data. +//go:embed sample.conf +var sampleConfig string + var ( defaultPIDFinder = NewPgrep defaultProcess = NewProc @@ -54,6 +61,10 @@ type PidsTags struct { Err error } +func (*Procstat) SampleConfig() string { + return sampleConfig +} + func (p *Procstat) Gather(acc telegraf.Accumulator) error { if p.createPIDFinder == nil { switch p.PidFinder { diff --git a/plugins/inputs/procstat/procstat_sample_config.go b/plugins/inputs/procstat/procstat_sample_config.go deleted file mode 100644 index ae39ee2ba97f9..0000000000000 --- a/plugins/inputs/procstat/procstat_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package procstat - -func (p *Procstat) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/inputs/prometheus/README.md b/plugins/inputs/prometheus/README.md index 074994620cf12..b1c2b382ba8ee 100644 --- a/plugins/inputs/prometheus/README.md +++ b/plugins/inputs/prometheus/README.md @@ -5,7 +5,7 @@ in Prometheus format. ## Configuration -```toml +```toml @sample.conf # Read metrics from one or many prometheus clients [[inputs.prometheus]] ## An array of urls to scrape metrics from. diff --git a/plugins/inputs/prometheus/prometheus.go b/plugins/inputs/prometheus/prometheus.go index 28a934a3e63f2..2d04a30814c3d 100644 --- a/plugins/inputs/prometheus/prometheus.go +++ b/plugins/inputs/prometheus/prometheus.go @@ -1,7 +1,9 @@ +//go:generate ../../../tools/readme_config_includer/generator package prometheus import ( "context" + _ "embed" "errors" "fmt" "io" @@ -24,6 +26,10 @@ import ( parserV2 "github.com/influxdata/telegraf/plugins/parsers/prometheus" ) +// DO NOT REMOVE THE NEXT TWO LINES! This is required to embedd the sampleConfig data. +//go:embed sample.conf +var sampleConfig string + const acceptHeader = `application/vnd.google.protobuf;proto=io.prometheus.client.MetricFamily;encoding=delimited;q=0.7,text/plain;version=0.0.4;q=0.3` type Prometheus struct { @@ -91,6 +97,10 @@ type Prometheus struct { consulServices map[string]URLAndAddress } +func (*Prometheus) SampleConfig() string { + return sampleConfig +} + func (p *Prometheus) Init() error { // Config processing for node scrape scope for monitor_kubernetes_pods p.isNodeScrapeScope = strings.EqualFold(p.PodScrapeScope, "node") diff --git a/plugins/inputs/prometheus/prometheus_sample_config.go b/plugins/inputs/prometheus/prometheus_sample_config.go deleted file mode 100644 index b5811d89583ac..0000000000000 --- a/plugins/inputs/prometheus/prometheus_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package prometheus - -func (p *Prometheus) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/inputs/proxmox/README.md b/plugins/inputs/proxmox/README.md index 9387474507a30..0ca6f5b6ea8df 100644 --- a/plugins/inputs/proxmox/README.md +++ b/plugins/inputs/proxmox/README.md @@ -6,7 +6,7 @@ Telegraf minimum version: Telegraf 1.16.0 ## Configuration -```toml +```toml @sample.conf # Provides metrics from Proxmox nodes (Proxmox Virtual Environment > 6.2). [[inputs.proxmox]] ## API connection configuration. The API token was introduced in Proxmox v6.2. Required permissions for user and token: PVEAuditor role on /. diff --git a/plugins/inputs/proxmox/proxmox.go b/plugins/inputs/proxmox/proxmox.go index f4d9d2be9ad0f..e85f7f3f80820 100644 --- a/plugins/inputs/proxmox/proxmox.go +++ b/plugins/inputs/proxmox/proxmox.go @@ -1,6 +1,8 @@ +//go:generate ../../../tools/readme_config_includer/generator package proxmox import ( + _ "embed" "encoding/json" "errors" "io" @@ -14,6 +16,14 @@ 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 + +func (*Proxmox) SampleConfig() string { + return sampleConfig +} + func (px *Proxmox) Gather(acc telegraf.Accumulator) error { err := getNodeSearchDomain(px) if err != nil { diff --git a/plugins/inputs/proxmox/proxmox_sample_config.go b/plugins/inputs/proxmox/proxmox_sample_config.go deleted file mode 100644 index 9b832a557536b..0000000000000 --- a/plugins/inputs/proxmox/proxmox_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package proxmox - -func (px *Proxmox) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/inputs/puppetagent/README.md b/plugins/inputs/puppetagent/README.md index 153dfc9efcede..df18a5d57e312 100644 --- a/plugins/inputs/puppetagent/README.md +++ b/plugins/inputs/puppetagent/README.md @@ -79,7 +79,7 @@ jcross@pit-devops-02 ~ >sudo ./telegraf_linux_amd64 --input-filter puppetagent - ## Configuration -```toml +```toml @sample.conf # Reads last_run_summary.yaml file and converts to measurements [[inputs.puppetagent]] ## Location of puppet last run summary file diff --git a/plugins/inputs/puppetagent/puppetagent.go b/plugins/inputs/puppetagent/puppetagent.go index 712498e91d786..f22c7ccd2e869 100644 --- a/plugins/inputs/puppetagent/puppetagent.go +++ b/plugins/inputs/puppetagent/puppetagent.go @@ -1,6 +1,8 @@ +//go:generate ../../../tools/readme_config_includer/generator package puppetagent import ( + _ "embed" "fmt" "os" "reflect" @@ -12,6 +14,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 + // PuppetAgent is a PuppetAgent plugin type PuppetAgent struct { Location string @@ -77,6 +83,10 @@ type version struct { Puppet string `yaml:"puppet"` } +func (*PuppetAgent) SampleConfig() string { + return sampleConfig +} + // Gather reads stats from all configured servers accumulates stats func (pa *PuppetAgent) Gather(acc telegraf.Accumulator) error { if len(pa.Location) == 0 { diff --git a/plugins/inputs/puppetagent/puppetagent_sample_config.go b/plugins/inputs/puppetagent/puppetagent_sample_config.go deleted file mode 100644 index 0de8ef4fe2fb1..0000000000000 --- a/plugins/inputs/puppetagent/puppetagent_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package puppetagent - -func (pa *PuppetAgent) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/inputs/rabbitmq/README.md b/plugins/inputs/rabbitmq/README.md index 2205a1e5728b0..275637b88ce40 100644 --- a/plugins/inputs/rabbitmq/README.md +++ b/plugins/inputs/rabbitmq/README.md @@ -9,7 +9,7 @@ For additional details reference the [RabbitMQ Management HTTP Stats][management ## Configuration -```toml +```toml @sample.conf # Reads metrics from RabbitMQ servers via the Management Plugin [[inputs.rabbitmq]] ## Management Plugin url. (default: http://localhost:15672) diff --git a/plugins/inputs/rabbitmq/rabbitmq.go b/plugins/inputs/rabbitmq/rabbitmq.go index c7fe985664db4..1958eb28cf75c 100644 --- a/plugins/inputs/rabbitmq/rabbitmq.go +++ b/plugins/inputs/rabbitmq/rabbitmq.go @@ -1,6 +1,8 @@ +//go:generate ../../../tools/readme_config_includer/generator package rabbitmq import ( + _ "embed" "encoding/json" "fmt" "io" @@ -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 + // DefaultUsername will set a default value that corresponds to the default // value used by Rabbitmq const DefaultUsername = "guest" @@ -276,6 +282,10 @@ func boolToInt(b bool) int64 { return 0 } +func (*RabbitMQ) SampleConfig() string { + return sampleConfig +} + func (r *RabbitMQ) Init() error { var err error diff --git a/plugins/inputs/rabbitmq/rabbitmq_sample_config.go b/plugins/inputs/rabbitmq/rabbitmq_sample_config.go deleted file mode 100644 index 0a147aaaa26a1..0000000000000 --- a/plugins/inputs/rabbitmq/rabbitmq_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package rabbitmq - -func (r *RabbitMQ) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/inputs/raindrops/README.md b/plugins/inputs/raindrops/README.md index 0e06fa1eefaa6..13079b88e8e7c 100644 --- a/plugins/inputs/raindrops/README.md +++ b/plugins/inputs/raindrops/README.md @@ -5,7 +5,7 @@ specified raindops [middleware](http://raindrops.bogomips.org/Raindrops/Middlewa ## Configuration -```toml +```toml @sample.conf # Read raindrops stats (raindrops - real-time stats for preforking Rack servers) [[inputs.raindrops]] ## An array of raindrops middleware URI to gather stats. diff --git a/plugins/inputs/raindrops/raindrops.go b/plugins/inputs/raindrops/raindrops.go index 4084602cec6f9..cb815b01f353b 100644 --- a/plugins/inputs/raindrops/raindrops.go +++ b/plugins/inputs/raindrops/raindrops.go @@ -1,7 +1,9 @@ +//go:generate ../../../tools/readme_config_includer/generator package raindrops import ( "bufio" + _ "embed" "fmt" "net" "net/http" @@ -15,11 +17,19 @@ 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 Raindrops struct { Urls []string httpClient *http.Client } +func (*Raindrops) SampleConfig() string { + return sampleConfig +} + func (r *Raindrops) Gather(acc telegraf.Accumulator) error { var wg sync.WaitGroup diff --git a/plugins/inputs/raindrops/raindrops_sample_config.go b/plugins/inputs/raindrops/raindrops_sample_config.go deleted file mode 100644 index e09b38f04a89c..0000000000000 --- a/plugins/inputs/raindrops/raindrops_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package raindrops - -func (r *Raindrops) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/inputs/ras/README.md b/plugins/inputs/ras/README.md index beb65f0560f55..b405681db7589 100644 --- a/plugins/inputs/ras/README.md +++ b/plugins/inputs/ras/README.md @@ -6,7 +6,7 @@ The `RAS` plugin gathers and counts errors provided by [RASDaemon](https://githu ## Configuration -```toml +```toml @sample.conf # RAS plugin exposes counter metrics for Machine Check Errors provided by RASDaemon (sqlite3 output is required). [[inputs.ras]] ## Optional path to RASDaemon sqlite3 database. diff --git a/plugins/inputs/ras/ras.go b/plugins/inputs/ras/ras.go index 1f83c1aaa9312..cc4f3969f4bc2 100644 --- a/plugins/inputs/ras/ras.go +++ b/plugins/inputs/ras/ras.go @@ -1,3 +1,4 @@ +//go:generate ../../../tools/readme_config_includer/generator //go:build linux && (386 || amd64 || arm || arm64) // +build linux // +build 386 amd64 arm arm64 @@ -6,18 +7,24 @@ package ras import ( "database/sql" + _ "embed" "fmt" "os" "strconv" "strings" "time" - _ "modernc.org/sqlite" //to register SQLite driver + // Required for SQL framework driver + _ "modernc.org/sqlite" "github.com/influxdata/telegraf" "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 + // Ras plugin gathers and counts errors provided by RASDaemon type Ras struct { DBPath string `toml:"db_path"` @@ -68,6 +75,10 @@ const ( unclassifiedMCEBase = "unclassified_mce_errors" ) +func (*Ras) SampleConfig() string { + return sampleConfig +} + // Start initializes connection to DB, metrics are gathered in Gather func (r *Ras) Start(telegraf.Accumulator) error { err := validateDbPath(r.DBPath) diff --git a/plugins/inputs/ras/ras_sample_config.go b/plugins/inputs/ras/ras_sample_config.go deleted file mode 100644 index de986d86b1bd7..0000000000000 --- a/plugins/inputs/ras/ras_sample_config.go +++ /dev/null @@ -1,12 +0,0 @@ -//go:build linux && (386 || amd64 || arm || arm64) -// +build linux -// +build 386 amd64 arm arm64 - -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package ras - -func (r *Ras) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/inputs/ravendb/README.md b/plugins/inputs/ravendb/README.md index 978416162682b..e54453cade575 100644 --- a/plugins/inputs/ravendb/README.md +++ b/plugins/inputs/ravendb/README.md @@ -8,7 +8,7 @@ Requires RavenDB Server 5.2+. The following is an example config for RavenDB. **Note:** The client certificate used should have `Operator` permissions on the cluster. -```toml +```toml @sample.conf # Reads metrics from RavenDB servers via the Monitoring Endpoints [[inputs.ravendb]] ## Node URL and port that RavenDB is listening on. By default, diff --git a/plugins/inputs/ravendb/ravendb.go b/plugins/inputs/ravendb/ravendb.go index 594c453dcb288..e19a9a4ca71fc 100644 --- a/plugins/inputs/ravendb/ravendb.go +++ b/plugins/inputs/ravendb/ravendb.go @@ -1,6 +1,8 @@ +//go:generate ../../../tools/readme_config_includer/generator package ravendb import ( + _ "embed" "encoding/json" "fmt" "net/http" @@ -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 + // defaultURL will set a default value that corresponds to the default value // used by RavenDB const defaultURL = "http://localhost:8080" @@ -46,6 +52,10 @@ type RavenDB struct { requestURLCollection string } +func (*RavenDB) SampleConfig() string { + return sampleConfig +} + func (r *RavenDB) Gather(acc telegraf.Accumulator) error { var wg sync.WaitGroup diff --git a/plugins/inputs/ravendb/ravendb_sample_config.go b/plugins/inputs/ravendb/ravendb_sample_config.go deleted file mode 100644 index c709d3f089528..0000000000000 --- a/plugins/inputs/ravendb/ravendb_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package ravendb - -func (r *RavenDB) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/inputs/redfish/README.md b/plugins/inputs/redfish/README.md index bf106b9738dbc..7115cada7c0df 100644 --- a/plugins/inputs/redfish/README.md +++ b/plugins/inputs/redfish/README.md @@ -6,7 +6,7 @@ Telegraf minimum version: Telegraf 1.15.0 ## Configuration -```toml +```toml @sample.conf # Read CPU, Fans, Powersupply and Voltage metrics of hardware server through redfish APIs [[inputs.redfish]] ## Redfish API Base URL. diff --git a/plugins/inputs/redfish/redfish.go b/plugins/inputs/redfish/redfish.go index abf1d65e2d561..9fcfe4f303f15 100644 --- a/plugins/inputs/redfish/redfish.go +++ b/plugins/inputs/redfish/redfish.go @@ -1,6 +1,8 @@ +//go:generate ../../../tools/readme_config_includer/generator package redfish import ( + _ "embed" "encoding/json" "fmt" "io" @@ -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 Redfish struct { Address string `toml:"address"` Username string `toml:"username"` @@ -110,6 +116,10 @@ type Status struct { Health string } +func (*Redfish) SampleConfig() string { + return sampleConfig +} + func (r *Redfish) Init() error { if r.Address == "" { return fmt.Errorf("did not provide IP") diff --git a/plugins/inputs/redfish/redfish_sample_config.go b/plugins/inputs/redfish/redfish_sample_config.go deleted file mode 100644 index d1be463cb8f3b..0000000000000 --- a/plugins/inputs/redfish/redfish_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package redfish - -func (r *Redfish) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/inputs/redis/README.md b/plugins/inputs/redis/README.md index 63aac629c1ce2..9e3a790aed02e 100644 --- a/plugins/inputs/redis/README.md +++ b/plugins/inputs/redis/README.md @@ -2,7 +2,7 @@ ## Configuration -```toml +```toml @sample.conf # Read metrics from one or many redis servers [[inputs.redis]] ## specify servers via a url matching: diff --git a/plugins/inputs/redis/redis.go b/plugins/inputs/redis/redis.go index d65724d3d9c7a..7bbb0bf4d5037 100644 --- a/plugins/inputs/redis/redis.go +++ b/plugins/inputs/redis/redis.go @@ -1,7 +1,9 @@ +//go:generate ../../../tools/readme_config_includer/generator package redis import ( "bufio" + _ "embed" "fmt" "io" "net/url" @@ -13,11 +15,16 @@ import ( "time" "github.com/go-redis/redis" + "github.com/influxdata/telegraf" "github.com/influxdata/telegraf/plugins/common/tls" "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 RedisCommand struct { Command []interface{} Field string @@ -193,6 +200,10 @@ var Tracking = map[string]string{ "role": "replication_role", } +func (*Redis) SampleConfig() string { + return sampleConfig +} + func (r *Redis) Init() error { for _, command := range r.Commands { if command.Type != "string" && command.Type != "integer" && command.Type != "float" { diff --git a/plugins/inputs/redis/redis_sample_config.go b/plugins/inputs/redis/redis_sample_config.go deleted file mode 100644 index 8039df2f3fd5d..0000000000000 --- a/plugins/inputs/redis/redis_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package redis - -func (r *Redis) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/inputs/redis_sentinel/README.md b/plugins/inputs/redis_sentinel/README.md index 793e68df5c42e..cea0a5659c243 100644 --- a/plugins/inputs/redis_sentinel/README.md +++ b/plugins/inputs/redis_sentinel/README.md @@ -5,7 +5,7 @@ monitoring multiple Redis servers and replicas. ## Configuration -```toml +```toml @sample.conf # Read metrics from one or many redis-sentinel servers [[inputs.redis_sentinel]] ## specify servers via a url matching: diff --git a/plugins/inputs/redis_sentinel/redis_sentinel.go b/plugins/inputs/redis_sentinel/redis_sentinel.go index b425fcd94d3b1..0a4f0fe84074e 100644 --- a/plugins/inputs/redis_sentinel/redis_sentinel.go +++ b/plugins/inputs/redis_sentinel/redis_sentinel.go @@ -1,7 +1,9 @@ +//go:generate ../../../tools/readme_config_includer/generator package redis_sentinel import ( "bufio" + _ "embed" "fmt" "io" "net/url" @@ -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 RedisSentinel struct { Servers []string `toml:"servers"` tls.ClientConfig @@ -39,6 +45,10 @@ func init() { }) } +func (*RedisSentinel) SampleConfig() string { + return sampleConfig +} + func (r *RedisSentinel) Init() error { if len(r.Servers) == 0 { r.Servers = []string{"tcp://localhost:26379"} diff --git a/plugins/inputs/redis_sentinel/redis_sentinel_sample_config.go b/plugins/inputs/redis_sentinel/redis_sentinel_sample_config.go deleted file mode 100644 index 69003d726acae..0000000000000 --- a/plugins/inputs/redis_sentinel/redis_sentinel_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package redis_sentinel - -func (r *RedisSentinel) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/inputs/rethinkdb/README.md b/plugins/inputs/rethinkdb/README.md index 3368d5c899a56..7fae3958575c5 100644 --- a/plugins/inputs/rethinkdb/README.md +++ b/plugins/inputs/rethinkdb/README.md @@ -7,7 +7,7 @@ Collect metrics from [RethinkDB](https://www.rethinkdb.com/). This section contains the default TOML to configure the plugin. You can generate it using `telegraf --usage rethinkdb`. -```toml +```toml @sample.conf # Read metrics from one or many RethinkDB servers [[inputs.rethinkdb]] ## An array of URI to gather stats about. Specify an ip or hostname diff --git a/plugins/inputs/rethinkdb/rethinkdb.go b/plugins/inputs/rethinkdb/rethinkdb.go index 8cab237213818..cf9fbe9ba8780 100644 --- a/plugins/inputs/rethinkdb/rethinkdb.go +++ b/plugins/inputs/rethinkdb/rethinkdb.go @@ -1,22 +1,32 @@ +//go:generate ../../../tools/readme_config_includer/generator package rethinkdb import ( + _ "embed" "fmt" "net/url" "sync" + "gopkg.in/gorethink/gorethink.v3" + "github.com/influxdata/telegraf" "github.com/influxdata/telegraf/plugins/inputs" - - "gopkg.in/gorethink/gorethink.v3" ) +// DO NOT REMOVE THE NEXT TWO LINES! This is required to embedd the sampleConfig data. +//go:embed sample.conf +var sampleConfig string + type RethinkDB struct { Servers []string } var localhost = &Server{URL: &url.URL{Host: "127.0.0.1:28015"}} +func (*RethinkDB) SampleConfig() string { + return sampleConfig +} + // Reads stats from all configured servers accumulates stats. // Returns one of the errors encountered while gather stats (if any). func (r *RethinkDB) Gather(acc telegraf.Accumulator) error { diff --git a/plugins/inputs/rethinkdb/rethinkdb_sample_config.go b/plugins/inputs/rethinkdb/rethinkdb_sample_config.go deleted file mode 100644 index 5386eb0622a17..0000000000000 --- a/plugins/inputs/rethinkdb/rethinkdb_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package rethinkdb - -func (r *RethinkDB) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/inputs/riak/README.md b/plugins/inputs/riak/README.md index 7a7d682bfc7da..00ba1bd8e8406 100644 --- a/plugins/inputs/riak/README.md +++ b/plugins/inputs/riak/README.md @@ -4,7 +4,7 @@ The Riak plugin gathers metrics from one or more riak instances. ## Configuration -```toml +```toml @sample.conf # Read metrics one or many Riak servers [[inputs.riak]] # Specify a list of one or more riak http servers diff --git a/plugins/inputs/riak/riak.go b/plugins/inputs/riak/riak.go index c67cf4faae85e..2bc1b30813856 100644 --- a/plugins/inputs/riak/riak.go +++ b/plugins/inputs/riak/riak.go @@ -1,6 +1,8 @@ +//go:generate ../../../tools/readme_config_includer/generator package riak import ( + _ "embed" "encoding/json" "fmt" "net/http" @@ -11,6 +13,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 Riak gathers statistics from one or more Riak instances type Riak struct { // Servers is a slice of servers as http addresses (ex. http://127.0.0.1:8098) @@ -79,6 +85,10 @@ type riakStats struct { ReadRepairsTotal int64 `json:"read_repairs_total"` } +func (*Riak) SampleConfig() string { + return sampleConfig +} + // Reads stats from all configured servers. func (r *Riak) Gather(acc telegraf.Accumulator) error { // Default to a single server at localhost (default port) if none specified diff --git a/plugins/inputs/riak/riak_sample_config.go b/plugins/inputs/riak/riak_sample_config.go deleted file mode 100644 index aa7730eab5fbb..0000000000000 --- a/plugins/inputs/riak/riak_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package riak - -func (r *Riak) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/inputs/riemann_listener/README.md b/plugins/inputs/riemann_listener/README.md index 338bac2bc958d..5407f63ff1439 100644 --- a/plugins/inputs/riemann_listener/README.md +++ b/plugins/inputs/riemann_listener/README.md @@ -7,7 +7,7 @@ client that use riemann clients using riemann-protobuff format. This is a sample configuration for the plugin. -```toml +```toml @sample.conf # Riemann protobuff listener [[inputs.rimann_listener]] ## URL to listen on diff --git a/plugins/inputs/riemann_listener/riemann_listener.go b/plugins/inputs/riemann_listener/riemann_listener.go index 1f2290ad2b903..880b9ede532ff 100644 --- a/plugins/inputs/riemann_listener/riemann_listener.go +++ b/plugins/inputs/riemann_listener/riemann_listener.go @@ -1,9 +1,11 @@ +//go:generate ../../../tools/readme_config_includer/generator package riemann_listener import ( "bytes" "context" "crypto/tls" + _ "embed" "encoding/binary" "fmt" "io" @@ -25,6 +27,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 RiemannSocketListener struct { ServiceAddress string `toml:"service_address"` MaxConnections int `toml:"max_connections"` @@ -265,6 +271,10 @@ func (rsl *riemannListener) riemannReturnErrorResponse(conn net.Conn, errorMessa } } +func (*RiemannSocketListener) SampleConfig() string { + return sampleConfig +} + func (rsl *RiemannSocketListener) Gather(_ telegraf.Accumulator) error { return nil } diff --git a/plugins/inputs/riemann_listener/riemann_listener_sample_config.go b/plugins/inputs/riemann_listener/riemann_listener_sample_config.go deleted file mode 100644 index d6930162d2c41..0000000000000 --- a/plugins/inputs/riemann_listener/riemann_listener_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package riemann_listener - -func (rsl *RiemannSocketListener) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/inputs/salesforce/README.md b/plugins/inputs/salesforce/README.md index b0bebf68f16ff..69210322faadc 100644 --- a/plugins/inputs/salesforce/README.md +++ b/plugins/inputs/salesforce/README.md @@ -5,7 +5,7 @@ It fetches its data from the [limits endpoint](https://developer.salesforce.com/ ## Configuration -```toml +```toml @sample.conf # Read API usage and limits for a Salesforce organisation [[inputs.salesforce]] ## specify your credentials diff --git a/plugins/inputs/salesforce/salesforce.go b/plugins/inputs/salesforce/salesforce.go index fd6922eb27864..079b45c263f0f 100644 --- a/plugins/inputs/salesforce/salesforce.go +++ b/plugins/inputs/salesforce/salesforce.go @@ -1,6 +1,8 @@ +//go:generate ../../../tools/readme_config_includer/generator package salesforce import ( + _ "embed" "encoding/json" "encoding/xml" "errors" @@ -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 limit struct { Max int Remaining int @@ -54,6 +60,10 @@ func NewSalesforce() *Salesforce { Environment: defaultEnvironment} } +func (*Salesforce) SampleConfig() string { + return sampleConfig +} + // Reads limits values from Salesforce API func (s *Salesforce) Gather(acc telegraf.Accumulator) error { limits, err := s.fetchLimits() diff --git a/plugins/inputs/salesforce/salesforce_sample_config.go b/plugins/inputs/salesforce/salesforce_sample_config.go deleted file mode 100644 index 83ae1c520e3e3..0000000000000 --- a/plugins/inputs/salesforce/salesforce_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package salesforce - -func (s *Salesforce) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/inputs/sensors/README.md b/plugins/inputs/sensors/README.md index 9de12f588b556..980a2e46f349a 100644 --- a/plugins/inputs/sensors/README.md +++ b/plugins/inputs/sensors/README.md @@ -7,7 +7,7 @@ This plugin collects sensor metrics with the `sensors` executable from the lm-se ## Configuration -```toml +```toml @sample.conf # Monitor sensors, requires lm-sensors package [[inputs.sensors]] ## Remove numbers from field names. diff --git a/plugins/inputs/sensors/sensors.go b/plugins/inputs/sensors/sensors.go index d73c543e9ef58..b9c4f9fd0d083 100644 --- a/plugins/inputs/sensors/sensors.go +++ b/plugins/inputs/sensors/sensors.go @@ -1,9 +1,11 @@ +//go:generate ../../../tools/readme_config_includer/generator //go:build linux // +build linux package sensors import ( + _ "embed" "errors" "fmt" "os/exec" @@ -18,6 +20,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 + var ( execCommand = exec.Command // execCommand is used to mock commands in tests. numberRegp = regexp.MustCompile("[0-9]+") @@ -30,6 +36,30 @@ type Sensors struct { path string } +const cmd = "sensors" + +func (*Sensors) SampleConfig() string { + return sampleConfig +} + +func (s *Sensors) Init() error { + // Set defaults + if s.path == "" { + path, err := exec.LookPath(cmd) + if err != nil { + return fmt.Errorf("looking up %q failed: %v", cmd, err) + } + s.path = path + } + + // Check parameters + if s.path == "" { + return fmt.Errorf("no path specified for %q", cmd) + } + + return nil +} + func (s *Sensors) Gather(acc telegraf.Accumulator) error { if len(s.path) == 0 { return errors.New("sensors not found: verify that lm-sensors package is installed and that sensors is in your PATH") @@ -96,15 +126,10 @@ func snake(input string) string { } func init() { - s := Sensors{ - RemoveNumbers: true, - Timeout: defaultTimeout, - } - path, _ := exec.LookPath("sensors") - if len(path) > 0 { - s.path = path - } inputs.Add("sensors", func() telegraf.Input { - return &s + return &Sensors{ + RemoveNumbers: true, + Timeout: defaultTimeout, + } }) } diff --git a/plugins/inputs/sensors/sensors_sample_config.go b/plugins/inputs/sensors/sensors_sample_config.go deleted file mode 100644 index aadc20de8f9c9..0000000000000 --- a/plugins/inputs/sensors/sensors_sample_config.go +++ /dev/null @@ -1,11 +0,0 @@ -//go:build linux -// +build linux - -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package sensors - -func (*Sensors) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/inputs/sensors/sensors_test.go b/plugins/inputs/sensors/sensors_test.go index fe1d62ceceeb0..ac2bf498ed8e1 100644 --- a/plugins/inputs/sensors/sensors_test.go +++ b/plugins/inputs/sensors/sensors_test.go @@ -25,6 +25,7 @@ func TestGatherDefault(t *testing.T) { defer func() { execCommand = exec.Command }() var acc testutil.Accumulator + require.NoError(t, s.Init()) require.NoError(t, s.Gather(&acc)) var tests = []struct { @@ -163,6 +164,7 @@ func TestGatherNotRemoveNumbers(t *testing.T) { defer func() { execCommand = exec.Command }() var acc testutil.Accumulator + require.NoError(t, s.Init()) require.NoError(t, s.Gather(&acc)) var tests = []struct { diff --git a/plugins/inputs/sflow/README.md b/plugins/inputs/sflow/README.md index 9da3723d15df4..2371590fbbaca 100644 --- a/plugins/inputs/sflow/README.md +++ b/plugins/inputs/sflow/README.md @@ -20,7 +20,7 @@ avoid cardinality issues: ## Configuration -```toml +```toml @sample.conf # SFlow V5 Protocol Listener [[inputs.sflow]] ## Address to listen for sFlow packets. diff --git a/plugins/inputs/sflow/sflow.go b/plugins/inputs/sflow/sflow.go index 7579b34571919..4f342ff7d8de9 100644 --- a/plugins/inputs/sflow/sflow.go +++ b/plugins/inputs/sflow/sflow.go @@ -1,7 +1,9 @@ +//go:generate ../../../tools/readme_config_includer/generator package sflow import ( "bytes" + _ "embed" "fmt" "io" "net" @@ -14,6 +16,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 + const ( maxPacketSize = 64 * 1024 ) @@ -30,6 +36,10 @@ type SFlow struct { wg sync.WaitGroup } +func (*SFlow) SampleConfig() string { + return sampleConfig +} + func (s *SFlow) Init() error { s.decoder = NewDecoder() s.decoder.Log = s.Log diff --git a/plugins/inputs/sflow/sflow_sample_config.go b/plugins/inputs/sflow/sflow_sample_config.go deleted file mode 100644 index 92a18f8f17a5c..0000000000000 --- a/plugins/inputs/sflow/sflow_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package sflow - -func (s *SFlow) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/inputs/smart/README.md b/plugins/inputs/smart/README.md index 3fb37c396f9b5..5a9df0b01dfac 100644 --- a/plugins/inputs/smart/README.md +++ b/plugins/inputs/smart/README.md @@ -70,7 +70,7 @@ smartctl --scan -d nvme ## Configuration -```toml +```toml @sample.conf # Read metrics from storage devices supporting S.M.A.R.T. [[inputs.smart]] ## Optionally specify the path to the smartctl executable @@ -208,9 +208,9 @@ smartctl or nvme-cli. ## Device Names -Device names, e.g., `/dev/sda`, are *not persistent*, and may be +Device names, e.g., `/dev/sda`, are _not persistent_, and may be subject to change across reboots or system changes. Instead, you can use the -*World Wide Name* (WWN) or serial number to identify devices. On Linux block +_World Wide Name_ (WWN) or serial number to identify devices. On Linux block devices can be referenced by the WWN in the following location: `/dev/disk/by-id/`. diff --git a/plugins/inputs/smart/smart.go b/plugins/inputs/smart/smart.go index 383fca60d4321..5c59e79224820 100644 --- a/plugins/inputs/smart/smart.go +++ b/plugins/inputs/smart/smart.go @@ -1,7 +1,9 @@ +//go:generate ../../../tools/readme_config_includer/generator package smart import ( "bufio" + _ "embed" "fmt" "os" "os/exec" @@ -19,6 +21,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 + const intelVID = "0x8086" var ( @@ -354,6 +360,10 @@ func newSmart() *Smart { } } +func (*Smart) SampleConfig() string { + return sampleConfig +} + // Init performs one time setup of the plugin and returns an error if the configuration is invalid. func (m *Smart) Init() error { //if deprecated `path` (to smartctl binary) is provided in config and `path_smartctl` override does not exist diff --git a/plugins/inputs/smart/smart_sample_config.go b/plugins/inputs/smart/smart_sample_config.go deleted file mode 100644 index 4d4f1fb568012..0000000000000 --- a/plugins/inputs/smart/smart_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package smart - -func (m *Smart) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/inputs/snmp/README.md b/plugins/inputs/snmp/README.md index a517e510690ff..e7ac1583e0d74 100644 --- a/plugins/inputs/snmp/README.md +++ b/plugins/inputs/snmp/README.md @@ -11,7 +11,7 @@ path onto the global path variable ## Configuration -```toml +```toml @sample.conf # Retrieves SNMP values from remote agents [[inputs.snmp]] ## Agent addresses to retrieve values from. diff --git a/plugins/inputs/snmp/snmp.go b/plugins/inputs/snmp/snmp.go index eecc4ec47b12e..aab01fc32d4b9 100644 --- a/plugins/inputs/snmp/snmp.go +++ b/plugins/inputs/snmp/snmp.go @@ -1,6 +1,8 @@ +//go:generate ../../../tools/readme_config_includer/generator package snmp import ( + _ "embed" "encoding/binary" "errors" "fmt" @@ -19,6 +21,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 Translator interface { SnmpTranslate(oid string) ( mibName string, oidNum string, oidText string, @@ -63,6 +69,10 @@ func (s *Snmp) SetTranslator(name string) { s.Translator = name } +func (*Snmp) SampleConfig() string { + return sampleConfig +} + func (s *Snmp) Init() error { var err error switch s.Translator { @@ -291,22 +301,6 @@ func (e *walkError) Unwrap() error { return e.err } -func init() { - inputs.Add("snmp", func() telegraf.Input { - return &Snmp{ - Name: "snmp", - ClientConfig: snmp.ClientConfig{ - Retries: 3, - MaxRepetitions: 10, - Timeout: config.Duration(5 * time.Second), - Version: 2, - Path: []string{"/usr/share/snmp/mibs"}, - Community: "public", - }, - } - }) -} - // Gather retrieves all the configured fields and tables. // Any error encountered does not halt the process. The errors are accumulated // and returned at the end. @@ -756,3 +750,19 @@ func fieldConvert(conv string, v interface{}) (interface{}, error) { return nil, fmt.Errorf("invalid conversion type '%s'", conv) } + +func init() { + inputs.Add("snmp", func() telegraf.Input { + return &Snmp{ + Name: "snmp", + ClientConfig: snmp.ClientConfig{ + Retries: 3, + MaxRepetitions: 10, + Timeout: config.Duration(5 * time.Second), + Version: 2, + Path: []string{"/usr/share/snmp/mibs"}, + Community: "public", + }, + } + }) +} diff --git a/plugins/inputs/snmp/snmp_sample_config.go b/plugins/inputs/snmp/snmp_sample_config.go deleted file mode 100644 index 77f9a1e68044d..0000000000000 --- a/plugins/inputs/snmp/snmp_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package snmp - -func (s *Snmp) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/inputs/snmp_legacy/README.md b/plugins/inputs/snmp_legacy/README.md index 0afa64d45da24..88e9ab0bbd3e5 100644 --- a/plugins/inputs/snmp_legacy/README.md +++ b/plugins/inputs/snmp_legacy/README.md @@ -10,7 +10,7 @@ In this example, the plugin will gather value of OIDS: - `.1.3.6.1.2.1.2.2.1.4.1` -```toml +```toml @sample.conf # DEPRECATED! PLEASE USE inputs.snmp INSTEAD. [[inputs.snmp_legacy]] ## Use 'oids.txt' file to translate oids to names diff --git a/plugins/inputs/snmp_legacy/snmp_legacy.go b/plugins/inputs/snmp_legacy/snmp_legacy.go index 9071b7ee6c4c7..2ef000239e989 100644 --- a/plugins/inputs/snmp_legacy/snmp_legacy.go +++ b/plugins/inputs/snmp_legacy/snmp_legacy.go @@ -1,6 +1,8 @@ +//go:generate ../../../tools/readme_config_includer/generator package snmp_legacy import ( + _ "embed" "log" "net" "os" @@ -14,6 +16,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 + // Snmp is a snmp plugin type Snmp struct { Host []Host @@ -164,6 +170,10 @@ func findNodeName(node Node, ids []string) (oidName string, instance string) { return node.name, "" } +func (*Snmp) SampleConfig() string { + return sampleConfig +} + func (s *Snmp) Gather(acc telegraf.Accumulator) error { // TODO put this in cache on first run // Create subtables mapping diff --git a/plugins/inputs/snmp_legacy/snmp_legacy_sample_config.go b/plugins/inputs/snmp_legacy/snmp_legacy_sample_config.go deleted file mode 100644 index 8ec292634e607..0000000000000 --- a/plugins/inputs/snmp_legacy/snmp_legacy_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package snmp_legacy - -func (s *Snmp) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/inputs/snmp_trap/README.md b/plugins/inputs/snmp_trap/README.md index d57822050e948..4aa69fdd3517b 100644 --- a/plugins/inputs/snmp_trap/README.md +++ b/plugins/inputs/snmp_trap/README.md @@ -13,7 +13,7 @@ path onto the global path variable ## Configuration -```toml +```toml @sample.conf # Receive SNMP traps [[inputs.snmp_trap]] ## Transport, local address, and port to listen on. Transport must diff --git a/plugins/inputs/snmp_trap/snmp_trap.go b/plugins/inputs/snmp_trap/snmp_trap.go index 94d46ef9e1b4d..d0e4094a42e4d 100644 --- a/plugins/inputs/snmp_trap/snmp_trap.go +++ b/plugins/inputs/snmp_trap/snmp_trap.go @@ -1,20 +1,26 @@ +//go:generate ../../../tools/readme_config_includer/generator package snmp_trap import ( + _ "embed" "fmt" "net" "strconv" "strings" "time" + "github.com/gosnmp/gosnmp" + "github.com/influxdata/telegraf" "github.com/influxdata/telegraf/config" "github.com/influxdata/telegraf/internal/snmp" "github.com/influxdata/telegraf/plugins/inputs" - - "github.com/gosnmp/gosnmp" ) +// DO NOT REMOVE THE NEXT TWO LINES! This is required to embedd the sampleConfig data. +//go:embed sample.conf +var sampleConfig string + type translator interface { lookup(oid string) (snmp.MibEntry, error) } @@ -49,6 +55,10 @@ type SnmpTrap struct { translator translator //nolint:revive } +func (*SnmpTrap) SampleConfig() string { + return sampleConfig +} + func (s *SnmpTrap) Gather(_ telegraf.Accumulator) error { return nil } diff --git a/plugins/inputs/snmp_trap/snmp_trap_sample_config.go b/plugins/inputs/snmp_trap/snmp_trap_sample_config.go deleted file mode 100644 index ad0a5d999d6b0..0000000000000 --- a/plugins/inputs/snmp_trap/snmp_trap_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package snmp_trap - -func (s *SnmpTrap) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/inputs/socket_listener/README.md b/plugins/inputs/socket_listener/README.md index c445e0f5a5c78..50c049af142f7 100644 --- a/plugins/inputs/socket_listener/README.md +++ b/plugins/inputs/socket_listener/README.md @@ -10,7 +10,7 @@ The plugin expects messages in the This is a sample configuration for the plugin. -```toml +```toml @sample.conf # Generic socket listener capable of handling multiple socket types. [[inputs.socket_listener]] ## URL to listen on diff --git a/plugins/inputs/socket_listener/socket_listener.go b/plugins/inputs/socket_listener/socket_listener.go index 8e77002538820..d64021a3a19b2 100644 --- a/plugins/inputs/socket_listener/socket_listener.go +++ b/plugins/inputs/socket_listener/socket_listener.go @@ -1,8 +1,10 @@ +//go:generate ../../../tools/readme_config_includer/generator package socket_listener import ( "bufio" "crypto/tls" + _ "embed" "fmt" "io" "net" @@ -20,6 +22,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 + type setReadBufferer interface { SetReadBuffer(bytes int) error } @@ -212,6 +218,10 @@ type SocketListener struct { io.Closer } +func (*SocketListener) SampleConfig() string { + return sampleConfig +} + func (sl *SocketListener) Gather(_ telegraf.Accumulator) error { return nil } diff --git a/plugins/inputs/socket_listener/socket_listener_sample_config.go b/plugins/inputs/socket_listener/socket_listener_sample_config.go deleted file mode 100644 index 27c3372995c46..0000000000000 --- a/plugins/inputs/socket_listener/socket_listener_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package socket_listener - -func (sl *SocketListener) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/inputs/socketstat/README.md b/plugins/inputs/socketstat/README.md index c9cff9a52ab93..261257742f19e 100644 --- a/plugins/inputs/socketstat/README.md +++ b/plugins/inputs/socketstat/README.md @@ -8,7 +8,7 @@ The `ss` command does not require specific privileges. ## Configuration -```toml +```toml @sample.conf # Gather indicators from established connections, using iproute2's ss command. [[inputs.socketstat]] ## ss can display information about tcp, udp, raw, unix, packet, dccp and sctp sockets diff --git a/plugins/inputs/socketstat/socketstat.go b/plugins/inputs/socketstat/socketstat.go index d987884d67505..54e5dfec9e7fe 100644 --- a/plugins/inputs/socketstat/socketstat.go +++ b/plugins/inputs/socketstat/socketstat.go @@ -1,3 +1,4 @@ +//go:generate ../../../tools/readme_config_includer/generator //go:build !windows // +build !windows @@ -8,6 +9,7 @@ package socketstat import ( "bufio" "bytes" + _ "embed" "fmt" "os/exec" "regexp" @@ -21,6 +23,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 + const measurement = "socketstat" // Socketstat is a telegraf plugin to gather indicators from established connections, using iproute2's `ss` command. @@ -37,6 +43,10 @@ type Socketstat struct { type socketLister func(cmdName string, proto string, timeout config.Duration) (*bytes.Buffer, error) +func (*Socketstat) SampleConfig() string { + return sampleConfig +} + // Gather gathers indicators from established connections func (ss *Socketstat) Gather(acc telegraf.Accumulator) error { // best effort : we continue through the protocols even if an error is encountered, diff --git a/plugins/inputs/socketstat/socketstat_sample_config.go b/plugins/inputs/socketstat/socketstat_sample_config.go deleted file mode 100644 index f059f8cde4e0b..0000000000000 --- a/plugins/inputs/socketstat/socketstat_sample_config.go +++ /dev/null @@ -1,11 +0,0 @@ -//go:build !windows -// +build !windows - -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package socketstat - -func (ss *Socketstat) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/inputs/solr/README.md b/plugins/inputs/solr/README.md index 93763ae029221..775dccce98501 100644 --- a/plugins/inputs/solr/README.md +++ b/plugins/inputs/solr/README.md @@ -9,7 +9,7 @@ Tested from 3.5 to 7.* ## Configuration -```toml +```toml @sample.conf # Read stats from one or more Solr servers or cores [[inputs.solr]] ## specify a list of one or more Solr servers diff --git a/plugins/inputs/solr/solr.go b/plugins/inputs/solr/solr.go index ae2e5c7d079e2..3ebef30764f48 100644 --- a/plugins/inputs/solr/solr.go +++ b/plugins/inputs/solr/solr.go @@ -1,6 +1,8 @@ +//go:generate ../../../tools/readme_config_includer/generator package solr import ( + _ "embed" "encoding/json" "fmt" "math" @@ -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 + const mbeansPath = "/admin/mbeans?stats=true&wt=json&cat=CORE&cat=QUERYHANDLER&cat=UPDATEHANDLER&cat=CACHE" const adminCoresPath = "/solr/admin/cores?action=STATUS&wt=json" @@ -114,6 +120,10 @@ func NewSolr() *Solr { } } +func (*Solr) SampleConfig() string { + return sampleConfig +} + // Gather reads the stats from Solr and writes it to the // Accumulator. func (s *Solr) Gather(acc telegraf.Accumulator) error { diff --git a/plugins/inputs/solr/solr_sample_config.go b/plugins/inputs/solr/solr_sample_config.go deleted file mode 100644 index 655f502f2aef8..0000000000000 --- a/plugins/inputs/solr/solr_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package solr - -func (s *Solr) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/inputs/sql/README.md b/plugins/inputs/sql/README.md index 9b233e031a8ea..d2086a88eb9d9 100644 --- a/plugins/inputs/sql/README.md +++ b/plugins/inputs/sql/README.md @@ -10,7 +10,7 @@ Please check the list of [supported SQL drivers](../../../docs/SQL_DRIVERS_INPUT This section contains the default TOML to configure the plugin. You can generate it using `telegraf --usage `. -```toml +```toml @sample.conf # Read metrics from SQL queries [[inputs.sql]] ## Database Driver diff --git a/plugins/inputs/sql/sql.go b/plugins/inputs/sql/sql.go index 9e4bca99c9d6f..dd903d7af63ab 100644 --- a/plugins/inputs/sql/sql.go +++ b/plugins/inputs/sql/sql.go @@ -1,8 +1,10 @@ +//go:generate ../../../tools/readme_config_includer/generator package sql import ( "context" dbsql "database/sql" + _ "embed" "errors" "fmt" "os" @@ -19,6 +21,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 + const magicIdleCount int = (-int(^uint(0) >> 1)) type Query struct { @@ -210,6 +216,10 @@ type SQL struct { db *dbsql.DB } +func (*SQL) SampleConfig() string { + return sampleConfig +} + func (s *SQL) Init() error { // Option handling if s.Driver == "" { diff --git a/plugins/inputs/sql/sql_sample_config.go b/plugins/inputs/sql/sql_sample_config.go deleted file mode 100644 index 66e52ca4202da..0000000000000 --- a/plugins/inputs/sql/sql_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package sql - -func (s *SQL) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/inputs/sqlserver/README.md b/plugins/inputs/sqlserver/README.md index 3b7f376f6b874..48c35bc2313ac 100644 --- a/plugins/inputs/sqlserver/README.md +++ b/plugins/inputs/sqlserver/README.md @@ -88,7 +88,7 @@ Remove User Id and Password keywords from the connection string in your config f ## Configuration -```toml +```toml @sample.conf # Read metrics from Microsoft SQL Server [[inputs.sqlserver]] ## Specify instances to monitor with a list of connection strings. diff --git a/plugins/inputs/sqlserver/sqlserver.go b/plugins/inputs/sqlserver/sqlserver.go index 9396dc1e35878..02746b3a5d24b 100644 --- a/plugins/inputs/sqlserver/sqlserver.go +++ b/plugins/inputs/sqlserver/sqlserver.go @@ -1,7 +1,9 @@ +//go:generate ../../../tools/readme_config_includer/generator package sqlserver import ( "database/sql" + _ "embed" "errors" "fmt" "strings" @@ -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 + // SQLServer struct type SQLServer struct { Servers []string `toml:"servers"` @@ -179,6 +185,10 @@ func (s *SQLServer) initQueries() error { return nil } +func (*SQLServer) SampleConfig() string { + return sampleConfig +} + // Gather collect data from SQL Server func (s *SQLServer) Gather(acc telegraf.Accumulator) error { var wg sync.WaitGroup diff --git a/plugins/inputs/sqlserver/sqlserver_sample_config.go b/plugins/inputs/sqlserver/sqlserver_sample_config.go deleted file mode 100644 index 2e85f1373f30a..0000000000000 --- a/plugins/inputs/sqlserver/sqlserver_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package sqlserver - -func (s *SQLServer) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/inputs/stackdriver/README.md b/plugins/inputs/stackdriver/README.md index 9426ced7abbf4..f6f80a80764cc 100644 --- a/plugins/inputs/stackdriver/README.md +++ b/plugins/inputs/stackdriver/README.md @@ -8,7 +8,7 @@ costs. ## Configuration -```toml +```toml @sample.conf # Gather timeseries from Google Cloud Platform v3 monitoring API [[inputs.stackdriver]] ## GCP Project diff --git a/plugins/inputs/stackdriver/stackdriver.go b/plugins/inputs/stackdriver/stackdriver.go index 9236e48b0ccdf..ad65ff9864857 100644 --- a/plugins/inputs/stackdriver/stackdriver.go +++ b/plugins/inputs/stackdriver/stackdriver.go @@ -1,7 +1,9 @@ +//go:generate ../../../tools/readme_config_includer/generator package stackdriver import ( "context" + _ "embed" "fmt" "math" "strconv" @@ -25,6 +27,10 @@ import ( "github.com/influxdata/telegraf/selfstat" ) +// DO NOT REMOVE THE NEXT TWO LINES! This is required to embedd the sampleConfig data. +//go:embed sample.conf +var sampleConfig string + const ( defaultRateLimit = 14 ) @@ -185,6 +191,10 @@ func (smc *stackdriverMetricClient) Close() error { return smc.conn.Close() } +func (*Stackdriver) SampleConfig() string { + return sampleConfig +} + // Gather implements telegraf.Input interface func (s *Stackdriver) Gather(acc telegraf.Accumulator) error { ctx := context.Background() @@ -627,7 +637,7 @@ func (s *Stackdriver) addDistribution(dist *distributionpb.Distribution, tags ma } func init() { - f := func() telegraf.Input { + inputs.Add("stackdriver", func() telegraf.Input { return &Stackdriver{ CacheTTL: defaultCacheTTL, RateLimit: defaultRateLimit, @@ -635,7 +645,5 @@ func init() { GatherRawDistributionBuckets: true, DistributionAggregationAligners: []string{}, } - } - - inputs.Add("stackdriver", f) + }) } diff --git a/plugins/inputs/stackdriver/stackdriver_sample_config.go b/plugins/inputs/stackdriver/stackdriver_sample_config.go deleted file mode 100644 index 5d3123e340fdb..0000000000000 --- a/plugins/inputs/stackdriver/stackdriver_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package stackdriver - -func (s *Stackdriver) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/inputs/statsd/README.md b/plugins/inputs/statsd/README.md index 620b95b7e6007..76390a82213cb 100644 --- a/plugins/inputs/statsd/README.md +++ b/plugins/inputs/statsd/README.md @@ -2,7 +2,7 @@ ## Configuration -```toml +```toml @sample.conf # Statsd Server [[inputs.statsd]] ## Protocol, must be "tcp", "udp4", "udp6" or "udp" (default=udp) diff --git a/plugins/inputs/statsd/statsd.go b/plugins/inputs/statsd/statsd.go index fbbdd03f00c58..5086d395adb44 100644 --- a/plugins/inputs/statsd/statsd.go +++ b/plugins/inputs/statsd/statsd.go @@ -1,8 +1,10 @@ +//go:generate ../../../tools/readme_config_includer/generator package statsd import ( "bufio" "bytes" + _ "embed" "fmt" "net" "regexp" @@ -22,6 +24,10 @@ import ( "github.com/influxdata/telegraf/selfstat" ) +// DO NOT REMOVE THE NEXT TWO LINES! This is required to embedd the sampleConfig data. +//go:embed sample.conf +var sampleConfig string + const ( // UDPMaxPacketSize is the UDP packet limit, see // https://en.wikipedia.org/wiki/User_Datagram_Protocol#Packet_structure @@ -219,6 +225,10 @@ type cacheddistributions struct { tags map[string]string } +func (*Statsd) SampleConfig() string { + return sampleConfig +} + func (s *Statsd) Gather(acc telegraf.Accumulator) error { s.Lock() defer s.Unlock() diff --git a/plugins/inputs/statsd/statsd_sample_config.go b/plugins/inputs/statsd/statsd_sample_config.go deleted file mode 100644 index 42c2a045208bd..0000000000000 --- a/plugins/inputs/statsd/statsd_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package statsd - -func (s *Statsd) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/inputs/suricata/README.md b/plugins/inputs/suricata/README.md index 1f6db7df2fda6..06edd8cc6626b 100644 --- a/plugins/inputs/suricata/README.md +++ b/plugins/inputs/suricata/README.md @@ -8,7 +8,7 @@ It can also report for triggered Suricata IDS/IPS alerts. ## Configuration -```toml +```toml @sample.conf # Suricata stats and alerts plugin [[inputs.suricata]] ## Data sink for Suricata stats log. diff --git a/plugins/inputs/suricata/suricata.go b/plugins/inputs/suricata/suricata.go index 8186e545dfbc1..a7b9f4d158c59 100644 --- a/plugins/inputs/suricata/suricata.go +++ b/plugins/inputs/suricata/suricata.go @@ -1,8 +1,10 @@ +//go:generate ../../../tools/readme_config_includer/generator package suricata import ( "bufio" "context" + _ "embed" "encoding/json" "fmt" "io" @@ -14,6 +16,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 + const ( // InBufSize is the input buffer size for JSON received via socket. // Set to 10MB, as depending on the number of threads the output might be @@ -35,6 +41,10 @@ type Suricata struct { wg sync.WaitGroup } +func (*Suricata) SampleConfig() string { + return sampleConfig +} + // Start initiates background collection of JSON data from the socket // provided to Suricata. func (s *Suricata) Start(acc telegraf.Accumulator) error { diff --git a/plugins/inputs/suricata/suricata_sample_config.go b/plugins/inputs/suricata/suricata_sample_config.go deleted file mode 100644 index 7974abde535d1..0000000000000 --- a/plugins/inputs/suricata/suricata_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package suricata - -func (s *Suricata) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/inputs/swap/README.md b/plugins/inputs/swap/README.md index c538559ca9aa4..f3c721842675b 100644 --- a/plugins/inputs/swap/README.md +++ b/plugins/inputs/swap/README.md @@ -6,7 +6,7 @@ For more information on what swap memory is, read [All about Linux swap space](h ## Configuration -```toml +```toml @sample.conf # Read metrics about swap memory usage [[inputs.swap]] # no configuration diff --git a/plugins/inputs/swap/swap.go b/plugins/inputs/swap/swap.go index cd05786d91110..08668d5e411a1 100644 --- a/plugins/inputs/swap/swap.go +++ b/plugins/inputs/swap/swap.go @@ -1,6 +1,8 @@ +//go:generate ../../../tools/readme_config_includer/generator package swap import ( + _ "embed" "fmt" "github.com/influxdata/telegraf" @@ -8,10 +10,18 @@ import ( "github.com/influxdata/telegraf/plugins/inputs/system" ) +// DO NOT REMOVE THE NEXT TWO LINES! This is required to embedd the sampleConfig data. +//go:embed sample.conf +var sampleConfig string + type SwapStats struct { ps system.PS } +func (*SwapStats) SampleConfig() string { + return sampleConfig +} + func (ss *SwapStats) Gather(acc telegraf.Accumulator) error { swap, err := ss.ps.SwapStat() if err != nil { diff --git a/plugins/inputs/swap/swap_sample_config.go b/plugins/inputs/swap/swap_sample_config.go deleted file mode 100644 index 0964ef4f86294..0000000000000 --- a/plugins/inputs/swap/swap_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package swap - -func (ss *SwapStats) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/inputs/synproxy/README.md b/plugins/inputs/synproxy/README.md index 70ce577056f2c..3a348a458efd7 100644 --- a/plugins/inputs/synproxy/README.md +++ b/plugins/inputs/synproxy/README.md @@ -7,7 +7,7 @@ The use of synproxy is documented in `man iptables-extensions` under the SYNPROX The synproxy plugin does not need any configuration -```toml +```toml @sample.conf # Get synproxy counter statistics from procfs [[inputs.synproxy]] # no configuration diff --git a/plugins/inputs/synproxy/synproxy.go b/plugins/inputs/synproxy/synproxy.go index 3cd363cca17c0..ef5b5834b9003 100644 --- a/plugins/inputs/synproxy/synproxy.go +++ b/plugins/inputs/synproxy/synproxy.go @@ -1,6 +1,8 @@ +//go:generate ../../../tools/readme_config_includer/generator package synproxy import ( + _ "embed" "os" "path" @@ -8,6 +10,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 Synproxy struct { Log telegraf.Logger `toml:"-"` @@ -15,6 +21,10 @@ type Synproxy struct { statFile string } +func (*Synproxy) SampleConfig() string { + return sampleConfig +} + func getHostProc() string { procPath := "/proc" if os.Getenv("HOST_PROC") != "" { diff --git a/plugins/inputs/synproxy/synproxy_sample_config.go b/plugins/inputs/synproxy/synproxy_sample_config.go deleted file mode 100644 index abdf8040736ad..0000000000000 --- a/plugins/inputs/synproxy/synproxy_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package synproxy - -func (k *Synproxy) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/inputs/syslog/README.md b/plugins/inputs/syslog/README.md index 993d0e5de5686..6d42d59d0b244 100644 --- a/plugins/inputs/syslog/README.md +++ b/plugins/inputs/syslog/README.md @@ -11,7 +11,7 @@ Syslog messages should be formatted according to ## Configuration -```toml +```toml @sample.conf [[inputs.syslog]] ## Protocol, address and port to host the syslog receiver. ## If no host is specified, then localhost is used. diff --git a/plugins/inputs/syslog/syslog.go b/plugins/inputs/syslog/syslog.go index 39c2bf1cf53da..1bf84e00dc79b 100644 --- a/plugins/inputs/syslog/syslog.go +++ b/plugins/inputs/syslog/syslog.go @@ -1,7 +1,9 @@ +//go:generate ../../../tools/readme_config_includer/generator package syslog import ( "crypto/tls" + _ "embed" "fmt" "io" "net" @@ -18,6 +20,7 @@ import ( "github.com/influxdata/go-syslog/v3/octetcounting" "github.com/influxdata/go-syslog/v3/rfc3164" "github.com/influxdata/go-syslog/v3/rfc5424" + "github.com/influxdata/telegraf" "github.com/influxdata/telegraf/config" framing "github.com/influxdata/telegraf/internal/syslog" @@ -25,6 +28,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 syslogRFC string const defaultReadTimeout = time.Second * 5 @@ -61,6 +68,10 @@ type Syslog struct { udpListener net.PacketConn } +func (*Syslog) SampleConfig() string { + return sampleConfig +} + // Gather ... func (s *Syslog) Gather(_ telegraf.Accumulator) error { return nil diff --git a/plugins/inputs/syslog/syslog_sample_config.go b/plugins/inputs/syslog/syslog_sample_config.go deleted file mode 100644 index 002c39f0e6822..0000000000000 --- a/plugins/inputs/syslog/syslog_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package syslog - -func (s *Syslog) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/inputs/sysstat/README.md b/plugins/inputs/sysstat/README.md index c10bc78e186a0..f42c4519dd65c 100644 --- a/plugins/inputs/sysstat/README.md +++ b/plugins/inputs/sysstat/README.md @@ -8,7 +8,7 @@ the created binary data file with the `sadf` utility. ## Configuration -```toml +```toml @sample.conf # Sysstat metrics collector [[inputs.sysstat]] ## Path to the sadc command. diff --git a/plugins/inputs/sysstat/sysstat.go b/plugins/inputs/sysstat/sysstat.go index 8499e925d2534..1ec94b5f1d5de 100644 --- a/plugins/inputs/sysstat/sysstat.go +++ b/plugins/inputs/sysstat/sysstat.go @@ -1,3 +1,4 @@ +//go:generate ../../../tools/readme_config_includer/generator //go:build linux // +build linux @@ -5,6 +6,7 @@ package sysstat import ( "bufio" + _ "embed" "encoding/csv" "fmt" "io" @@ -21,6 +23,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 + var ( firstTimestamp time.Time execCommand = exec.Command // execCommand is used to mock commands in tests. @@ -70,6 +76,29 @@ type Sysstat struct { Log telegraf.Logger } +const cmd = "sadf" + +func (*Sysstat) SampleConfig() string { + return sampleConfig +} + +func (s *Sysstat) Init() error { + // Set defaults + if s.Sadf == "" { + sadf, err := exec.LookPath(cmd) + if err != nil { + return fmt.Errorf("looking up %q failed: %v", cmd, err) + } + s.Sadf = sadf + } + + if s.Sadf == "" { + return fmt.Errorf("no path specified for %q", cmd) + } + + return nil +} + func (s *Sysstat) Gather(acc telegraf.Accumulator) error { if time.Duration(s.SadcInterval) != 0 { // Collect interval is calculated as interval - parseInterval @@ -273,15 +302,10 @@ func escape(dirty string) string { } func init() { - s := Sysstat{ - Group: true, - Activities: dfltActivities, - } - sadf, _ := exec.LookPath("sadf") - if len(sadf) > 0 { - s.Sadf = sadf - } inputs.Add("sysstat", func() telegraf.Input { - return &s + return &Sysstat{ + Group: true, + Activities: dfltActivities, + } }) } diff --git a/plugins/inputs/sysstat/sysstat_interval_test.go b/plugins/inputs/sysstat/sysstat_interval_test.go index f714ec10b1c36..d9cf7b54b17ee 100644 --- a/plugins/inputs/sysstat/sysstat_interval_test.go +++ b/plugins/inputs/sysstat/sysstat_interval_test.go @@ -9,6 +9,7 @@ import ( "time" "github.com/influxdata/telegraf/testutil" + "github.com/stretchr/testify/require" ) // TestInterval verifies that the correct interval is created. It is not @@ -23,22 +24,31 @@ func TestInterval(t *testing.T) { defer func() { execCommand = exec.Command }() var acc testutil.Accumulator - s.interval = 0 - wantedInterval := 3 - - err := acc.GatherError(s.Gather) - if err != nil { - t.Fatal(err) + s := &Sysstat{ + Log: testutil.Logger{}, + interval: 0, + Sadc: "/usr/lib/sa/sadc", + Sadf: "/usr/bin/sadf", + Group: false, + Activities: []string{"DISK", "SNMP"}, + Options: map[string]string{ + "C": "cpu", + "d": "disk", + }, + DeviceTags: map[string][]map[string]string{ + "sda": { + { + "vg": "rootvg", + }, + }, + }, } + require.NoError(t, s.Init()) + require.NoError(t, acc.GatherError(s.Gather)) + wantedInterval := 3 time.Sleep(time.Duration(wantedInterval) * time.Second) - err = acc.GatherError(s.Gather) - if err != nil { - t.Fatal(err) - } - - if s.interval != wantedInterval { - t.Errorf("wrong interval: got %d, want %d", s.interval, wantedInterval) - } + require.NoError(t, acc.GatherError(s.Gather)) + require.Equalf(t, wantedInterval, s.interval, "wrong interval: got %d, want %d", s.interval, wantedInterval) } diff --git a/plugins/inputs/sysstat/sysstat_sample_config.go b/plugins/inputs/sysstat/sysstat_sample_config.go deleted file mode 100644 index 2cff2c07d9254..0000000000000 --- a/plugins/inputs/sysstat/sysstat_sample_config.go +++ /dev/null @@ -1,11 +0,0 @@ -//go:build linux -// +build linux - -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package sysstat - -func (*Sysstat) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/inputs/sysstat/sysstat_test.go b/plugins/inputs/sysstat/sysstat_test.go index f4f96823a887d..646ea80a4f370 100644 --- a/plugins/inputs/sysstat/sysstat_test.go +++ b/plugins/inputs/sysstat/sysstat_test.go @@ -15,36 +15,33 @@ import ( "github.com/influxdata/telegraf/testutil" ) -var s = Sysstat{ - Log: testutil.Logger{}, - interval: 10, - Sadc: "/usr/lib/sa/sadc", - Sadf: "/usr/bin/sadf", - Group: false, - Activities: []string{"DISK", "SNMP"}, - Options: map[string]string{ - "C": "cpu", - "d": "disk", - }, - DeviceTags: map[string][]map[string]string{ - "sda": { - { - "vg": "rootvg", - }, - }, - }, -} - func TestGather(t *testing.T) { // overwriting exec commands with mock commands execCommand = fakeExecCommand defer func() { execCommand = exec.Command }() var acc testutil.Accumulator - err := acc.GatherError(s.Gather) - if err != nil { - t.Fatal(err) + s := &Sysstat{ + Log: testutil.Logger{}, + interval: 10, + Sadc: "/usr/lib/sa/sadc", + Sadf: "/usr/bin/sadf", + Group: false, + Activities: []string{"DISK", "SNMP"}, + Options: map[string]string{ + "C": "cpu", + "d": "disk", + }, + DeviceTags: map[string][]map[string]string{ + "sda": { + { + "vg": "rootvg", + }, + }, + }, } + require.NoError(t, s.Init()) + require.NoError(t, acc.GatherError(s.Gather)) cpuTags := map[string]string{"device": "all"} diskTags := map[string]string{"device": "sda", "vg": "rootvg"} @@ -158,16 +155,32 @@ func TestGather(t *testing.T) { } func TestGatherGrouped(t *testing.T) { - s.Group = true // overwriting exec commands with mock commands execCommand = fakeExecCommand defer func() { execCommand = exec.Command }() var acc testutil.Accumulator - err := acc.GatherError(s.Gather) - if err != nil { - t.Fatal(err) + s := &Sysstat{ + Log: testutil.Logger{}, + interval: 10, + Sadc: "/usr/lib/sa/sadc", + Sadf: "/usr/bin/sadf", + Group: true, + Activities: []string{"DISK", "SNMP"}, + Options: map[string]string{ + "C": "cpu", + "d": "disk", + }, + DeviceTags: map[string][]map[string]string{ + "sda": { + { + "vg": "rootvg", + }, + }, + }, } + require.NoError(t, s.Init()) + require.NoError(t, acc.GatherError(s.Gather)) var tests = []struct { measurement string diff --git a/plugins/inputs/system/README.md b/plugins/inputs/system/README.md index 4f87a8342b9bb..4bc83ef2b55d1 100644 --- a/plugins/inputs/system/README.md +++ b/plugins/inputs/system/README.md @@ -7,7 +7,7 @@ Number of CPUs is obtained from the /proc/cpuinfo file. ## Configuration -```toml +```toml @sample.conf # Read metrics about system load & uptime [[inputs.system]] # no configuration diff --git a/plugins/inputs/system/system.go b/plugins/inputs/system/system.go index 2eda2e3bb4f0e..906a4e9bf5d71 100644 --- a/plugins/inputs/system/system.go +++ b/plugins/inputs/system/system.go @@ -1,24 +1,35 @@ +//go:generate ../../../tools/readme_config_includer/generator package system import ( "bufio" "bytes" + _ "embed" "fmt" "os" "strings" "time" - "github.com/influxdata/telegraf" - "github.com/influxdata/telegraf/plugins/inputs" "github.com/shirou/gopsutil/v3/cpu" "github.com/shirou/gopsutil/v3/host" "github.com/shirou/gopsutil/v3/load" + + "github.com/influxdata/telegraf" + "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 SystemStats struct { Log telegraf.Logger } +func (*SystemStats) SampleConfig() string { + return sampleConfig +} + func (s *SystemStats) Gather(acc telegraf.Accumulator) error { loadavg, err := load.Avg() if err != nil && !strings.Contains(err.Error(), "not implemented") { diff --git a/plugins/inputs/system/system_sample_config.go b/plugins/inputs/system/system_sample_config.go deleted file mode 100644 index e67118438ca8d..0000000000000 --- a/plugins/inputs/system/system_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package system - -func (*SystemStats) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/inputs/systemd_units/README.md b/plugins/inputs/systemd_units/README.md index 75b317193e688..a902bbf7c278a 100644 --- a/plugins/inputs/systemd_units/README.md +++ b/plugins/inputs/systemd_units/README.md @@ -14,7 +14,7 @@ see `systemctl list-units --all --type help` for possible options. ## Configuration -```toml +```toml @sample.conf # Gather systemd units state [[inputs.systemd_units]] ## Set timeout for systemctl execution diff --git a/plugins/inputs/systemd_units/systemd_units.go b/plugins/inputs/systemd_units/systemd_units.go index e9ac1a9182d6f..e70b51593a1bf 100644 --- a/plugins/inputs/systemd_units/systemd_units.go +++ b/plugins/inputs/systemd_units/systemd_units.go @@ -1,8 +1,10 @@ +//go:generate ../../../tools/readme_config_includer/generator package systemd_units import ( "bufio" "bytes" + _ "embed" "fmt" "os/exec" "strings" @@ -14,6 +16,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 + // SystemdUnits is a telegraf plugin to gather systemd unit status type SystemdUnits struct { Timeout config.Duration @@ -119,6 +125,10 @@ var ( defaultPattern = "" ) +func (*SystemdUnits) SampleConfig() string { + return sampleConfig +} + // Gather parses systemctl outputs and adds counters to the Accumulator func (s *SystemdUnits) Gather(acc telegraf.Accumulator) error { out, err := s.systemctl(s.Timeout, s.UnitType, s.Pattern) diff --git a/plugins/inputs/systemd_units/systemd_units_sample_config.go b/plugins/inputs/systemd_units/systemd_units_sample_config.go deleted file mode 100644 index a728a763b61c5..0000000000000 --- a/plugins/inputs/systemd_units/systemd_units_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package systemd_units - -func (s *SystemdUnits) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/inputs/tail/README.md b/plugins/inputs/tail/README.md index efcff3e394efa..f458fc9d00683 100644 --- a/plugins/inputs/tail/README.md +++ b/plugins/inputs/tail/README.md @@ -21,7 +21,7 @@ The plugin expects messages in one of the ## Configuration -```toml +```toml @sample.conf # Parse the new lines appended to a file [[inputs.tail]] ## File names or a pattern to tail. diff --git a/plugins/inputs/tail/tail.go b/plugins/inputs/tail/tail.go index e27f6ad90f1f3..dd40934da22df 100644 --- a/plugins/inputs/tail/tail.go +++ b/plugins/inputs/tail/tail.go @@ -1,3 +1,4 @@ +//go:generate ../../../tools/readme_config_includer/generator //go:build !solaris // +build !solaris @@ -6,6 +7,7 @@ package tail import ( "bytes" "context" + _ "embed" "errors" "io" "strings" @@ -14,15 +16,20 @@ import ( "github.com/dimchansky/utfbom" "github.com/influxdata/tail" + "github.com/pborman/ansi" + "github.com/influxdata/telegraf" "github.com/influxdata/telegraf/internal/globpath" "github.com/influxdata/telegraf/plugins/common/encoding" "github.com/influxdata/telegraf/plugins/inputs" "github.com/influxdata/telegraf/plugins/parsers" "github.com/influxdata/telegraf/plugins/parsers/csv" - "github.com/pborman/ansi" ) +// DO NOT REMOVE THE NEXT TWO LINES! This is required to embedd the sampleConfig data. +//go:embed sample.conf +var sampleConfig string + const ( defaultWatchMethod = "inotify" ) @@ -80,6 +87,10 @@ func NewTail() *Tail { } } +func (*Tail) SampleConfig() string { + return sampleConfig +} + func (t *Tail) Init() error { if t.MaxUndeliveredLines == 0 { return errors.New("max_undelivered_lines must be positive") diff --git a/plugins/inputs/tail/tail_sample_config.go b/plugins/inputs/tail/tail_sample_config.go deleted file mode 100644 index 75f9dee0b7afa..0000000000000 --- a/plugins/inputs/tail/tail_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package tail - -func (t *Tail) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/inputs/tcp_listener/README.md b/plugins/inputs/tcp_listener/README.md index 0b3bf8a914a8b..858c8c51aa104 100644 --- a/plugins/inputs/tcp_listener/README.md +++ b/plugins/inputs/tcp_listener/README.md @@ -5,7 +5,7 @@ ## Configuration -```toml +```toml @sample.conf # Generic TCP listener [[inputs.tcp_listener]] # socket_listener plugin diff --git a/plugins/inputs/tcp_listener/tcp_listener.go b/plugins/inputs/tcp_listener/tcp_listener.go index e70cad17ecf5f..f1f8cc2d517bb 100644 --- a/plugins/inputs/tcp_listener/tcp_listener.go +++ b/plugins/inputs/tcp_listener/tcp_listener.go @@ -1,7 +1,9 @@ +//go:generate ../../../tools/readme_config_includer/generator package tcp_listener import ( "bufio" + _ "embed" "fmt" "net" "sync" @@ -13,6 +15,10 @@ import ( "github.com/influxdata/telegraf/selfstat" ) +// DO NOT REMOVE THE NEXT TWO LINES! This is required to embedd the sampleConfig data. +//go:embed sample.conf +var sampleConfig string + type TCPListener struct { ServiceAddress string AllowedPendingMessages int @@ -58,6 +64,10 @@ var dropwarn = "tcp_listener message queue full. " + var malformedwarn = "tcp_listener has received %d malformed packets" + " thus far." +func (*TCPListener) SampleConfig() string { + return sampleConfig +} + // All the work is done in the Start() function, so this is just a dummy // function. func (t *TCPListener) Gather(_ telegraf.Accumulator) error { diff --git a/plugins/inputs/tcp_listener/tcp_listener_sample_config.go b/plugins/inputs/tcp_listener/tcp_listener_sample_config.go deleted file mode 100644 index ef0e6a4811ef9..0000000000000 --- a/plugins/inputs/tcp_listener/tcp_listener_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package tcp_listener - -func (t *TCPListener) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/inputs/teamspeak/README.md b/plugins/inputs/teamspeak/README.md index f2c99fd6b748c..341849a82c385 100644 --- a/plugins/inputs/teamspeak/README.md +++ b/plugins/inputs/teamspeak/README.md @@ -7,7 +7,7 @@ the [Teamspeak 3 ServerQuery Manual](http://media.teamspeak.com/ts3_literature/T ## Configuration -```toml +```toml @sample.conf # Reads metrics from a Teamspeak 3 Server via ServerQuery [[inputs.teamspeak]] ## Server address for Teamspeak 3 ServerQuery diff --git a/plugins/inputs/teamspeak/teamspeak.go b/plugins/inputs/teamspeak/teamspeak.go index 9e006b3853236..ac9223adc8456 100644 --- a/plugins/inputs/teamspeak/teamspeak.go +++ b/plugins/inputs/teamspeak/teamspeak.go @@ -1,14 +1,20 @@ +//go:generate ../../../tools/readme_config_includer/generator package teamspeak import ( - "github.com/multiplay/go-ts3" - + _ "embed" "strconv" + "github.com/multiplay/go-ts3" + "github.com/influxdata/telegraf" "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 Teamspeak struct { Server string Username string @@ -49,6 +55,10 @@ func (ts *Teamspeak) connect() error { return nil } +func (*Teamspeak) SampleConfig() string { + return sampleConfig +} + func (ts *Teamspeak) Gather(acc telegraf.Accumulator) error { var err error diff --git a/plugins/inputs/teamspeak/teamspeak_sample_config.go b/plugins/inputs/teamspeak/teamspeak_sample_config.go deleted file mode 100644 index 5147f9e9d18f2..0000000000000 --- a/plugins/inputs/teamspeak/teamspeak_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package teamspeak - -func (ts *Teamspeak) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/inputs/temp/README.md b/plugins/inputs/temp/README.md index e0c01788d0004..b61c435fa17de 100644 --- a/plugins/inputs/temp/README.md +++ b/plugins/inputs/temp/README.md @@ -7,7 +7,7 @@ Currently supports Linux and Windows. ## Configuration -```toml +```toml @sample.conf # Read metrics about temperature [[inputs.temp]] # no configuration diff --git a/plugins/inputs/temp/temp.go b/plugins/inputs/temp/temp.go index f7c75982fb984..39328ac84a46e 100644 --- a/plugins/inputs/temp/temp.go +++ b/plugins/inputs/temp/temp.go @@ -1,6 +1,8 @@ +//go:generate ../../../tools/readme_config_includer/generator package temp import ( + _ "embed" "fmt" "strings" @@ -9,10 +11,18 @@ import ( "github.com/influxdata/telegraf/plugins/inputs/system" ) +// DO NOT REMOVE THE NEXT TWO LINES! This is required to embedd the sampleConfig data. +//go:embed sample.conf +var sampleConfig string + type Temperature struct { ps system.PS } +func (*Temperature) SampleConfig() string { + return sampleConfig +} + func (t *Temperature) Gather(acc telegraf.Accumulator) error { temps, err := t.ps.Temperature() if err != nil { diff --git a/plugins/inputs/temp/temp_sample_config.go b/plugins/inputs/temp/temp_sample_config.go deleted file mode 100644 index fa8a0d8dad82c..0000000000000 --- a/plugins/inputs/temp/temp_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package temp - -func (t *Temperature) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/inputs/tengine/README.md b/plugins/inputs/tengine/README.md index d70c304ef9559..642aaae2f4422 100644 --- a/plugins/inputs/tengine/README.md +++ b/plugins/inputs/tengine/README.md @@ -6,7 +6,7 @@ The tengine plugin gathers metrics from the ## Configuration -```toml +```toml @sample.conf # Read Tengine's basic status information (ngx_http_reqstat_module) [[inputs.tengine]] ## An array of Tengine reqstat module URI to gather stats. diff --git a/plugins/inputs/tengine/tengine.go b/plugins/inputs/tengine/tengine.go index 4399569d6a692..92c99064a7f2c 100644 --- a/plugins/inputs/tengine/tengine.go +++ b/plugins/inputs/tengine/tengine.go @@ -1,8 +1,11 @@ +//go:generate ../../../tools/readme_config_includer/generator package tengine import ( "bufio" + _ "embed" "fmt" + "io" "net" "net/http" "net/url" @@ -11,14 +14,16 @@ import ( "sync" "time" - "io" - "github.com/influxdata/telegraf" "github.com/influxdata/telegraf/config" "github.com/influxdata/telegraf/plugins/common/tls" "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 Tengine struct { Urls []string ResponseTimeout config.Duration @@ -27,6 +32,10 @@ type Tengine struct { client *http.Client } +func (*Tengine) SampleConfig() string { + return sampleConfig +} + func (n *Tengine) Gather(acc telegraf.Accumulator) error { var wg sync.WaitGroup diff --git a/plugins/inputs/tengine/tengine_sample_config.go b/plugins/inputs/tengine/tengine_sample_config.go deleted file mode 100644 index baa207d2da831..0000000000000 --- a/plugins/inputs/tengine/tengine_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package tengine - -func (n *Tengine) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/inputs/tomcat/README.md b/plugins/inputs/tomcat/README.md index 68080c2ece624..d2cf41507b727 100644 --- a/plugins/inputs/tomcat/README.md +++ b/plugins/inputs/tomcat/README.md @@ -6,7 +6,7 @@ See the [Tomcat documentation](https://tomcat.apache.org/tomcat-9.0-doc/manager- ## Configuration -```toml +```toml @sample.conf # Gather metrics from the Tomcat server status page. [[inputs.tomcat]] ## URL of the Tomcat server status diff --git a/plugins/inputs/tomcat/tomcat.go b/plugins/inputs/tomcat/tomcat.go index a63391cada81e..604c734d378ba 100644 --- a/plugins/inputs/tomcat/tomcat.go +++ b/plugins/inputs/tomcat/tomcat.go @@ -1,6 +1,8 @@ +//go:generate ../../../tools/readme_config_includer/generator package tomcat import ( + _ "embed" "encoding/xml" "fmt" "net/http" @@ -14,6 +16,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 TomcatStatus struct { TomcatJvm TomcatJvm `xml:"jvm"` TomcatConnectors []TomcatConnector `xml:"connector"` @@ -70,6 +76,10 @@ type Tomcat struct { request *http.Request } +func (*Tomcat) SampleConfig() string { + return sampleConfig +} + func (s *Tomcat) Gather(acc telegraf.Accumulator) error { if s.client == nil { client, err := s.createHTTPClient() diff --git a/plugins/inputs/tomcat/tomcat_sample_config.go b/plugins/inputs/tomcat/tomcat_sample_config.go deleted file mode 100644 index 2d67bc9be8372..0000000000000 --- a/plugins/inputs/tomcat/tomcat_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package tomcat - -func (s *Tomcat) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/inputs/trig/README.md b/plugins/inputs/trig/README.md index 9ece5604ac697..7e5e0854c8d8b 100644 --- a/plugins/inputs/trig/README.md +++ b/plugins/inputs/trig/README.md @@ -4,7 +4,7 @@ The `trig` plugin is for demonstration purposes and inserts sine and cosine ## Configuration -```toml +```toml @sample.conf # Inserts sine and cosine waves for demonstration purposes [[inputs.trig]] ## Set the amplitude diff --git a/plugins/inputs/trig/trig.go b/plugins/inputs/trig/trig.go index 40613607270c2..9a473f2efc6e5 100644 --- a/plugins/inputs/trig/trig.go +++ b/plugins/inputs/trig/trig.go @@ -1,17 +1,27 @@ +//go:generate ../../../tools/readme_config_includer/generator package trig import ( + _ "embed" "math" "github.com/influxdata/telegraf" "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 Trig struct { x float64 Amplitude 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 diff --git a/plugins/inputs/trig/trig_sample_config.go b/plugins/inputs/trig/trig_sample_config.go deleted file mode 100644 index 0c089b92251cc..0000000000000 --- a/plugins/inputs/trig/trig_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package trig - -func (s *Trig) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/inputs/twemproxy/README.md b/plugins/inputs/twemproxy/README.md index 6242f9b3c347f..20b5a4251aba7 100644 --- a/plugins/inputs/twemproxy/README.md +++ b/plugins/inputs/twemproxy/README.md @@ -4,7 +4,7 @@ The `twemproxy` plugin gathers statistics from [Twemproxy](https://github.com/tw ## Configuration -```toml +```toml @sample.conf # Read Twemproxy stats data [[inputs.twemproxy]] ## Twemproxy stats address and port (no scheme) diff --git a/plugins/inputs/twemproxy/twemproxy.go b/plugins/inputs/twemproxy/twemproxy.go index 60c7ed9022934..fba9c5dfb4273 100644 --- a/plugins/inputs/twemproxy/twemproxy.go +++ b/plugins/inputs/twemproxy/twemproxy.go @@ -1,6 +1,8 @@ +//go:generate ../../../tools/readme_config_includer/generator package twemproxy import ( + _ "embed" "encoding/json" "errors" "io" @@ -11,11 +13,19 @@ 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 Twemproxy struct { Addr string Pools []string } +func (*Twemproxy) SampleConfig() string { + return sampleConfig +} + // Gather data from all Twemproxy instances func (t *Twemproxy) Gather(acc telegraf.Accumulator) error { conn, err := net.DialTimeout("tcp", t.Addr, 1*time.Second) diff --git a/plugins/inputs/twemproxy/twemproxy_sample_config.go b/plugins/inputs/twemproxy/twemproxy_sample_config.go deleted file mode 100644 index ab2539415be9c..0000000000000 --- a/plugins/inputs/twemproxy/twemproxy_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package twemproxy - -func (t *Twemproxy) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/inputs/udp_listener/README.md b/plugins/inputs/udp_listener/README.md index 36892d4a5340f..ebbf2d8d917e3 100644 --- a/plugins/inputs/udp_listener/README.md +++ b/plugins/inputs/udp_listener/README.md @@ -5,7 +5,7 @@ ## Configuration -```toml +```toml @sample.conf # Generic UDP listener [[inputs.udp_listener]] # see https://github.com/influxdata/telegraf/tree/master/plugins/inputs/socket_listener diff --git a/plugins/inputs/udp_listener/udp_listener.go b/plugins/inputs/udp_listener/udp_listener.go index 5fe91e9602226..f27df6a7145fa 100644 --- a/plugins/inputs/udp_listener/udp_listener.go +++ b/plugins/inputs/udp_listener/udp_listener.go @@ -1,6 +1,8 @@ +//go:generate ../../../tools/readme_config_includer/generator package udp_listener import ( + _ "embed" "fmt" "net" "sync" @@ -12,6 +14,10 @@ import ( "github.com/influxdata/telegraf/selfstat" ) +// DO NOT REMOVE THE NEXT TWO LINES! This is required to embedd the sampleConfig data. +//go:embed sample.conf +var sampleConfig string + // UDPListener main struct for the collector type UDPListener struct { ServiceAddress string @@ -67,6 +73,10 @@ var dropwarn = "udp_listener message queue full. " + var malformedwarn = "udp_listener has received %d malformed packets" + " thus far." +func (*UDPListener) SampleConfig() string { + return sampleConfig +} + // All the work is done in the Start() function, so this is just a dummy // function. func (u *UDPListener) Gather(_ telegraf.Accumulator) error { diff --git a/plugins/inputs/udp_listener/udp_listener_sample_config.go b/plugins/inputs/udp_listener/udp_listener_sample_config.go deleted file mode 100644 index 607be1209fc55..0000000000000 --- a/plugins/inputs/udp_listener/udp_listener_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package udp_listener - -func (u *UDPListener) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/inputs/unbound/README.md b/plugins/inputs/unbound/README.md index 025bb1727031e..546bb7846bbaa 100644 --- a/plugins/inputs/unbound/README.md +++ b/plugins/inputs/unbound/README.md @@ -5,7 +5,7 @@ a validating, recursive, and caching DNS resolver. ## Configuration -```toml +```toml @sample.conf # A plugin to collect stats from the Unbound DNS resolver [[inputs.unbound]] ## Address of server to connect to, read from unbound conf default, optionally ':port' diff --git a/plugins/inputs/unbound/unbound.go b/plugins/inputs/unbound/unbound.go index 1dd6ca85be31c..1d1cd6fc979c7 100644 --- a/plugins/inputs/unbound/unbound.go +++ b/plugins/inputs/unbound/unbound.go @@ -1,9 +1,11 @@ +//go:generate ../../../tools/readme_config_includer/generator package unbound import ( "bufio" "bytes" "context" + _ "embed" "fmt" "net" "os/exec" @@ -18,6 +20,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 runner func(unbound Unbound) (*bytes.Buffer, error) // Unbound is used to store configuration values @@ -88,6 +94,10 @@ func unboundRunner(unbound Unbound) (*bytes.Buffer, error) { // Gather collects stats from unbound-control and adds them to the Accumulator // +func (*Unbound) SampleConfig() string { + return sampleConfig +} + // All the dots in stat name will replaced by underscores. Histogram statistics will not be collected. func (s *Unbound) Gather(acc telegraf.Accumulator) error { // Always exclude histogram statistics diff --git a/plugins/inputs/unbound/unbound_sample_config.go b/plugins/inputs/unbound/unbound_sample_config.go deleted file mode 100644 index 64032afb9b6d4..0000000000000 --- a/plugins/inputs/unbound/unbound_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package unbound - -func (s *Unbound) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/inputs/uwsgi/README.md b/plugins/inputs/uwsgi/README.md index 4f385cedbe69b..2ffa82db68ac6 100644 --- a/plugins/inputs/uwsgi/README.md +++ b/plugins/inputs/uwsgi/README.md @@ -4,7 +4,7 @@ The uWSGI input plugin gathers metrics about uWSGI using its [Stats Server](http ## Configuration -```toml +```toml @sample.conf # Read uWSGI metrics. [[inputs.uwsgi]] ## List with urls of uWSGI Stats servers. Url must match pattern: diff --git a/plugins/inputs/uwsgi/uwsgi.go b/plugins/inputs/uwsgi/uwsgi.go index cdf3f326b7291..3dbcfaf16a9f6 100644 --- a/plugins/inputs/uwsgi/uwsgi.go +++ b/plugins/inputs/uwsgi/uwsgi.go @@ -1,8 +1,10 @@ +//go:generate ../../../tools/readme_config_includer/generator // Package uwsgi implements a telegraf plugin for collecting uwsgi stats from // the uwsgi stats server. package uwsgi import ( + _ "embed" "encoding/json" "fmt" "io" @@ -19,6 +21,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 + // Uwsgi server struct type Uwsgi struct { Servers []string `toml:"servers"` @@ -27,6 +33,10 @@ type Uwsgi struct { client *http.Client } +func (*Uwsgi) SampleConfig() string { + return sampleConfig +} + // Gather collect data from uWSGI Server func (u *Uwsgi) Gather(acc telegraf.Accumulator) error { if u.client == nil { diff --git a/plugins/inputs/uwsgi/uwsgi_sample_config.go b/plugins/inputs/uwsgi/uwsgi_sample_config.go deleted file mode 100644 index 923bbbe1b90ec..0000000000000 --- a/plugins/inputs/uwsgi/uwsgi_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package uwsgi - -func (u *Uwsgi) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/inputs/varnish/README.md b/plugins/inputs/varnish/README.md index dd684a2511460..4c26d60f92209 100644 --- a/plugins/inputs/varnish/README.md +++ b/plugins/inputs/varnish/README.md @@ -4,7 +4,7 @@ This plugin gathers stats from [Varnish HTTP Cache](https://varnish-cache.org/) ## Configuration -```toml +```toml @sample.conf # A plugin to collect stats from Varnish HTTP Cache [[inputs.varnish]] ## If running as a restricted user you can prepend sudo for additional access: diff --git a/plugins/inputs/varnish/varnish.go b/plugins/inputs/varnish/varnish.go index db5a72ba89a1d..ddec745b42093 100644 --- a/plugins/inputs/varnish/varnish.go +++ b/plugins/inputs/varnish/varnish.go @@ -1,3 +1,4 @@ +//go:generate ../../../tools/readme_config_includer/generator //go:build !windows // +build !windows @@ -6,6 +7,7 @@ package varnish import ( "bufio" "bytes" + _ "embed" "encoding/json" "fmt" "io" @@ -22,6 +24,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 + var ( measurementNamespace = "varnish" defaultStats = []string{"MAIN.cache_hit", "MAIN.cache_miss", "MAIN.uptime"} @@ -91,6 +97,10 @@ func varnishRunner(cmdName string, useSudo bool, cmdArgs []string, timeout confi return &out, nil } +func (*Varnish) SampleConfig() string { + return sampleConfig +} + func (s *Varnish) Init() error { var customRegexps []*regexp.Regexp for _, re := range s.Regexps { diff --git a/plugins/inputs/varnish/varnish_sample_config.go b/plugins/inputs/varnish/varnish_sample_config.go deleted file mode 100644 index 664f613f83cf1..0000000000000 --- a/plugins/inputs/varnish/varnish_sample_config.go +++ /dev/null @@ -1,11 +0,0 @@ -//go:build !windows -// +build !windows - -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package varnish - -func (s *Varnish) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/inputs/vault/README.md b/plugins/inputs/vault/README.md index 03e6b2d41a61f..9ddad7431c2ca 100644 --- a/plugins/inputs/vault/README.md +++ b/plugins/inputs/vault/README.md @@ -6,7 +6,7 @@ The Vault plugin could grab metrics from every Vault agent of the cluster. Teleg ## Configuration -```toml +```toml @sample.conf # Read metrics from the Vault API [[inputs.vault]] ## URL for the Vault agent diff --git a/plugins/inputs/vault/vault.go b/plugins/inputs/vault/vault.go index 0bd4748a3f111..76495f177e461 100644 --- a/plugins/inputs/vault/vault.go +++ b/plugins/inputs/vault/vault.go @@ -1,6 +1,8 @@ +//go:generate ../../../tools/readme_config_includer/generator package vault import ( + _ "embed" "encoding/json" "fmt" "net/http" @@ -15,6 +17,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 + // Vault configuration object type Vault struct { URL string `toml:"url"` @@ -39,6 +45,10 @@ func init() { }) } +func (*Vault) SampleConfig() string { + return sampleConfig +} + func (n *Vault) Init() error { if n.URL == "" { n.URL = "http://127.0.0.1:8200" diff --git a/plugins/inputs/vault/vault_sample_config.go b/plugins/inputs/vault/vault_sample_config.go deleted file mode 100644 index 0b1000bc1c916..0000000000000 --- a/plugins/inputs/vault/vault_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package vault - -func (n *Vault) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/inputs/vsphere/README.md b/plugins/inputs/vsphere/README.md index 51011b9390c35..1cefc2f4d0956 100644 --- a/plugins/inputs/vsphere/README.md +++ b/plugins/inputs/vsphere/README.md @@ -19,7 +19,7 @@ Compatibility information was found [here](https://github.com/vmware/govmomi/tre NOTE: To disable collection of a specific resource type, simply exclude all metrics using the XX_metric_exclude. For example, to disable collection of VMs, add this: -```toml +```toml @sample.conf vm_metric_exclude = [ "*" ] ``` diff --git a/plugins/inputs/vsphere/vsphere.go b/plugins/inputs/vsphere/vsphere.go index c1737068f5328..bc18203efb9c4 100644 --- a/plugins/inputs/vsphere/vsphere.go +++ b/plugins/inputs/vsphere/vsphere.go @@ -1,17 +1,24 @@ +//go:generate ../../../tools/readme_config_includer/generator package vsphere import ( "context" + _ "embed" "sync" "time" + "github.com/vmware/govmomi/vim25/soap" + "github.com/influxdata/telegraf" "github.com/influxdata/telegraf/config" "github.com/influxdata/telegraf/plugins/common/tls" "github.com/influxdata/telegraf/plugins/inputs" - "github.com/vmware/govmomi/vim25/soap" ) +// DO NOT REMOVE THE NEXT TWO LINES! This is required to embedd the sampleConfig data. +//go:embed sample.conf +var sampleConfig string + // VSphere is the top level type for the vSphere input plugin. It contains all the configuration // and a list of connected vSphere endpoints type VSphere struct { @@ -73,6 +80,10 @@ type VSphere struct { Log telegraf.Logger } +func (*VSphere) SampleConfig() string { + return sampleConfig +} + // Start is called from telegraf core when a plugin is started and allows it to // perform initialization tasks. func (v *VSphere) Start(_ telegraf.Accumulator) error { diff --git a/plugins/inputs/vsphere/vsphere_sample_config.go b/plugins/inputs/vsphere/vsphere_sample_config.go deleted file mode 100644 index 211d52dd1a675..0000000000000 --- a/plugins/inputs/vsphere/vsphere_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package vsphere - -func (v *VSphere) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/inputs/webhooks/README.md b/plugins/inputs/webhooks/README.md index 16105c93eb979..1a1a72dd22b99 100644 --- a/plugins/inputs/webhooks/README.md +++ b/plugins/inputs/webhooks/README.md @@ -15,7 +15,7 @@ sudo service telegraf start ## Configuration -```toml +```toml @sample.conf # A Webhooks Event collector [[inputs.webhooks]] ## Address and port to host Webhook listener on diff --git a/plugins/inputs/webhooks/webhooks.go b/plugins/inputs/webhooks/webhooks.go index c1167565948ad..50b8f521507bc 100644 --- a/plugins/inputs/webhooks/webhooks.go +++ b/plugins/inputs/webhooks/webhooks.go @@ -1,6 +1,8 @@ +//go:generate ../../../tools/readme_config_includer/generator package webhooks import ( + _ "embed" "fmt" "net" "net/http" @@ -19,6 +21,10 @@ import ( "github.com/influxdata/telegraf/plugins/inputs/webhooks/rollbar" ) +// DO NOT REMOVE THE NEXT TWO LINES! This is required to embedd the sampleConfig data. +//go:embed sample.conf +var sampleConfig string + type Webhook interface { Register(router *mux.Router, acc telegraf.Accumulator, log telegraf.Logger) } @@ -47,6 +53,10 @@ func NewWebhooks() *Webhooks { return &Webhooks{} } +func (*Webhooks) SampleConfig() string { + return sampleConfig +} + func (wb *Webhooks) Gather(_ telegraf.Accumulator) error { return nil } diff --git a/plugins/inputs/webhooks/webhooks_sample_config.go b/plugins/inputs/webhooks/webhooks_sample_config.go deleted file mode 100644 index 882ce3944e1ce..0000000000000 --- a/plugins/inputs/webhooks/webhooks_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package webhooks - -func (wb *Webhooks) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/inputs/win_eventlog/README.md b/plugins/inputs/win_eventlog/README.md index 8515103fd2fb3..ebb0159769e9e 100644 --- a/plugins/inputs/win_eventlog/README.md +++ b/plugins/inputs/win_eventlog/README.md @@ -10,7 +10,7 @@ Telegraf minimum version: Telegraf 1.16.0 ### Configuration -```toml +```toml @sample.conf # Input plugin to collect Windows Event Log messages [[inputs.win_eventlog]] ## Telegraf should have Administrator permissions to subscribe for some Windows Events channels diff --git a/plugins/inputs/win_eventlog/win_eventlog.go b/plugins/inputs/win_eventlog/win_eventlog.go index 552f727f7598d..875dd4e772d93 100644 --- a/plugins/inputs/win_eventlog/win_eventlog.go +++ b/plugins/inputs/win_eventlog/win_eventlog.go @@ -1,3 +1,4 @@ +//go:generate ../../../tools/readme_config_includer/generator //go:build windows // +build windows @@ -8,6 +9,7 @@ package win_eventlog import ( "bufio" "bytes" + _ "embed" "encoding/xml" "fmt" "path/filepath" @@ -16,11 +18,16 @@ import ( "syscall" "time" + "golang.org/x/sys/windows" + "github.com/influxdata/telegraf" "github.com/influxdata/telegraf/plugins/inputs" - "golang.org/x/sys/windows" ) +// DO NOT REMOVE THE NEXT TWO LINES! This is required to embedd the sampleConfig data. +//go:embed sample.conf +var sampleConfig string + // WinEventLog config type WinEventLog struct { Locale uint32 `toml:"locale"` @@ -44,6 +51,10 @@ var bufferSize = 1 << 14 var description = "Input plugin to collect Windows Event Log messages" +func (*WinEventLog) SampleConfig() string { + return sampleConfig +} + // Gather Windows Event Log entries func (w *WinEventLog) Gather(acc telegraf.Accumulator) error { diff --git a/plugins/inputs/win_eventlog/win_eventlog_sample_config.go b/plugins/inputs/win_eventlog/win_eventlog_sample_config.go deleted file mode 100644 index d2e93d0e05735..0000000000000 --- a/plugins/inputs/win_eventlog/win_eventlog_sample_config.go +++ /dev/null @@ -1,11 +0,0 @@ -//go:build windows -// +build windows - -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package win_eventlog - -func (w *WinEventLog) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/inputs/win_perf_counters/README.md b/plugins/inputs/win_perf_counters/README.md index 7c300309141c9..ff62941561511 100644 --- a/plugins/inputs/win_perf_counters/README.md +++ b/plugins/inputs/win_perf_counters/README.md @@ -225,7 +225,7 @@ if any of the combinations of ObjectName/Instances/Counters are invalid. ## Configuration -```toml +```toml @sample.conf # # Input plugin to counterPath Performance Counters on Windows operating systems # [[inputs.win_perf_counters]] # ## By default this plugin returns basic CPU and Disk statistics. diff --git a/plugins/inputs/win_perf_counters/win_perf_counters.go b/plugins/inputs/win_perf_counters/win_perf_counters.go index 4ad7f2fd423c9..1a2b3e70ae489 100644 --- a/plugins/inputs/win_perf_counters/win_perf_counters.go +++ b/plugins/inputs/win_perf_counters/win_perf_counters.go @@ -1,9 +1,11 @@ +//go:generate ../../../tools/readme_config_includer/generator //go:build windows // +build windows package win_perf_counters import ( + _ "embed" "errors" "fmt" "strings" @@ -14,6 +16,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 Win_PerfCounters struct { PrintValid bool `toml:"PrintValid"` PreVistaSupport bool `toml:"PreVistaSupport" deprecated:"1.7.0;determined dynamically"` @@ -129,6 +135,10 @@ func newCounter(counterHandle PDH_HCOUNTER, counterPath string, objectName strin includeTotal, useRawValue, counterHandle} } +func (*Win_PerfCounters) SampleConfig() string { + return sampleConfig +} + func (m *Win_PerfCounters) AddItem(counterPath string, objectName string, instance string, counterName string, measurement string, includeTotal bool, useRawValue bool) error { origCounterPath := counterPath var err error diff --git a/plugins/inputs/win_perf_counters/win_perf_counters_sample_config.go b/plugins/inputs/win_perf_counters/win_perf_counters_sample_config.go deleted file mode 100644 index 62e6696db6abb..0000000000000 --- a/plugins/inputs/win_perf_counters/win_perf_counters_sample_config.go +++ /dev/null @@ -1,11 +0,0 @@ -//go:build windows -// +build windows - -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package win_perf_counters - -func (m *Win_PerfCounters) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/inputs/win_services/README.md b/plugins/inputs/win_services/README.md index bb590e7f69416..08a084a0936aa 100644 --- a/plugins/inputs/win_services/README.md +++ b/plugins/inputs/win_services/README.md @@ -6,7 +6,7 @@ Monitoring some services may require running Telegraf with administrator privile ## Configuration -```toml +```toml @sample.conf # Input plugin to report Windows services info. [[inputs.win_services]] ## Names of the services to monitor. Leave empty to monitor all the available services on the host. Globs accepted. Case sensitive. diff --git a/plugins/inputs/win_services/win_services.go b/plugins/inputs/win_services/win_services.go index 3c5abb4481217..ccbf99978d9fb 100644 --- a/plugins/inputs/win_services/win_services.go +++ b/plugins/inputs/win_services/win_services.go @@ -1,19 +1,26 @@ +//go:generate ../../../tools/readme_config_includer/generator //go:build windows // +build windows package win_services import ( + _ "embed" "fmt" "os" + "golang.org/x/sys/windows/svc" + "golang.org/x/sys/windows/svc/mgr" + "github.com/influxdata/telegraf" "github.com/influxdata/telegraf/filter" "github.com/influxdata/telegraf/plugins/inputs" - "golang.org/x/sys/windows/svc" - "golang.org/x/sys/windows/svc/mgr" ) +// DO NOT REMOVE THE NEXT TWO LINES! This is required to embedd the sampleConfig data. +//go:embed sample.conf +var sampleConfig string + type ServiceErr struct { Message string Service string @@ -97,6 +104,10 @@ type ServiceInfo struct { StartUpMode int } +func (*WinServices) SampleConfig() string { + return sampleConfig +} + func (m *WinServices) Init() error { var err error m.servicesFilter, err = filter.NewIncludeExcludeFilter(m.ServiceNames, m.ServiceNamesExcluded) diff --git a/plugins/inputs/win_services/win_services_sample_config.go b/plugins/inputs/win_services/win_services_sample_config.go deleted file mode 100644 index 5de8f33d39dad..0000000000000 --- a/plugins/inputs/win_services/win_services_sample_config.go +++ /dev/null @@ -1,11 +0,0 @@ -//go:build windows -// +build windows - -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package win_services - -func (m *WinServices) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/inputs/wireguard/README.md b/plugins/inputs/wireguard/README.md index 1f1c7c9899266..86ebdee7a670f 100644 --- a/plugins/inputs/wireguard/README.md +++ b/plugins/inputs/wireguard/README.md @@ -6,7 +6,7 @@ reports gauge metrics for Wireguard interface device(s) and its peers. ## Configuration -```toml +```toml @sample.conf # Collect Wireguard server interface and peer statistics [[inputs.wireguard]] ## Optional list of Wireguard device/interface names to query. diff --git a/plugins/inputs/wireguard/wireguard.go b/plugins/inputs/wireguard/wireguard.go index 8fe602b24e3d5..62fd58d9387ad 100644 --- a/plugins/inputs/wireguard/wireguard.go +++ b/plugins/inputs/wireguard/wireguard.go @@ -1,6 +1,8 @@ +//go:generate ../../../tools/readme_config_includer/generator package wireguard import ( + _ "embed" "fmt" "golang.zx2c4.com/wireguard/wgctrl" @@ -10,6 +12,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 + const ( measurementDevice = "wireguard_device" measurementPeer = "wireguard_peer" @@ -32,6 +38,10 @@ type Wireguard struct { client *wgctrl.Client } +func (*Wireguard) SampleConfig() string { + return sampleConfig +} + func (wg *Wireguard) Init() error { var err error diff --git a/plugins/inputs/wireguard/wireguard_sample_config.go b/plugins/inputs/wireguard/wireguard_sample_config.go deleted file mode 100644 index e5b7ef940af9d..0000000000000 --- a/plugins/inputs/wireguard/wireguard_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package wireguard - -func (wg *Wireguard) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/inputs/wireless/README.md b/plugins/inputs/wireless/README.md index b46a4604834ea..27ae639c88aeb 100644 --- a/plugins/inputs/wireless/README.md +++ b/plugins/inputs/wireless/README.md @@ -4,7 +4,7 @@ The wireless plugin gathers metrics about wireless link quality by reading the ` ## Configuration -```toml +```toml @sample.conf # Monitor wifi signal strength and quality [[inputs.wireless]] ## Sets 'proc' directory path diff --git a/plugins/inputs/wireless/wireless.go b/plugins/inputs/wireless/wireless.go index df063d81827d9..81e3e737a4a40 100644 --- a/plugins/inputs/wireless/wireless.go +++ b/plugins/inputs/wireless/wireless.go @@ -1,16 +1,27 @@ +//go:generate ../../../tools/readme_config_includer/generator package wireless import ( + _ "embed" + "github.com/influxdata/telegraf" "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 + // Wireless is used to store configuration values. type Wireless struct { HostProc string `toml:"host_proc"` Log telegraf.Logger `toml:"-"` } +func (*Wireless) SampleConfig() string { + return sampleConfig +} + func init() { inputs.Add("wireless", func() telegraf.Input { return &Wireless{} diff --git a/plugins/inputs/wireless/wireless_sample_config.go b/plugins/inputs/wireless/wireless_sample_config.go deleted file mode 100644 index d878df8f59b12..0000000000000 --- a/plugins/inputs/wireless/wireless_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package wireless - -func (w *Wireless) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/inputs/x509_cert/README.md b/plugins/inputs/x509_cert/README.md index 1412c4bd9ab4e..b40d63150447d 100644 --- a/plugins/inputs/x509_cert/README.md +++ b/plugins/inputs/x509_cert/README.md @@ -7,7 +7,7 @@ When using a UDP address as a certificate source, the server must support [DTLS] ## Configuration -```toml +```toml @sample.conf # Reads metrics from a SSL certificate [[inputs.x509_cert]] ## List certificate sources, support wildcard expands for files diff --git a/plugins/inputs/x509_cert/x509_cert.go b/plugins/inputs/x509_cert/x509_cert.go index 28acb676130fb..a7b3e192ecba7 100644 --- a/plugins/inputs/x509_cert/x509_cert.go +++ b/plugins/inputs/x509_cert/x509_cert.go @@ -1,3 +1,4 @@ +//go:generate ../../../tools/readme_config_includer/generator // Package x509_cert reports metrics from an SSL certificate. package x509_cert @@ -5,6 +6,7 @@ import ( "bytes" "crypto/tls" "crypto/x509" + _ "embed" "encoding/pem" "fmt" "net" @@ -23,6 +25,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 + // X509Cert holds the configuration of the plugin. type X509Cert struct { Sources []string `toml:"sources"` @@ -254,6 +260,10 @@ func (c *X509Cert) collectCertURLs() ([]*url.URL, error) { return urls, nil } +func (*X509Cert) SampleConfig() string { + return sampleConfig +} + // Gather adds metrics into the accumulator. func (c *X509Cert) Gather(acc telegraf.Accumulator) error { now := time.Now() diff --git a/plugins/inputs/x509_cert/x509_cert_sample_config.go b/plugins/inputs/x509_cert/x509_cert_sample_config.go deleted file mode 100644 index b5f0c8b341504..0000000000000 --- a/plugins/inputs/x509_cert/x509_cert_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package x509_cert - -func (c *X509Cert) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/inputs/xtremio/README.md b/plugins/inputs/xtremio/README.md index dae2b22720016..0298dfa276062 100644 --- a/plugins/inputs/xtremio/README.md +++ b/plugins/inputs/xtremio/README.md @@ -4,7 +4,7 @@ The `xtremio` plugin gathers metrics from a Dell EMC XtremIO Storage Array's V3 ## Configuration -```toml +```toml @sample.conf # Gathers Metrics From a Dell EMC XtremIO Storage Array's V3 API [[inputs.xtremio]] ## XtremIO User Interface Endpoint diff --git a/plugins/inputs/xtremio/xtremio.go b/plugins/inputs/xtremio/xtremio.go index a632955adad6e..46e2e7f4e57f8 100644 --- a/plugins/inputs/xtremio/xtremio.go +++ b/plugins/inputs/xtremio/xtremio.go @@ -1,6 +1,8 @@ +//go:generate ../../../tools/readme_config_includer/generator package xtremio import ( + _ "embed" "encoding/json" "errors" "fmt" @@ -15,6 +17,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 XtremIO struct { Username string `toml:"username"` Password string `toml:"password"` @@ -27,6 +33,10 @@ type XtremIO struct { client *http.Client } +func (*XtremIO) SampleConfig() string { + return sampleConfig +} + func (xio *XtremIO) Init() error { if xio.Username == "" { return errors.New("username cannot be empty") diff --git a/plugins/inputs/xtremio/xtremio_sample_config.go b/plugins/inputs/xtremio/xtremio_sample_config.go deleted file mode 100644 index fc343a203221b..0000000000000 --- a/plugins/inputs/xtremio/xtremio_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package xtremio - -func (xio *XtremIO) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/inputs/zfs/README.md b/plugins/inputs/zfs/README.md index 44a0974b08211..aaca3c116aed2 100644 --- a/plugins/inputs/zfs/README.md +++ b/plugins/inputs/zfs/README.md @@ -6,7 +6,7 @@ from `sysctl`, 'zfs' and `zpool` on FreeBSD. ## Configuration -```toml +```toml @sample.conf # Read metrics of ZFS from arcstats, zfetchstats, vdev_cache_stats, pools and datasets [[inputs.zfs]] ## ZFS kstat path. Ignored on FreeBSD diff --git a/plugins/inputs/zfs/zfs.go b/plugins/inputs/zfs/zfs.go index 8902a00d81ccb..759fce421d5bb 100644 --- a/plugins/inputs/zfs/zfs.go +++ b/plugins/inputs/zfs/zfs.go @@ -1,9 +1,16 @@ +//go:generate ../../../tools/readme_config_includer/generator package zfs import ( + _ "embed" + "github.com/influxdata/telegraf" ) +// DO NOT REMOVE THE NEXT TWO LINES! This is required to embedd the sampleConfig data. +//go:embed sample.conf +var sampleConfig string + type Sysctl func(metric string) ([]string, error) type Zpool func() ([]string, error) type Zdataset func(properties []string) ([]string, error) @@ -18,3 +25,7 @@ type Zfs struct { zdataset Zdataset //nolint:varcheck,unused // False positive - this var is used for non-default build tag: freebsd Log telegraf.Logger `toml:"-"` } + +func (*Zfs) SampleConfig() string { + return sampleConfig +} diff --git a/plugins/inputs/zfs/zfs_linux.go b/plugins/inputs/zfs/zfs_linux.go index 940fe1099d17b..571e9fedef5ad 100644 --- a/plugins/inputs/zfs/zfs_linux.go +++ b/plugins/inputs/zfs/zfs_linux.go @@ -169,7 +169,7 @@ func gatherPoolStats(pool poolInfo, acc telegraf.Accumulator) error { case v2: fields, gatherErr = gatherV2(lines, tags) case unknown: - return errors.New("Unknown metrics version detected") + return errors.New("unknown metrics version detected") } if gatherErr != nil { diff --git a/plugins/inputs/zfs/zfs_sample_config.go b/plugins/inputs/zfs/zfs_sample_config.go deleted file mode 100644 index 466558426605d..0000000000000 --- a/plugins/inputs/zfs/zfs_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package zfs - -func (z *Zfs) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/inputs/zipkin/README.md b/plugins/inputs/zipkin/README.md index 1a03d588ca2c9..58eb0342b62ea 100644 --- a/plugins/inputs/zipkin/README.md +++ b/plugins/inputs/zipkin/README.md @@ -2,12 +2,12 @@ This plugin implements the Zipkin http server to gather trace and timing data needed to troubleshoot latency problems in microservice architectures. -*Please Note: This plugin is experimental; Its data schema may be subject to change -based on its main usage cases and the evolution of the OpenTracing standard.* +__Please Note:__ This plugin is experimental; Its data schema may be subject to change +based on its main usage cases and the evolution of the OpenTracing standard. ## Configuration -```toml +```toml @sample.conf # This plugin implements the Zipkin http server to gather trace and timing data needed to troubleshoot latency problems in microservice architectures. [[inputs.zipkin]] # path = "/api/v1/spans" # URL path for span data @@ -26,7 +26,7 @@ Traces are built by collecting all Spans that share a traceId. - __SPAN:__ is a set of Annotations and BinaryAnnotations that correspond to a particular RPC. -- __Annotations:__ for each annotation & binary annotation of a span a metric is output. *Records an occurrence in time at the beginning and end of a request.* +- __Annotations:__ for each annotation & binary annotation of a span a metric is output. _Records an occurrence in time at the beginning and end of a request._ Annotations may have the following values: diff --git a/plugins/inputs/zipkin/zipkin.go b/plugins/inputs/zipkin/zipkin.go index be6f9c95a6bd1..4c1aaae64eb0f 100644 --- a/plugins/inputs/zipkin/zipkin.go +++ b/plugins/inputs/zipkin/zipkin.go @@ -1,7 +1,9 @@ +//go:generate ../../../tools/readme_config_includer/generator package zipkin import ( "context" + _ "embed" "fmt" "net" "net/http" @@ -15,6 +17,10 @@ import ( "github.com/influxdata/telegraf/plugins/inputs/zipkin/trace" ) +// DO NOT REMOVE THE NEXT TWO LINES! This is required to embedd the sampleConfig data. +//go:embed sample.conf +var sampleConfig string + const ( // DefaultPort is the default port zipkin listens on, which zipkin implementations // expect. @@ -63,6 +69,10 @@ type Zipkin struct { waitGroup *sync.WaitGroup } +func (*Zipkin) SampleConfig() string { + return sampleConfig +} + // Gather is empty for the zipkin plugin; all gathering is done through // the separate goroutine launched in (*Zipkin).Start() func (z *Zipkin) Gather(_ telegraf.Accumulator) error { return nil } diff --git a/plugins/inputs/zipkin/zipkin_sample_config.go b/plugins/inputs/zipkin/zipkin_sample_config.go deleted file mode 100644 index a7bad2f40a361..0000000000000 --- a/plugins/inputs/zipkin/zipkin_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package zipkin - -func (z Zipkin) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/inputs/zookeeper/README.md b/plugins/inputs/zookeeper/README.md index 76c89aac22d46..bd458d406ef17 100644 --- a/plugins/inputs/zookeeper/README.md +++ b/plugins/inputs/zookeeper/README.md @@ -5,7 +5,7 @@ The zookeeper plugin collects variables outputted from the 'mntr' command ## Configuration -```toml +```toml @sample.conf # Reads 'mntr' stats from one or many zookeeper servers [[inputs.zookeeper]] ## An array of address to gather stats about. Specify an ip or hostname diff --git a/plugins/inputs/zookeeper/zookeeper.go b/plugins/inputs/zookeeper/zookeeper.go index 8581da9c3ac99..318ed532288cc 100644 --- a/plugins/inputs/zookeeper/zookeeper.go +++ b/plugins/inputs/zookeeper/zookeeper.go @@ -1,9 +1,11 @@ +//go:generate ../../../tools/readme_config_includer/generator package zookeeper import ( "bufio" "context" "crypto/tls" + _ "embed" "fmt" "net" "regexp" @@ -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 + var zookeeperFormatRE = regexp.MustCompile(`^zk_(\w[\w\.\-]*)\s+([\w\.\-]+)`) // Zookeeper is a zookeeper plugin @@ -46,6 +52,10 @@ func (z *Zookeeper) dial(ctx context.Context, addr string) (net.Conn, error) { return dialer.DialContext(ctx, "tcp", addr) } +func (*Zookeeper) SampleConfig() string { + return sampleConfig +} + // Gather reads stats from all configured servers accumulates stats func (z *Zookeeper) Gather(acc telegraf.Accumulator) error { ctx := context.Background() diff --git a/plugins/inputs/zookeeper/zookeeper_sample_config.go b/plugins/inputs/zookeeper/zookeeper_sample_config.go deleted file mode 100644 index e13ab459b6c6d..0000000000000 --- a/plugins/inputs/zookeeper/zookeeper_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package zookeeper - -func (z *Zookeeper) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/parsers/xpath/README.md b/plugins/parsers/xpath/README.md index cc5b553fc37c9..13040300d7f37 100644 --- a/plugins/parsers/xpath/README.md +++ b/plugins/parsers/xpath/README.md @@ -4,7 +4,7 @@ The XPath data format parser parses different formats into metric fields using [ For supported XPath functions check [the underlying XPath library][xpath lib]. -**NOTE:** The type of fields are specified using [XPath functions][xpath lib]. The only exception are *integer* fields that need to be specified in a `fields_int` section. +__NOTE:__ The type of fields are specified using [XPath functions][xpath lib]. The only exception are _integer_ fields that need to be specified in a `fields_int` section. ## Supported data formats @@ -17,7 +17,7 @@ For supported XPath functions check [the underlying XPath library][xpath lib]. ### Protocol-buffers additional settings -For using the protocol-buffer format you need to specify additional (*mandatory*) properties for the parser. Those options are described here. +For using the protocol-buffer format you need to specify additional (_mandatory_) properties for the parser. Those options are described here. #### `xpath_protobuf_file` (mandatory) @@ -124,7 +124,7 @@ In this configuration mode, you explicitly specify the field and tags you want t ok = "Mode != 'ok'" ``` -A configuration can contain muliple *xpath* subsections for e.g. the file plugin to process the xml-string multiple times. Consult the [XPath syntax][xpath] and the [underlying library's functions][xpath lib] for details and help regarding XPath queries. Consider using an XPath tester such as [xpather.com][xpather] or [Code Beautify's XPath Tester][xpath tester] for help developing and debugging +A configuration can contain muliple _xpath_ subsections for e.g. the file plugin to process the xml-string multiple times. Consult the [XPath syntax][xpath] and the [underlying library's functions][xpath lib] for details and help regarding XPath queries. Consider using an XPath tester such as [xpather.com][xpather] or [Code Beautify's XPath Tester][xpath tester] for help developing and debugging your query. ## Configuration (batch) @@ -209,7 +209,8 @@ metric. ``` -**Please note**: The resulting fields are *always* of type string! +__Please note__: The resulting fields are _always_ of type string! +_Please note_: The resulting fields are _always_ of type string! It is also possible to specify a mixture of the two alternative ways of specifying fields. @@ -238,13 +239,13 @@ If `timestamp_format` is omitted `unix` format is assumed as result of the `time [XPath][xpath] queries in the `tag name = query` format to add tags to the metrics. The specified path can be absolute (starting with `/`) or relative. Relative paths use the currently selected node as reference. -**NOTE:** Results of tag-queries will always be converted to strings. +__NOTE:__ Results of tag-queries will always be converted to strings. ### fields_int sub-section [XPath][xpath] queries in the `field name = query` format to add integer typed fields to the metrics. The specified path can be absolute (starting with `/`) or relative. Relative paths use the currently selected node as reference. -**NOTE:** Results of field_int-queries will always be converted to **int64**. The conversion will fail in case the query result is not convertible! +__NOTE:__ Results of field_int-queries will always be converted to __int64__. The conversion will fail in case the query result is not convertible! ### fields sub-section @@ -253,22 +254,22 @@ If `timestamp_format` is omitted `unix` format is assumed as result of the `time The type of the field is specified in the [XPath][xpath] query using the type conversion functions of XPath such as `number()`, `boolean()` or `string()` If no conversion is performed in the query the field will be of type string. -**NOTE: Path conversion functions will always succeed even if you convert a text to float!** +__NOTE: Path conversion functions will always succeed even if you convert a text to float!__ ### field_selection, field_name, field_value (optional) You can specify a [XPath][xpath] query to select a set of nodes forming the fields of the metric. The specified path can be absolute (starting with `/`) or relative to the currently selected node. Each node selected by `field_selection` forms a new field within the metric. -The *name* and the *value* of each field can be specified using the optional `field_name` and `field_value` queries. The queries are relative to the selected field if not starting with `/`. If not specified the field's *name* defaults to the node name and the field's *value* defaults to the content of the selected field node. -**NOTE**: `field_name` and `field_value` queries are only evaluated if a `field_selection` is specified. +The _name_ and the _value_ of each field can be specified using the optional `field_name` and `field_value` queries. The queries are relative to the selected field if not starting with `/`. If not specified the field's _name_ defaults to the node name and the field's _value_ defaults to the content of the selected field node. +__NOTE__: `field_name` and `field_value` queries are only evaluated if a `field_selection` is specified. Specifying `field_selection` is optional. This is an alternative way to specify fields especially for documents where the node names are not known a priori or if there is a large number of fields to be specified. These options can also be combined with the field specifications above. -**NOTE: Path conversion functions will always succeed even if you convert a text to float!** +__NOTE: Path conversion functions will always succeed even if you convert a text to float!__ ### field_name_expansion (optional) -When *true*, field names selected with `field_selection` are expanded to a *path* relative to the *selected node*. This +When _true_, field names selected with `field_selection` are expanded to a _path_ relative to the _selected node_. This is necessary if we e.g. select all leaf nodes as fields and those leaf nodes do not have unique names. That is in case you have duplicate names in the fields you select you should set this to `true`. @@ -276,14 +277,14 @@ you have duplicate names in the fields you select you should set this to `true`. You can specify a [XPath][xpath] query to select a set of nodes forming the tags of the metric. The specified path can be absolute (starting with `/`) or relative to the currently selected node. Each node selected by `tag_selection` forms a new tag within the metric. -The *name* and the *value* of each tag can be specified using the optional `tag_name` and `tag_value` queries. The queries are relative to the selected tag if not starting with `/`. If not specified the tag's *name* defaults to the node name and the tag's *value* defaults to the content of the selected tag node. -**NOTE**: `tag_name` and `tag_value` queries are only evaluated if a `tag_selection` is specified. +The _name_ and the _value_ of each tag can be specified using the optional `tag_name` and `tag_value` queries. The queries are relative to the selected tag if not starting with `/`. If not specified the tag's _name_ defaults to the node name and the tag's _value_ defaults to the content of the selected tag node. +__NOTE__: `tag_name` and `tag_value` queries are only evaluated if a `tag_selection` is specified. Specifying `tag_selection` is optional. This is an alternative way to specify tags especially for documents where the node names are not known a priori or if there is a large number of tags to be specified. These options can also be combined with the tag specifications above. ### tag_name_expansion (optional) -When *true*, tag names selected with `tag_selection` are expanded to a *path* relative to the *selected node*. This +When _true_, tag names selected with `tag_selection` are expanded to a _path_ relative to the _selected node_. This is necessary if we e.g. select all leaf nodes as tags and those leaf nodes do not have unique names. That is in case you have duplicate names in the tags you select you should set this to `true`. @@ -353,8 +354,8 @@ Output: file,gateway=Main,host=Hugin seqnr=12i,ok=true 1598610830000000000 ``` -In the *tags* definition the XPath function `substring-before()` is used to only extract the sub-string before the space. To get the integer value of `/Gateway/Sequence` we have to use the *fields_int* section as there is no XPath expression to convert node values to integers (only float). -The `ok` field is filled with a boolean by specifying a query comparing the query result of `/Gateway/Status` with the string *ok*. Use the type conversions available in the XPath syntax to specify field types. +In the _tags_ definition the XPath function `substring-before()` is used to only extract the sub-string before the space. To get the integer value of `/Gateway/Sequence` we have to use the _fields_int_ section as there is no XPath expression to convert node values to integers (only float). +The `ok` field is filled with a boolean by specifying a query comparing the query result of `/Gateway/Status` with the string _ok_. Use the type conversions available in the XPath syntax to specify field types. ### Time and metric names @@ -390,7 +391,7 @@ Additionally to the basic parsing example, the metric name is defined as the nam ### Multi-node selection -For XML documents containing metrics for e.g. multiple devices (like `Sensor`s in the *example.xml*), multiple metrics can be generated using node selection. This example shows how to generate a metric for each *Sensor* in the example. +For XML documents containing metrics for e.g. multiple devices (like `Sensor`s in the _example.xml_), multiple metrics can be generated using node selection. This example shows how to generate a metric for each _Sensor_ in the example. Config: @@ -433,7 +434,7 @@ Using the `metric_selection` option we select all `Sensor` nodes in the XML docu ### Batch field processing with multi-node selection -For XML documents containing metrics with a large number of fields or where the fields are not known before (e.g. an unknown set of `Variable` nodes in the *example.xml*), field selectors can be used. This example shows how to generate a metric for each *Sensor* in the example with fields derived from the *Variable* nodes. +For XML documents containing metrics with a large number of fields or where the fields are not known before (e.g. an unknown set of `Variable` nodes in the _example.xml_), field selectors can be used. This example shows how to generate a metric for each _Sensor_ in the example with fields derived from the _Variable_ nodes. Config: @@ -465,8 +466,8 @@ sensors,host=Hugin,name=Facility\ B consumers=1,frequency=49.78,power=14.3,tempe sensors,host=Hugin,name=Facility\ C consumers=0,frequency=49.78,power=0.02,temperature=19.7 1596294243000000000 ``` -Using the `metric_selection` option we select all `Sensor` nodes in the XML document. For each *Sensor* we then use `field_selection` to select all child nodes of the sensor as *field-nodes* Please note that the field selection is relative to the selected nodes. -For each selected *field-node* we use `field_name` and `field_value` to determining the field's name and value, respectively. The `field_name` derives the name of the first attribute of the node, while `field_value` derives the value of the first attribute and converts the result to a number. +Using the `metric_selection` option we select all `Sensor` nodes in the XML document. For each _Sensor_ we then use `field_selection` to select all child nodes of the sensor as _field-nodes_ Please note that the field selection is relative to the selected nodes. +For each selected _field-node_ we use `field_name` and `field_value` to determining the field's name and value, respectively. The `field_name` derives the name of the first attribute of the node, while `field_value` derives the value of the first attribute and converts the result to a number. [xpath lib]: https://github.com/antchfx/xpath [json]: https://www.json.org/ diff --git a/plugins/processors/defaults/README.md b/plugins/processors/defaults/README.md index 576333b38c0d0..ee04441931766 100644 --- a/plugins/processors/defaults/README.md +++ b/plugins/processors/defaults/README.md @@ -1,6 +1,6 @@ # Defaults Processor -The *Defaults* processor allows you to ensure certain fields will always exist with a specified default value on your metric(s). +The _Defaults_ processor allows you to ensure certain fields will always exist with a specified default value on your metric(s). There are three cases where this processor will insert a configured default field. diff --git a/plugins/processors/noise/README.md b/plugins/processors/noise/README.md index 94c4e8d3fc5ac..ab39fc879691a 100644 --- a/plugins/processors/noise/README.md +++ b/plugins/processors/noise/README.md @@ -1,6 +1,6 @@ # Noise Processor -The *Noise* processor is used to add noise to numerical field values. For each field a noise is generated using a defined probability densitiy function and added to the value. The function type can be configured as _Laplace_, _Gaussian_ or _Uniform_. +The _Noise_ processor is used to add noise to numerical field values. For each field a noise is generated using a defined probability densitiy function and added to the value. The function type can be configured as _Laplace_, _Gaussian_ or _Uniform_. Depending on the function, various parameters need to be configured: ## Configuration @@ -36,25 +36,25 @@ The following distribution functions are available. ### Laplacian -* `noise_type = laplacian` -* `scale`: also referred to as _diversity_ parameter, regulates the width & height of the function, a bigger `scale` value means a higher probability of larger noise, default set to 1.0 -* `mu`: location of the curve, default set to 0.0 +- `noise_type = laplacian` +- `scale`: also referred to as _diversity_ parameter, regulates the width & height of the function, a bigger `scale` value means a higher probability of larger noise, default set to 1.0 +- `mu`: location of the curve, default set to 0.0 ### Gaussian -* `noise_type = gaussian` -* `mu`: mean value, default set to 0.0 -* `scale`: standard deviation, default set to 1.0 +- `noise_type = gaussian` +- `mu`: mean value, default set to 0.0 +- `scale`: standard deviation, default set to 1.0 ### Uniform -* `noise_type = uniform` -* `min`: minimal interval value, default set to -1.0 -* `max`: maximal interval value, default set to 1.0 +- `noise_type = uniform` +- `min`: minimal interval value, default set to -1.0 +- `max`: maximal interval value, default set to 1.0 ## Example -Add noise to each value the *Inputs.CPU* plugin generates, except for the _usage\_steal_, _usage\_user_, _uptime\_format_, _usage\_idle_ field and all fields of the metrics _swap_, _disk_ and _net_: +Add noise to each value the _inputs.cpu_ plugin generates, except for the _usage\_steal_, _usage\_user_, _uptime\_format_, _usage\_idle_ field and all fields of the metrics _swap_, _disk_ and _net_: ```toml [[inputs.cpu]] diff --git a/tools/readme_config_includer/generator.go b/tools/readme_config_includer/generator.go new file mode 100644 index 0000000000000..c6e266efec405 --- /dev/null +++ b/tools/readme_config_includer/generator.go @@ -0,0 +1,170 @@ +// This is a tool to embedd configuration files into the README.md of all plugins +// It searches for TOML sections in the plugins' README.md and detects includes specified in the form +// ```toml [@includeA.conf[ @includeB[ @...]] +// Whatever is in here gets replaced. +// ``` +// Then it will replace everything in this section by the concatenation of the file `includeA.conf`, `includeB` etc. +// content. The tool is not stateful, so it can be run multiple time with a stable result as long +// as the included files do not change. +package main + +import ( + "bytes" + "errors" + "fmt" + "io" + "log" //nolint:revive + "os" + "regexp" + "strings" + + "github.com/yuin/goldmark" + "github.com/yuin/goldmark/ast" + "github.com/yuin/goldmark/text" +) + +type includeBlock struct { + Includes []string + Start int + Stop int +} + +func (b *includeBlock) extractBlockBorders(node *ast.FencedCodeBlock) { + // The node info starts at the language tag and stops right behind it + b.Start = node.Info.Segment.Stop + 1 + b.Stop = b.Start + + // To determine the end of the block, we need to iterate to the last line + // and take its stop-offset as the end of the block. + lines := node.Lines() + for i := 0; i < lines.Len(); i++ { + b.Stop = lines.At(i).Stop + } +} + +func insertInclude(buf *bytes.Buffer, include string) error { + file, err := os.Open(include) + if err != nil { + return fmt.Errorf("opening include %q failed: %v", include, err) + } + defer file.Close() + + // Write the include and make sure we get a newline + if _, err := io.Copy(buf, file); err != nil { + return fmt.Errorf("inserting include %q failed: %v", include, err) + } + return nil +} + +func insertIncludes(buf *bytes.Buffer, b includeBlock) error { + // Insert all includes in the order they occured + for _, include := range b.Includes { + if err := insertInclude(buf, include); err != nil { + return err + } + } + // Make sure we add a trailing newline + if !bytes.HasSuffix(buf.Bytes(), []byte("\n")) { + if _, err := buf.Write([]byte("\n")); err != nil { + return errors.New("adding newline failed") + } + } + + return nil +} + +func main() { + // Finds all TOML sections of the form `toml @includefile` and extracts the `includefile` part + tomlIncludesEx := regexp.MustCompile(`^toml\s+(@.+)+$`) + tomlIncludeMatch := regexp.MustCompile(`(?:@([^\s]+))+`) + + // Get the file permission of the README for later use + inputFilename := "README.md" + inputFileInfo, err := os.Lstat(inputFilename) + if err != nil { + log.Fatalf("Cannot get file permissions: %v", err) + } + perm := inputFileInfo.Mode().Perm() + + // Read and parse the README markdown file + readme, err := os.ReadFile(inputFilename) + if err != nil { + log.Fatalf("Reading README failed: %v", err) + } + parser := goldmark.DefaultParser() + root := parser.Parse(text.NewReader(readme)) + + // Walk the markdown to identify the (TOML) parts to replace + blocksToReplace := make([]includeBlock, 0) + for node := root.FirstChild(); node != nil; node = node.NextSibling() { + // Only match TOML code nodes + codeNode, ok := node.(*ast.FencedCodeBlock) + if !ok || string(codeNode.Language(readme)) != "toml" { + // Ignore any other node type or language + continue + } + + // Extract the includes from the node + includes := tomlIncludesEx.FindSubmatch(codeNode.Info.Text(readme)) + if len(includes) != 2 { + continue + } + block := includeBlock{} + for _, inc := range tomlIncludeMatch.FindAllSubmatch(includes[1], -1) { + if len(inc) != 2 { + continue + } + include := string(inc[1]) + // Safeguards to avoid directory traversals and other bad things + if strings.ContainsRune(include, os.PathSeparator) { + log.Printf("Ignoring include %q for containing a path...", include) + continue + } + if fi, err := os.Stat(include); err != nil || !fi.Mode().IsRegular() { + log.Printf("Ignoring include %q as it cannot be found or is not a regular file...", include) + continue + } + block.Includes = append(block.Includes, string(inc[1])) + } + + // Extract the block boarders + block.extractBlockBorders(codeNode) + blocksToReplace = append(blocksToReplace, block) + } + + // Replace the content of the TOML blocks with includes + var output bytes.Buffer + output.Grow(len(readme)) + offset := 0 + for _, b := range blocksToReplace { + // Copy everything up to the beginning of the block we want to replace and make sure we get a newline + if _, err := output.Write(readme[offset:b.Start]); err != nil { + log.Fatalf("Writing non-replaced content failed: %v", err) + } + if !bytes.HasSuffix(output.Bytes(), []byte("\n")) { + if _, err := output.Write([]byte("\n")); err != nil { + log.Fatalf("Writing failed: %v", err) + } + } + offset = b.Stop + + // Insert the include file + if err := insertIncludes(&output, b); err != nil { + log.Fatal(err) + } + } + // Copy the remainings of the original file... + if _, err := output.Write(readme[offset:]); err != nil { + log.Fatalf("Writing remaining content failed: %v", err) + } + + // Write output with same permission as input + file, err := os.OpenFile(inputFilename, os.O_CREATE|os.O_WRONLY, perm) + if err != nil { + log.Fatalf("Opening output file failed: %v", err) + } + defer file.Close() + if _, err := output.WriteTo(file); err != nil { + log.Fatalf("Writing output file failed: %v", err) + } +}