csv

package
v1.32.0 Latest Latest
Warning

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

Go to latest
Published: Sep 9, 2024 License: MIT Imports: 12 Imported by: 0

README

CSV Serializer

The csv output data format converts metrics into CSV lines.

Configuration

[[outputs.file]]
  ## Files to write to, "stdout" is a specially handled file.
  files = ["stdout", "/tmp/metrics.out"]

  ## Data format to output.
  ## Each data format has its own unique set of configuration options, read
  ## more about them here:
  ## https://github.com/influxdata/telegraf/blob/master/docs/DATA_FORMATS_OUTPUT.md
  data_format = "csv"

  ## The default timestamp format is Unix epoch time.
  # Other timestamp layout can be configured using the Go language time
  # layout specification from https://golang.org/pkg/time/#Time.Format
  # e.g.: csv_timestamp_format = "2006-01-02T15:04:05Z07:00"
  # csv_timestamp_format = "unix"

  ## The default separator for the CSV format.
  # csv_separator = ","

  ## Output the CSV header in the first line.
  ## Enable the header when outputting metrics to a new file.
  ## Disable when appending to a file or when using a stateless
  ## output to prevent headers appearing between data lines.
  # csv_header = false

  ## Prefix tag and field columns with "tag_" and "field_" respectively.
  ## This can be helpful if you need to know the "type" of a column.
  # csv_column_prefix = false

  ## Use the specified order for the columns.
  ## This can be helpful if you need a specific output order. To specify tags,
  ## use a `tag.` prefix, for fields use a `field.` prefix and use `name` and
  ## `timestamp` to reference the measurement name and timestamp respectively.
  ## NOTE: The output will only contain the specified tags, fields, etc. All
  ##       other data will be dropped. In case a tag or field does not exist,
  ##       the column will be empty.
  ##  ex. csv_columns = ["timestamp", "tag.host", "field.value"]
  ##
  ## By default all metric data will be written in the order:
  ##   timestamp, name, tags..., fields...
  ## with tags and fields being ordered alphabetically.
  # csv_columns = []

Examples

Standard form:

1458229140,docker,raynor,30,4,...,59,660

When an output plugin needs to emit multiple metrics at one time, it may use the batch format. The use of batch format is determined by the plugin, reference the documentation for the specific plugin. With csv_header = true you get

timestamp,measurement,host,field_1,field_2,...,field_N,n_images
1458229140,docker,raynor,30,4,...,59,660
1458229143,docker,raynor,28,5,...,60,665

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Serializer

type Serializer struct {
	TimestampFormat string   `toml:"csv_timestamp_format"`
	Separator       string   `toml:"csv_separator"`
	Header          bool     `toml:"csv_header"`
	Prefix          bool     `toml:"csv_column_prefix"`
	Columns         []string `toml:"csv_columns"`
	// contains filtered or unexported fields
}

func (*Serializer) Init added in v1.27.0

func (s *Serializer) Init() error

func (*Serializer) InitFromConfig added in v1.27.0

func (s *Serializer) InitFromConfig(cfg *serializers.Config) error

InitFromConfig is a compatibility function to construct the parser the old way

func (*Serializer) Serialize

func (s *Serializer) Serialize(metric telegraf.Metric) ([]byte, error)

func (*Serializer) SerializeBatch

func (s *Serializer) SerializeBatch(metrics []telegraf.Metric) ([]byte, error)

Jump to

Keyboard shortcuts

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