diff --git a/.gitignore b/.gitignore index ec7f96954..d78b6c1c1 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 7962c6a56..e3bf473f9 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 147316424..06644d12b 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 d02dc9453..a9541e99f 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 f43976909..4dcfb48d9 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 9170d43a9..000000000 --- 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 922dfeab8..f84cb5e02 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 50c1f2306..6fc29a282 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 1c42b63b4..000000000 --- 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 03e6a2748..1480c0ebc 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 9dfd8dd32..14bab4344 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 53fff350e..000000000 --- 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 392cb94e0..776ee8502 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 f613a7017..9e26cf07b 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 2508f6004..000000000 --- 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 c3455b025..11f9680ef 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 7d4ef02d8..127b57ac2 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 d92caaf7d..000000000 --- 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 710d8cbca..8c2499203 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 d03d22c32..43b4c3c0b 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 4de4091fd..000000000 --- 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 f02dc0552..d97325d7b 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 bd90103dd..7620540e8 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 7d8df9f41..000000000 --- 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 0519c97b3..58ab5fda6 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 e32a00de6..0d033ea27 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 daeb81516..000000000 --- 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 ded991064..8427e71b4 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 e582b4213..a6668e998 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 3e3b123c0..000000000 --- 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 0ab326e2d..ae5fcdc80 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 e46100d17..ba3589e4f 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 396a4815a..000000000 --- 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 feebca634..b548b1506 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 9d67b70b8..3748e3209 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 d1a820197..000000000 --- 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 ecf6f5edb..a3a5fdc49 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 b76ff0a4b..77a37d883 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 000752ff3..000000000 --- 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 eb22427d2..10e6630e0 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 d04283566..72b230682 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 278c9d709..000000000 --- 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 55ec3b812..30bc25e9a 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 ed009904a..f51c62a49 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 66d1d23bb..000000000 --- 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 5eef05f8e..619596f39 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 96c16c663..da4e931d4 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 988d4ce9e..000000000 --- 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 210d7e998..24c66b916 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 e73a4425e..460d046d3 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 b06286ad4..000000000 --- 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 3d1745884..160e0a9ab 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 99440bdf9..5dbbb57cf 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 61cbd1092..000000000 --- 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 377a92619..7b682891f 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 d67315186..167f6b1f3 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 db6f84f22..000000000 --- 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 ebb7ba65c..70a0f645c 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 1fbb4e288..80949f963 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 e0fc79ee7..000000000 --- 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 23a5ecf29..66e9d60fe 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 547237bd9..5a861a764 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 fb474a507..000000000 --- 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 b7bbe85c0..1e85a859e 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 7973476e9..92c2299ca 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 d6e2a4cce..000000000 --- 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 ea688faef..c57cab77b 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 1593eaaf0..1f825dd87 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 c07b8e983..000000000 --- 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 b67259e37..8f41fa6af 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 65018276d..de4b7fc58 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 ecb01a20f..000000000 --- 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 4a9eb0348..de64ec64c 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 4a87b1606..d02fc8451 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 2e9c84c46..000000000 --- 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 4e5bf627c..ea4df03e9 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 abbc0fc55..acd5b189f 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 f308c11d5..000000000 --- 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 609a8dfb8..e491c3ae1 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 135526d85..d2bfa5895 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 38c4c2210..000000000 --- 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 58f5ad530..67838bc12 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 85065d277..465461b14 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 1c4cf1e38..000000000 --- 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 be39100c7..419f02f7c 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 46dc2261b..4580bfed2 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 984cffdcc..000000000 --- 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 5e1b3c6df..4bb0ae8b7 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 b2f30a4cf..2296eb905 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 64cde4bbe..000000000 --- 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 e21a26149..a5c1e64a2 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 9a01de5a0..1ec06b80c 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 e195f9d83..000000000 --- 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 7b7f60394..b0254b95d 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 e6fded0fb..17c045c71 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 1c344d1c3..3f3ba73a3 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 2a1603a1a..000000000 --- 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 e3d4d9296..920b73c52 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 f3a6a6d3f..3822bc99f 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 91e8fd58d..000000000 --- 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 44257f4f8..bdcb5045f 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 45cafbe47..e29cacaa1 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 1fca93b67..000000000 --- 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 46d796456..212b903ad 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 0f4017a12..94c94be42 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 e7be4f911..000000000 --- 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 9fd0173bc..daadc3012 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 ddbea6cf6..02fd639de 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 a840e5eef..000000000 --- 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 383e7e810..c597a4152 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 351ce6759..96f3a0cad 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 ead29c67d..b7cc2e120 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 fc84362b9..000000000 --- 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 b228b3f02..64892b9e9 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 5871fc6f8..ec1181206 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 712e67900..349cb55a9 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 4b10517fc..000000000 --- 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 287addc20..cc61d7c52 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 edf406a2c..5f74505b1 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 14e14e350..000000000 --- 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 5a0585b41..81173c6e3 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 3f0c73bf1..af3ad819b 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 e25737232..000000000 --- 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 0faaf962e..079f5adbe 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 d340f4de2..9be78ff68 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 8194558c5..000000000 --- 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 573cbd1f7..09e0cf7e4 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 86e6c3805..e0d2a6974 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 c396dd9d6..000000000 --- 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 92c920dff..59a0ae9a5 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 41aaf46df..5312a041f 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 63e76a961..000000000 --- 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 b5152a3eb..66f3d34dd 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 8ef3a2f88..7c2cf3c8c 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 7ea296648..000000000 --- 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 c29173301..12ef60287 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 dcb37dac7..c796e0819 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 06f4a20fd..000000000 --- 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 67ceff4b5..3df9d5fe6 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 aa73b09bd..f682dfc3d 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 c0c5b1357..000000000 --- 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 9a805f3ca..f93d543bc 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 951b5cee9..0503aef4e 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 16081e4cd..78962b7ae 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 d3de2fdb9..000000000 --- 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 c6964b9ec..82526ebc4 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 fcc76e1af..d55b65949 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 bda841e8b..000000000 --- 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 69f66d29f..fc5f0c51b 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 1e61a51d1..752521de1 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 a5ca2518f..000000000 --- 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 3d188bbbc..49b798721 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 3369979ea..104e993dc 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 9d0d8bbf7..000000000 --- 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 31997e958..6680e95dd 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 08ef50ef7..a09c3fd61 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 bc59d8ef3..000000000 --- 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 221f9d5b4..322ea07fe 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 7961a473d..2d8aa1a63 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 ea8e27d36..000000000 --- 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 1afac3d78..0bf17f574 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 d02af0d5b..24d9fd2e2 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 aa3532868..6bb7d3310 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 fb556a448..000000000 --- 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 439c9f996..898374548 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 9f717cf24..8fdc3790c 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 aae05dce6..000000000 --- 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 1a56dd5be..0842a4722 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 e796a4163..5ab9114f9 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 f8d3bf3a4..000000000 --- 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 c8670471a..772b99201 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 2811786ee..6b919f729 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 c58f483a6..000000000 --- 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 cb5abe835..2c46a6e6f 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 ff197ab7b..bcdb69cf4 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 b4ed9bdb0..000000000 --- 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 0686af82a..c044dbc1e 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 b90a17759..c980ce84b 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 286cfc268..000000000 --- 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 549916ef0..d24825c4d 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 d78df6477..6b6e66f08 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 fc01a79c8..000000000 --- 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 49f2a160c..ab7bf2a57 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 f45bf0d8e..d017aabbb 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 4454fedee..000000000 --- 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 deb822ac5..68abbe40c 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 34614af89..1cc8ffad4 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 8191695e1..000000000 --- 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 4ce0070d9..496d97dbb 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 045dc7c79..72d1d61b2 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 7381c3ab1..000000000 --- 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 0f7523986..0a9631db4 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 82d06f0b4..154d2e4a0 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 c1fb51286..000000000 --- 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 4ec3bd26e..4fd50bdb9 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 247a95e4e..bbba049f2 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 4edad1626..000000000 --- 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 e0b68ffef..bdcfd1fa4 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 8ce14c7b0..fa452b160 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 3b2d52077..000000000 --- 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 fded2cd91..eab8a7101 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 1520a82e3..41f788a84 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 9d679aa76..000000000 --- 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 be6492a4e..57d48da15 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 233f3e1a9..4e5cc6460 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 f8a2281b7..000000000 --- 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 c08360f76..93535f9fb 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 5280932c6..bb25870e7 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 d2929fa43..000000000 --- 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 da6824e7f..336bdf0cb 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 5cfb64ed1..8314e9cdb 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 214f537a6..000000000 --- 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 441e427f3..fb630ae3a 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 dbb6d639b..bf5b72cb5 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 2868c683e..9ccb7dc2f 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 e2dc0ef99..000000000 --- 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 e13e6c4c6..76c29dd91 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 3e07437fa..0aa293f94 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 e35777fdb..000000000 --- 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 9f3b16735..755b7de5c 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 b6964ac7c..a4b8372c5 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 53000d4d2..000000000 --- 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 116a7a937..2cf48d529 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 a393e5e64..3612283c5 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 66b7c1808..000000000 --- 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 92a07d14e..9d520f0f3 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 63072c992..bd179aab3 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 ce91a4426..000000000 --- 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 0b1e5cb5d..db84ef73f 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 78336bbdf..1daeefcc8 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 24bb2d804..000000000 --- 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 75cf62a45..93e63fcf8 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 5c49d08be..a6eaa0839 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 a3ab73163..000000000 --- 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 504a7467f..a65dc5a15 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 77b840f01..4fba5a292 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 6e98ac4c4..7d7cd1bd6 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 ce21dcdb3..000000000 --- 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 015b0b0a8..07254ebd8 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 a1160d0ef..8d4c4820d 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 572222aab..000000000 --- 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 d195fa57e..ccea19690 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 7e7092995..6383460e2 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 2f917971a..000000000 --- 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 9bcc7eb1d..b4a484457 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 73eb3330a..160fcd66b 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 b1edb6b8a..000000000 --- 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 3b152f8e0..ba9b90854 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 d0cac7d0b..18c7e610d 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 292682c93..000000000 --- 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 1377df84b..665a4f1da 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 4cb80f4b0..0b425c62d 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 27840458d..000000000 --- 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 7e5529edc..24f0e4636 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 b99cf0aa9..000000000 --- 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 1354182e1..1a31d9ccc 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 895a4b5cf..deeb7cae1 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 9d12ad46c..f1ac43859 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 8094b58dd..000000000 --- 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 12d8005c1..1bc3f2cb1 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 393d7e932..b2f679f7e 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 985786650..000000000 --- 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 755277ed8..b9d9e97bb 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 58d6b207f..6e3927d92 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 ee4143ddd..000000000 --- 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 f089cee8f..b73db9823 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 a624bfc30..1bb70abba 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 9a82a9d2f..000000000 --- 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 d3467e826..a2063a332 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 3afcd4bff..ea5a6bd02 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 7109de4c2..000000000 --- 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 a5e54f158..f5a9773b6 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 b34d2654d..e54cba84d 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 98f0dd27a..000000000 --- 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 d3391eb2b..e0d95f61a 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 749c8d927..c99b8a1f9 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 d4d889e2c..000000000 --- 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 0306627ee..d571d887f 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 343c4b082..5bd5ba083 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 df1e931f3..000000000 --- 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 14d77556f..04acac83a 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 6ecd1865c..bde61ebb7 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 a40272dd0..000000000 --- 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 f58f0e2f8..0f3150e7b 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 87af3b4de..be804d679 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 c18c20175..000000000 --- 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 035bdb856..c0b4c96c7 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 7a2301919..a1e967531 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 777ed7f4a..000000000 --- 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 589f6773a..650039cca 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 6af46f096..525877336 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 31c66d7d3..000000000 --- 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 4034a7fe9..dcb1448c7 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 2888cb23c..bc7e22860 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 94cd25f1e..000000000 --- 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 a5a03037f..1fbf6e9fb 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 61fa3709b..26891d8e4 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 a232cf557..000000000 --- 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 3fd2f1de8..f8b812570 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 5c21659e9..bbcae9e35 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 aa052b898..000000000 --- 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 d582262d8..1f09eb830 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 a8508f5a4..634861e8e 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 c9c62e6d0..000000000 --- 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 0142c0cf5..8d2e562c3 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 73762be8d..143d86549 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 2e1a031f1..000000000 --- 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 40f37500b..f02670776 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 8ae6526b8..5afccfb9b 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 a7caf7252..000000000 --- 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 fe9d40326..9086898d6 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 3a4cf04be..0c4d4be91 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 71dc38533..000000000 --- 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 539cb531b..50260f7c4 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 b4b2078e6..b07155ff0 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 0616e7536..000000000 --- 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 a657ef125..147935b2c 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 8867081f9..71c408916 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 3b3a1fc1a..000000000 --- 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 462ac89ca..4bdcf349e 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 d844b2ad8..977b2f592 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 a29d296a5..000000000 --- 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 000000000..b3c5e677e --- /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 000000000..f6245caed --- /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 000000000..ebfaf636d --- /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 000000000..717b04e2d --- /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 64aa2a73f..8715ec1ed 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 946334346..8086f6492 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 fd8ac219f..000000000 --- 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 f166252e0..ddb7ba4e1 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 066df6992..c6b36c684 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 9a3e28305..000000000 --- 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 350ec5c46..e4742088b 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 27b46d23c..a0d4867dd 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 2509c01bc..000000000 --- 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 3df7b32cb..23ce116ab 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 fd2f2fa3e..c4026f8e9 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 ce2ae8009..000000000 --- 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 214cebd13..13c9457b1 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 3e1ed6b47..54199f170 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 41bc76c81..71b418931 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 8551b8e38..000000000 --- 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 7ddbfe7be..58deef132 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 98914bb41..f7dbdb516 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 09bf69113..000000000 --- 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 aa73c0355..b3865dca7 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 715206fe4..67a32cf95 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 baa02fdb2..000000000 --- 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 e43dbe084..5ded8abd1 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 4a2003c04..4c1c0bbb7 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 809c69f6c..000000000 --- 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 243293b93..798861b25 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 7403349f1..0615ae845 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 04d2950d2..000000000 --- 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 e64a7ebf6..ffae42a3d 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 1e8b6cf39..a768818cc 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 ad4c2a9c4..000000000 --- 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 a074e5c07..20b83ba48 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 5b52405c1..000000000 --- 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 e5cca8bac..ef631ccff 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 5936e8b66..4e452711c 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 4fd51e37d..000000000 --- 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 4859aa74c..685c20097 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 ed3d2c223..c89706c0e 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 b531aa6a0..000000000 --- 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 a56908a1d..f92c65e4a 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 276d6e5b8..21e2862ca 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 c8de4f608..000000000 --- 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 516e68126..04a7a413b 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 95d037a0f..c5c035a3c 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 3116e7869..000000000 --- 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 bacc1a32a..a935da463 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 7d2327910..703309508 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 a2b87daea..000000000 --- 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 6321f3f48..058672b25 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 d925ce87e..2cd1ca8cd 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 33397b164..000000000 --- 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 9d446f8c5..58f122e7e 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 29343dd7e..eaf765c9d 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 5eabb07e0..000000000 --- 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 508f5d64b..cc3aae384 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 debd07c12..85d5f6b1d 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 b8750dfc0..000000000 --- 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 51c45b1f4..f2364e321 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 4b633148c..95c508d59 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 ed25231c7..000000000 --- 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 6d25a9c42..4ea42bf88 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 dec8ccd74..9d86c02e7 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 75efaba5a..000000000 --- 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 b10bfbf6f..d2fc086ed 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 086c71722..d7d174cf3 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 58597d2b6..000000000 --- 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 72d4ffb40..b233819bc 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 2feddb3b6..c811f0658 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 ffed972bc..000000000 --- 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 79838b5c0..1ec26b516 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 91ba1c444..53fd42f4f 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 71afaf57e..000000000 --- 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 2ca257c27..d52b7d6eb 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 bc4b57157..d9c297e36 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 9919a1f1b..000000000 --- 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 e8505c694..cfc127600 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 66fbdcb68..44b8a6f29 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 4d8f96cea..000000000 --- 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 2acc03661..adb7d2dd3 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 45ae42a35..198023b90 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 f9705bd79..000000000 --- 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 c8cb7edab..25eaddd47 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 b5c293cc3..d599342f9 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 a6a5964d0..000000000 --- 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 5aaad1a35..d1ad9bca6 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 7159e47a6..cbd2c6868 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 d4f3cc03d..000000000 --- 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 0a70426d6..6b53f45bf 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 1da597946..38b6bc841 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 7168ea6e2..000000000 --- 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 f876cf73a..21522390a 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 798c9fe7d..944c83f99 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 82380c71d..000000000 --- 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 dc2d44a12..f6884371f 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 7876d81dd..73a3f2e17 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 e6444a6b1..000000000 --- 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 4300fd362..343f44139 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 1259b7716..96730328f 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 7a793b01c..000000000 --- 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 8f97af524..71c532829 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 40a8efb4b..33b576231 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 ab7663d76..000000000 --- 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 4539651cc..df323da9f 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 a3d5e1082..f4a86ab14 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 6150e515e..000000000 --- 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 8e7a6960c..a1b3759c6 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 52ef1f7f8..c0b1c1375 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 82460af25..000000000 --- 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 2d56ae1f6..2876ddafb 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 d2e07df83..ab755b0b9 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 7fb1867b8..000000000 --- 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 9388a9225..069bd7453 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 f4faeff84..fbbe6522d 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 8ec9ad99d..000000000 --- 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 ecc256a0a..9cb1f3fd4 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 d7769e7d3..9a3beef1e 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 f574107d4..000000000 --- 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 79789f8a5..6ac81a6dc 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 bbd647e08..844fc2bb5 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 34efab6ca..000000000 --- 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 6222bf6ca..56e1efcdb 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 04aaca527..422cfdbc8 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 71409d7ac..000000000 --- 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 0b713859f..377e1ef0e 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 ad7cea4ac..f4596c879 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 7f3e28320..000000000 --- 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 ac561f936..6de14cb58 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 5f0a008e0..35c778e13 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 070dce65f..9395d3443 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 2ee5d7406..000000000 --- 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 5dd673cfd..4b447db59 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 e20270534..89226fe30 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 ae39ee2ba..000000000 --- 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 074994620..b1c2b382b 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 28a934a3e..2d04a3081 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 b5811d895..000000000 --- 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 938747450..0ca6f5b6e 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 f4d9d2be9..e85f7f3f8 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 9b832a557..000000000 --- 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 153dfc9ef..df18a5d57 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 712498e91..f22c7ccd2 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 0de8ef4fe..000000000 --- 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 2205a1e57..275637b88 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 c7fe98566..1958eb28c 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 0a147aaaa..000000000 --- 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 0e06fa1ee..13079b88e 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 4084602ce..cb815b01f 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 e09b38f04..000000000 --- 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 beb65f056..b405681db 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 1f83c1aaa..cc4f3969f 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 de986d86b..000000000 --- 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 978416162..e54453cad 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 594c453dc..e19a9a4ca 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 c709d3f08..000000000 --- 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 bf106b973..7115cada7 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 abf1d65e2..9fcfe4f30 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 d1be463cb..000000000 --- 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 63aac629c..9e3a790ae 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 d65724d3d..7bbb0bf4d 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 8039df2f3..000000000 --- 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 793e68df5..cea0a5659 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 b425fcd94..0a4f0fe84 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 69003d726..000000000 --- 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 3368d5c89..7fae39585 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 8cab23721..cf9fbe9ba 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 5386eb062..000000000 --- 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 7a7d682bf..00ba1bd8e 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 c67cf4faa..2bc1b3081 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 aa7730eab..000000000 --- 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 338bac2bc..5407f63ff 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 1f2290ad2..880b9ede5 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 d6930162d..000000000 --- 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 b0bebf68f..69210322f 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 fd6922eb2..079b45c26 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 83ae1c520..000000000 --- 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 9de12f588..980a2e46f 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 d73c543e9..b9c4f9fd0 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 aadc20de8..000000000 --- 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 fe1d62cec..ac2bf498e 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 9da3723d1..2371590fb 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 7579b3457..4f342ff7d 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 92a18f8f1..000000000 --- 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 3fb37c396..5a9df0b01 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 383fca60d..5c59e7922 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 4d4f1fb56..000000000 --- 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 a517e5106..e7ac1583e 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 eecc4ec47..aab01fc32 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 77f9a1e68..000000000 --- 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 0afa64d45..88e9ab0bb 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 9071b7ee6..2ef000239 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 8ec292634..000000000 --- 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 d57822050..4aa69fdd3 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 94d46ef9e..d0e4094a4 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 ad0a5d999..000000000 --- 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 c445e0f5a..50c049af1 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 8e7700253..d64021a3a 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 27c337299..000000000 --- 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 c9cff9a52..261257742 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 d987884d6..54e5dfec9 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 f059f8cde..000000000 --- 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 93763ae02..775dccce9 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 ae2e5c7d0..3ebef3076 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 655f502f2..000000000 --- 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 9b233e031..d2086a88e 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 9e4bca99c..dd903d7af 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 66e52ca42..000000000 --- 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 3b7f376f6..48c35bc23 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 9396dc1e3..02746b3a5 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 2e85f1373..000000000 --- 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 9426ced7a..f6f80a807 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 9236e48b0..ad65ff986 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 5d3123e34..000000000 --- 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 620b95b7e..76390a822 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 fbbdd03f0..5086d395a 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 42c2a0452..000000000 --- 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 1f6db7df2..06edd8cc6 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 8186e545d..a7b9f4d15 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 7974abde5..000000000 --- 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 c538559ca..f3c721842 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 cd05786d9..08668d5e4 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 0964ef4f8..000000000 --- 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 70ce57705..3a348a458 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 3cd363cca..ef5b5834b 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 abdf80407..000000000 --- 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 993d0e5de..6d42d59d0 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 39c2bf1cf..1bf84e00d 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 002c39f0e..000000000 --- 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 c10bc78e1..f42c4519d 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 8499e925d..1ec94b5f1 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 f714ec10b..d9cf7b54b 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 2cff2c07d..000000000 --- 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 f4f96823a..646ea80a4 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 4f87a8342..4bc83ef2b 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 2eda2e3bb..906a4e9bf 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 e67118438..000000000 --- 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 75b317193..a902bbf7c 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 e9ac1a918..e70b51593 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 a728a763b..000000000 --- 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 efcff3e39..f458fc9d0 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 e27f6ad90..dd40934da 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 75f9dee0b..000000000 --- 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 0b3bf8a91..858c8c51a 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 e70cad17e..f1f8cc2d5 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 ef0e6a481..000000000 --- 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 f2c99fd6b..341849a82 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 9e006b385..ac9223adc 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 5147f9e9d..000000000 --- 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 e0c01788d..b61c435fa 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 f7c75982f..39328ac84 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 fa8a0d8da..000000000 --- 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 d70c304ef..642aaae2f 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 4399569d6..92c99064a 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 baa207d2d..000000000 --- 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 68080c2ec..d2cf41507 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 a63391cad..604c734d3 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 2d67bc9be..000000000 --- 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 9ece5604a..7e5e0854c 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 406136072..9a473f2ef 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 0c089b922..000000000 --- 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 6242f9b3c..20b5a4251 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 60c7ed902..fba9c5dfb 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 ab2539415..000000000 --- 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 36892d4a5..ebbf2d8d9 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 5fe91e960..f27df6a71 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 607be1209..000000000 --- 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 025bb1727..546bb7846 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 1dd6ca85b..1d1cd6fc9 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 64032afb9..000000000 --- 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 4f385cedb..2ffa82db6 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 cdf3f326b..3dbcfaf16 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 923bbbe1b..000000000 --- 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 dd684a251..4c26d60f9 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 db5a72ba8..ddec745b4 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 664f613f8..000000000 --- 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 03e6b2d41..9ddad7431 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 0bd4748a3..76495f177 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 0b1000bc1..000000000 --- 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 51011b939..1cefc2f4d 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 c1737068f..bc18203ef 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 211d52dd1..000000000 --- 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 16105c93e..1a1a72dd2 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 c11675659..50b8f5215 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 882ce3944..000000000 --- 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 8515103fd..ebb015976 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 552f727f7..875dd4e77 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 d2e93d0e0..000000000 --- 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 7c3003091..ff6294156 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 4ad7f2fd4..1a2b3e70a 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 62e6696db..000000000 --- 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 bb590e7f6..08a084a09 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 3c5abb448..ccbf99978 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 5de8f33d3..000000000 --- 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 1f1c7c989..86ebdee7a 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 8fe602b24..62fd58d93 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 e5b7ef940..000000000 --- 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 b46a46048..27ae639c8 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 df063d818..81e3e737a 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 d878df8f5..000000000 --- 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 1412c4bd9..b40d63150 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 28acb6761..a7b3e192e 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 b5f0c8b34..000000000 --- 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 dae2b2272..0298dfa27 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 a632955ad..46e2e7f4e 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 fc343a203..000000000 --- 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 44a0974b0..aaca3c116 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 8902a00d8..759fce421 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 940fe1099..571e9fede 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 466558426..000000000 --- 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 1a03d588c..58eb0342b 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 be6f9c95a..4c1aaae64 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 a7bad2f40..000000000 --- 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 76c89aac2..bd458d406 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 8581da9c3..318ed5322 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 e13ab459b..000000000 --- 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 cc5b553fc..13040300d 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 576333b38..ee0444193 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 94c4e8d3f..ab39fc879 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 000000000..c6e266efe --- /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) + } +}