From 15fd1133c7fca9ac8d3074342cfa4aaf5c4ebfc9 Mon Sep 17 00:00:00 2001 From: Sven Rebhan <36194019+srebhan@users.noreply.github.com> Date: Tue, 24 May 2022 17:55:36 +0200 Subject: [PATCH] fix: Convert slab plugin to new sample.conf. (#11181) --- plugins/inputs/slab/README.md | 2 +- plugins/inputs/slab/sample.conf | 4 ++++ plugins/inputs/slab/slab.go | 10 ++++++++++ plugins/inputs/slab/slab_sample_config.go | 11 ----------- 4 files changed, 15 insertions(+), 12 deletions(-) create mode 100644 plugins/inputs/slab/sample.conf delete mode 100644 plugins/inputs/slab/slab_sample_config.go diff --git a/plugins/inputs/slab/README.md b/plugins/inputs/slab/README.md index 18512fbf42b86..85859ee12c0b4 100644 --- a/plugins/inputs/slab/README.md +++ b/plugins/inputs/slab/README.md @@ -13,7 +13,7 @@ If the HOST_PROC environment variable is set, Telegraf will use its value instea ## Configuration -```toml +```toml @sample.conf # Get slab statistics from procfs [[inputs.slab]] # no configuration - please see the plugin's README for steps to configure diff --git a/plugins/inputs/slab/sample.conf b/plugins/inputs/slab/sample.conf new file mode 100644 index 0000000000000..d606f2dcd96bc --- /dev/null +++ b/plugins/inputs/slab/sample.conf @@ -0,0 +1,4 @@ +# Get slab statistics from procfs +[[inputs.slab]] + # no configuration - please see the plugin's README for steps to configure + # sudo properly diff --git a/plugins/inputs/slab/slab.go b/plugins/inputs/slab/slab.go index 2cf91c5a72086..d14b9809115c1 100644 --- a/plugins/inputs/slab/slab.go +++ b/plugins/inputs/slab/slab.go @@ -1,3 +1,4 @@ +//go:generate ../../../tools/readme_config_includer/generator //go:build linux // +build linux @@ -6,6 +7,7 @@ package slab import ( "bufio" "bytes" + _ "embed" "errors" "fmt" "os" @@ -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 + type SlabStats struct { Log telegraf.Logger `toml:"-"` @@ -27,6 +33,10 @@ type SlabStats struct { useSudo bool } +func (*SlabStats) SampleConfig() string { + return sampleConfig +} + func (ss *SlabStats) Init() error { return nil } diff --git a/plugins/inputs/slab/slab_sample_config.go b/plugins/inputs/slab/slab_sample_config.go deleted file mode 100644 index eb4da02542bf4..0000000000000 --- a/plugins/inputs/slab/slab_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 slab - -func (ss *SlabStats) SampleConfig() string { - return `{{ .SampleConfig }}` -}