template

package
v0.0.21 Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2021 License: MIT Imports: 6 Imported by: 0

README

Template Processor

The template processor applies a Go template to metrics to generate a new tag. The primary use case of this plugin is to create a tag that can be used for dynamic routing to multiple output plugins or using an output specific routing option.

The template has access to each metric's measurement name, tags, fields, and timestamp using the interface in /template_metric.go.

Read the full Go Template Documentation.

Configuration
[[processors.template]]
  ## Tag to set with the output of the template.
  tag = "topic"

  ## Go template used to create the tag value.  In order to ease TOML
  ## escaping requirements, you may wish to use single quotes around the
  ## template string.
  template = '{{ .Tag "hostname" }}.{{ .Tag "level" }}'
Example

Combine multiple tags to create a single tag:

[[processors.template]]
  tag = "topic"
  template = '{{ .Tag "hostname" }}.{{ .Tag "level" }}'
- cpu,level=debug,hostname=localhost time_idle=42
+ cpu,level=debug,hostname=localhost,topic=localhost.debug time_idle=42

Add measurement name as a tag:

[[processors.template]]
  tag = "measurement"
  template = '{{ .Name }}'
- cpu,hostname=localhost time_idle=42
+ cpu,hostname=localhost,measurement=cpu time_idle=42

Add the year as a tag, similar to the date processor:

[[processors.template]]
  tag = "year"
  template = '{{.Time.UTC.Year}}'

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Metric added in v0.0.12

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

func (*Metric) Field added in v0.0.12

func (m *Metric) Field(key string) interface{}

func (*Metric) Name added in v0.0.12

func (m *Metric) Name() string

func (*Metric) Tag added in v0.0.12

func (m *Metric) Tag(key string) string

func (*Metric) Time added in v0.0.12

func (m *Metric) Time() time.Time

type Processor added in v0.0.12

type Processor struct {
	Tag      string     `toml:"tag"`
	Template string     `toml:"template"`
	Log      cua.Logger `toml:"-"`
	// contains filtered or unexported fields
}

func (*Processor) Apply added in v0.0.12

func (r *Processor) Apply(in ...cua.Metric) []cua.Metric

func (*Processor) Description added in v0.0.12

func (r *Processor) Description() string

func (*Processor) Init added in v0.0.12

func (r *Processor) Init() error

func (*Processor) SampleConfig added in v0.0.12

func (r *Processor) SampleConfig() string

Jump to

Keyboard shortcuts

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