config

package
v1.40.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 21, 2026 License: MIT Imports: 49 Imported by: 281

Documentation

Index

Constants

View Source
const EmptySourcePath string = ""

Variables

View Source
var (

	// OldEnvVarReplacement is a switch to allow going back to pre v1.27.0
	// environment variable replacement behavior
	OldEnvVarReplacement = false

	// NonStrictEnvVarHandling allows to disable strict and safe environment
	// variables handling. Strict handling cannot replace non-string settings
	// so this option must be used in those use-cases.
	NonStrictEnvVarHandling = false

	// PrintPluginConfigSource is a switch to enable printing of plugin sources
	PrintPluginConfigSource = false

	// Password specified via command-line
	Password Secret
)

Functions

func ApplyMigrations added in v1.27.0

func ApplyMigrations(data []byte) ([]byte, uint64, error)

func CheckLabelKeyValuePairs added in v1.37.1

func CheckLabelKeyValuePairs(k, v string) error

CheckLabelKeyValuePairs checks the key and value of a label.

func CheckSelectionKeyValuePairs added in v1.36.0

func CheckSelectionKeyValuePairs(k, v string) error

CheckSelectionKeyValuePairs checks the key and value of a selector.

func DisableSecretProtection added in v1.29.0

func DisableSecretProtection()

func EnableSecretProtection added in v1.29.0

func EnableSecretProtection()

func GetDefaultConfigPath added in v1.27.0

func GetDefaultConfigPath() ([]string, error)

