defaults

package
v1.20.2 Latest Latest
Warning

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

Go to latest
Published: Oct 7, 2021 License: MIT Imports: 3 Imported by: 1

README

Defaults Processor

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.

  1. The field is nil on the incoming metric
  2. The field is not nil, but its value is an empty string.
  3. The field is not nil, but its value is a string of one or more empty spaces.

Telegraf minimum version: Telegraf 1.15.0

Configuration
## Set default fields on your metric(s) when they are nil or empty
[[processors.defaults]]

## This table determines what fields will be inserted in your metric(s)
  [processors.defaults.fields]
    field_1 = "bar"
    time_idle = 0
    is_error = true
Example

Ensure a status_code field with N/A is inserted in the metric when one is not set in the metric by default:

[[processors.defaults]]
  [processors.defaults.fields]
    status_code = "N/A"
- lb,http_method=GET cache_status=HIT,latency=230
+ lb,http_method=GET cache_status=HIT,latency=230,status_code="N/A"

Ensure an empty string gets replaced by a default:

- lb,http_method=GET cache_status=HIT,latency=230,status_code=""
+ lb,http_method=GET cache_status=HIT,latency=230,status_code="N/A"

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Defaults

type Defaults struct {
	DefaultFieldsSets map[string]interface{} `toml:"fields"`
}

Defaults is a processor for ensuring certain fields always exist on your Metrics with at least a default value.

func (*Defaults) Apply

func (def *Defaults) Apply(inputMetrics ...telegraf.Metric) []telegraf.Metric

Apply contains the main implementation of this processor. For each metric in 'inputMetrics', it goes over each default pair. If the field in the pair does not exist on the metric, the associated default is added. If the field was found, then, if its value is the empty string or one or more spaces, it is replaced by the associated default.

func (*Defaults) Description

func (def *Defaults) Description() string

Description is a brief description of this processor plugin's behaviour.

func (*Defaults) SampleConfig

func (def *Defaults) SampleConfig() string

SampleConfig represents a sample toml config for this plugin.

Jump to

Keyboard shortcuts

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