GetDefaultConfigPath will try to find a default config file at these locations (in order):

  1. $TELEGRAF_CONFIG_PATH
  2. $HOME/.telegraf/telegraf.conf
  3. /etc/telegraf/telegraf.conf and /etc/telegraf/telegraf.d/*.conf

func GetSources added in v1.37.0

func GetSources() []string

GetSources returns the redacted list of configuration sources

func LoadConfigFile added in v1.24.0

func LoadConfigFile(config string) ([]byte, bool, error)

LoadConfigFile loads the content of a configuration file and returns it together with a flag denoting if the file is from a remote location such as a web server.

func LoadConfigFileWithRetries added in v1.31.0

func LoadConfigFileWithRetries(config string, urlRetryAttempts int) ([]byte, bool, error)

func PluginNameCounts added in v1.16.0

func PluginNameCounts(plugins []string) []string

PluginNameCounts returns a string of plugin names and their counts. PluginNameCounts returns a list of sorted plugin names and their count

func PrintOptionDeprecationNotice added in v1.31.0

func PrintOptionDeprecationNotice(plugin, option string, info telegraf.DeprecationInfo)

func PrintOptionValueDeprecationNotice added in v1.31.0

func PrintOptionValueDeprecationNotice(plugin, option string, value any, info telegraf.DeprecationInfo)

func ResetSecrets added in v1.38.4

func ResetSecrets()

func SetPluginLabelSelections added in v1.36.0

func SetPluginLabelSelections(selections []string) error

SetPluginLabelSelections initializes the plugin label selector with the given different selection groups. Within a group selectors are combined via logical AND. Different selector groups are combined via OR.

func WalkDirectory added in v1.25.0

func WalkDirectory(path string) ([]string, error)

WalkDirectory collects all toml files that need to be loaded

func WithSourcePath added in v1.34.0

func WithSourcePath(path string) cfgDataOption

Types

type AgentConfig

type AgentConfig struct {
	// Interval at which to gather information
	Interval Duration

	// RoundInterval rounds collection interval to 'interval'.
	//     ie, if Interval=10s then always collect on :00, :10, :20, etc.
	RoundInterval bool

	// Collected metrics are rounded to the precision specified. Precision is
	// specified as an interval with an integer + unit (e.g. 0s, 10ms, 2us, 4s).
	// Valid time units are "ns", "us" (or "µs"), "ms", "s".
	//
	// By default, or when set to "0s", precision will be set to the same
	// timestamp order as the collection interval, with the maximum being 1s:
	//   ie, when interval = "10s", precision will be "1s"
	//       when interval = "250ms", precision will be "1ms"
	//
	// Precision will NOT be used for service inputs. It is up to each individual
	// service input to set the timestamp at the appropriate precision.
	Precision Duration

	// CollectionJitter is used to jitter the collection by a random amount.
	// Each plugin will sleep for a random time within jitter before collecting.
	// This can be used to avoid many plugins querying things like sysfs at the
	// same time, which can have a measurable effect on the system.
	CollectionJitter Duration

	// CollectionOffset is used to shift the collection by the given amount.
	// This can be used to avoid many plugins querying constraint devices
	// at the same time by manually scheduling them in time.
	CollectionOffset Duration

	// FlushInterval is the Interval at which to flush data
	FlushInterval Duration

	// FlushJitter Jitters the flush interval by a random amount.
	// This is primarily to avoid large write spikes for users running a large
	// number of telegraf instances.
	// ie, a jitter of 5s and interval 10s means flushes will happen every 10-15s
	FlushJitter Duration

	// MetricBatchSize is the maximum number of metrics that is written to an
	// output plugin in one call.
	MetricBatchSize int

	// MetricBufferLimit is the max number of metrics that each output plugin
	// will cache. The buffer is cleared when a successful write occurs. When
	// full, the oldest metrics will be overwritten. This number should be a
	// multiple of MetricBatchSize. Due to current implementation, this could
	// not be less than 2 times MetricBatchSize.
	MetricBufferLimit int

	// Debug is the option for running in debug mode
	Debug bool `toml:"debug"`

	// Quiet is the option for running in quiet mode
	Quiet bool `toml:"quiet"`

	// Log target controls the destination for logs and can be one of "file",
	// "stderr" or, on Windows, "eventlog". When set to "file", the output file
	// is determined by the "logfile" setting
	LogTarget string `toml:"logtarget" deprecated:"1.32.0;1.40.0;use 'logformat' and 'logfile' instead"`

	// Log format controls the way messages are logged and can be one of "text",
	// "structured" or, on Windows, "eventlog".
	LogFormat string `toml:"logformat"`

	// Name of the file to be logged to or stderr if empty. Ignored for "eventlog" format.
	Logfile string `toml:"logfile"`

	// Message key for structured logs, to override the default of "msg".
	// Ignored if "logformat" is not "structured".
	StructuredLogMessageKey string `toml:"structured_log_message_key"`

	// The file will be rotated after the time interval specified.  When set
	// to 0 no time based rotation is performed.
	LogfileRotationInterval Duration `toml:"logfile_rotation_interval"`

	// The logfile will be rotated when it becomes larger than the specified
	// size.  When set to 0 no size based rotation is performed.
	LogfileRotationMaxSize Size `toml:"logfile_rotation_max_size"`

	// Maximum number of rotated archives to keep, any older logs are deleted.
	// If set to -1, no archives are removed.
	LogfileRotationMaxArchives int `toml:"logfile_rotation_max_archives"`

	// Pick a timezone to use when logging or type 'local' for local time.
	LogWithTimezone string `toml:"log_with_timezone"`

	Hostname     string
	OmitHostname bool

	// Method for translating SNMP objects. 'netsnmp' to call external programs,
	// 'gosmi' to use the built-in library.
	SnmpTranslator string `toml:"snmp_translator"`

	// Name of the file to load the state of plugins from and store the state to.
	// If uncommented and not empty, this file will be used to save the state of
	// stateful plugins on termination of Telegraf. If the file exists on start,
	// the state in the file will be restored for the plugins.
	Statefile string `toml:"statefile"`

	// Flag to always keep tags explicitly defined in the plugin itself and
	// ensure those tags always pass filtering.
	AlwaysIncludeLocalTags bool `toml:"always_include_local_tags"`

	// Flag to always keep tags explicitly defined in the global tags section
	// and ensure those tags always pass filtering.
	AlwaysIncludeGlobalTags bool `toml:"always_include_global_tags"`

	// Flag to skip running processors after aggregators
	// By default, processors are run a second time after aggregators. Changing
	// this setting to true will skip the second run of processors.
	SkipProcessorsAfterAggregators *bool `toml:"skip_processors_after_aggregators"`

	// Flag to skip running processors before aggregators
	// By default, processors are run a first time before aggregators. Changing
	// this setting to true will skip the first run of processors.
	SkipProcessorsBeforeAggregators bool `toml:"skip_processors_before_aggregators"`

	// Number of attempts to obtain a remote configuration via a URL during
	// startup. Set to -1 for unlimited attempts.
	ConfigURLRetryAttempts int `toml:"config_url_retry_attempts"`

	// BufferStrategy is the metric buffer type to use for a given output plugin.
	// Supported types currently are "memory" and "disk_write_through" (alias: "disk").
	BufferStrategy string `toml:"buffer_strategy"`

	// BufferDirectory is the directory to store buffer files for serialized
	// to disk metrics when using the "disk_write_through" buffer strategy.
	BufferDirectory string `toml:"buffer_directory"`

	// BufferDiskSync controls writes durability when "disk" buffer strategy
	// is used. No sync offers better write performance at the risk of losing
	// metrics buffered in the last `flush_interval` in the event of a power
	// cut.
	BufferDiskSync *bool `toml:"buffer_disk_sync"`
}

AgentConfig defines configuration that will be used by the Telegraf agent

type Config

type Config struct {
	UnusedFields map[string]bool

	Tags               map[string]string
	InputFilters       []string
	OutputFilters      []string
	SecretStoreFilters []string
	// TestMode keeps output parsing in place while avoiding resources only
	// needed when outputs are actually used.
	TestMode bool

	SecretStores map[string]telegraf.SecretStore

	Agent       *AgentConfig
	Inputs      []*models.RunningInput
	Outputs     []*models.RunningOutput
	Aggregators []*models.RunningAggregator
	// Processors have a slice wrapper type because they need to be sorted
	Processors    models.RunningProcessors
	AggProcessors models.RunningProcessors

	Deprecations map[string][]int64

	Persister *persister.Persister

	NumberSecrets uint64
	// contains filtered or unexported fields
}

Config specifies the URL/user/password for the database that telegraf will be logging to, as well as all the plugins that the user has specified

func NewConfig

func NewConfig() *Config

NewConfig creates a new struct to hold the Telegraf config. For historical reasons, It holds the actual instances of the running plugins once the configuration is parsed.

func (*Config) AggregatorNames

func (c *Config) AggregatorNames() []string

AggregatorNames returns a list of strings of the configured aggregators.

func (*Config) AggregatorNamesWithSources added in v1.34.0

func (c *Config) AggregatorNamesWithSources() string

AggregatorNamesWithSources returns a table representation of aggregator names and their sources.

func (*Config) CollectDeprecationInfos added in v1.21.0

func (c *Config) CollectDeprecationInfos(inFilter, outFilter, aggFilter, procFilter []string) map[string][]PluginDeprecationInfo

func (*Config) InputNames

func (c *Config) InputNames() []string

InputNames returns a list of strings of the configured inputs.

func (*Config) InputNamesWithSources added in v1.34.0

func (c *Config) InputNamesWithSources() string

InputNamesWithSources returns a table representation of input names and their sources.

func (*Config) LinkSecrets added in v1.25.0

func (c *Config) LinkSecrets() error

func (*Config) ListTags

func (c *Config) ListTags() string

ListTags returns a string of tags specified in the config, line-protocol style

func (*Config) LoadAll added in v1.25.0

func (c *Config) LoadAll(configFiles ...string) error

func (*Config) LoadConfig

func (c *Config) LoadConfig(path string) error

LoadConfig loads the given config files and applies it to c

func (*Config) LoadConfigData

func (c *Config) LoadConfigData(data []byte, path string) error

LoadConfigData loads TOML-formatted config data

func (*Config) OutputNames

func (c *Config) OutputNames() []string

OutputNames returns a list of strings of the configured outputs.

func (*Config) OutputNamesWithSources added in v1.34.0

func (c *Config) OutputNamesWithSources() string

OutputNamesWithSources returns a table representation of output names and their sources.

func (*Config) PrintDeprecationList added in v1.21.0

func (*Config) PrintDeprecationList(plugins []PluginDeprecationInfo)

func (*Config) ProcessorNames

func (c *Config) ProcessorNames() []string

ProcessorNames returns a list of strings of the configured processors.

func (*Config) ProcessorNamesWithSources added in v1.34.0

func (c *Config) ProcessorNamesWithSources() string

ProcessorNamesWithSources returns a table representation of processor names and their sources.

func (*Config) SecretstoreNames added in v1.25.0

func (c *Config) SecretstoreNames() []string

SecretstoreNames returns a list of strings of the configured secret stores.

func (*Config) SecretstoreNamesWithSources added in v1.34.0

func (c *Config) SecretstoreNamesWithSources() string

SecretstoreNamesWithSources returns a table representation of secret store names and their sources.

type DeprecationInfo added in v1.24.0

type DeprecationInfo struct {
	// Name of the plugin or plugin option
	Name string
	// contains filtered or unexported fields
}

DeprecationInfo contains all important information to describe a deprecated entity

type Duration

type Duration time.Duration

Duration is a time.Duration

func (*Duration) UnmarshalText added in v1.15.3

func (d *Duration) UnmarshalText(b []byte) error

UnmarshalText parses the duration from the Text config file

type OrderedPlugin added in v1.25.0

type OrderedPlugin struct {
	Line int
	// contains filtered or unexported fields
}

OrderedPlugin is used to keep the order in which they appear in a file

type OrderedPlugins added in v1.25.0

type OrderedPlugins []*OrderedPlugin

func (OrderedPlugins) Len added in v1.25.0

func (op OrderedPlugins) Len() int

func (OrderedPlugins) Less added in v1.25.0

func (op OrderedPlugins) Less(i, j int) bool

func (OrderedPlugins) Swap added in v1.25.0

func (op OrderedPlugins) Swap(i, j int)

type PluginDeprecationInfo added in v1.24.0

type PluginDeprecationInfo struct {
	DeprecationInfo

	// Options deprecated for this plugin
	Options []DeprecationInfo
}

PluginDeprecationInfo holds all information about a deprecated plugin or it's options

type Secret added in v1.25.0

type Secret struct {
	// contains filtered or unexported fields
}

Secret safely stores sensitive data such as a password or token

func NewSecret added in v1.25.0

func NewSecret(b []byte) Secret

NewSecret creates a new secret from the given bytes

func (*Secret) Destroy added in v1.25.0

func (s *Secret) Destroy()

Destroy the secret content

func (*Secret) Empty added in v1.25.1

func (s *Secret) Empty() bool

Empty return if the secret is completely empty

func (*Secret) EqualTo added in v1.26.0

func (s *Secret) EqualTo(ref []byte) (bool, error)

EqualTo performs a constant-time comparison of the secret to the given reference

func (*Secret) Get added in v1.25.0

func (s *Secret) Get() (SecretBuffer, error)

Get return the string representation of the secret

func (*Secret) GetUnlinked added in v1.25.0

func (s *Secret) GetUnlinked() []string

GetUnlinked return the parts of the secret that is not yet linked to a resolver

func (s *Secret) Link(resolvers map[string]telegraf.ResolveFunc) error

Link used the given resolver map to link the secret parts to their secret store resolvers.

func (*Secret) Set added in v1.26.1

func (s *Secret) Set(value []byte) error

Set overwrites the secret's value with a new one. Please note, the secret is not linked again, so only references to secret stores can be used, e.g. by adding more clear-text or reordering secrets.

func (*Secret) UnmarshalText added in v1.25.1

func (s *Secret) UnmarshalText(b []byte) error

UnmarshalText creates a secret from a toml value following the "string" rule.

type SecretBuffer added in v1.28.2

type SecretBuffer interface {
	// Size returns the length of the buffer content
	Size() int
	// Grow will grow the capacity of the underlying buffer to the given size
	Grow(capacity int)
	// Bytes returns the content of the buffer as bytes.
	// NOTE: The returned bytes shall NOT be accessed after destroying the
	// buffer using 'Destroy()' as the underlying the memory area might be
	// wiped and invalid.
	Bytes() []byte
	// TemporaryString returns the content of the buffer as a string.
	// NOTE: The returned String shall NOT be accessed after destroying the
	// buffer using 'Destroy()' as the underlying the memory area might be
	// wiped and invalid.
	TemporaryString() string
	// String returns a copy of the underlying buffer's content as string.
	// It is safe to use the returned value after destroying the buffer.
	String() string
	// Destroy will wipe the buffer's content and destroy the underlying
	// buffer. Do not access the buffer after destroying it.
	Destroy()
}

SecretBuffer allows to access the content of the secret

type Size

type Size int64

Size is an int64

func (*Size) UnmarshalText added in v1.15.3

func (s *Size) UnmarshalText(b []byte) error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL