form_urlencoded

package
v1.17.8 Latest Latest
Warning

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

Go to latest
Published: Feb 16, 2021 License: MIT Imports: 7 Imported by: 0

README

Form Urlencoded

The form-urlencoded data format parses application/x-www-form-urlencoded data, such as commonly used in the query string.

A common use case is to pair it with http_listener_v2 input plugin to parse request body or query params.

Configuration
[[inputs.http_listener_v2]]
  ## Address and port to host HTTP listener on
  service_address = ":8080"

  ## Part of the request to consume.  Available options are "body" and
  ## "query".
  data_source = "body"

  ## Data format to consume.
  ## 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_INPUT.md
  data_format = "form_urlencoded"

  ## Array of key names which should be collected as tags.
  ## By default, keys with string value are ignored if not marked as tags.
  form_urlencoded_tag_keys = ["tag1"]
Examples
Basic parsing

Config:

[[inputs.http_listener_v2]]
  name_override = "mymetric"
  service_address = ":8080"
  data_source = "query"
  data_format = "form_urlencoded"
  form_urlencoded_tag_keys = ["tag1"]

Request:

curl -i -XGET 'http://localhost:8080/telegraf?tag1=foo&field1=0.42&field2=42'

Output:

mymetric,tag1=foo field1=0.42,field2=42

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNoMetric is returned when no metric is found in input line
	ErrNoMetric = fmt.Errorf("no metric in line")
)

Functions

This section is empty.

Types

type Parser

type Parser struct {
	MetricName  string
	DefaultTags map[string]string
	TagKeys     []string
	AllowedKeys []string
}

Parser decodes "application/x-www-form-urlencoded" data into metrics

func (Parser) Parse

func (p Parser) Parse(buf []byte) ([]telegraf.Metric, error)

Parse converts a slice of bytes in "application/x-www-form-urlencoded" format into metrics

func (Parser) ParseLine

func (p Parser) ParseLine(line string) (telegraf.Metric, error)

ParseLine delegates a single line of text to the Parse function

func (*Parser) SetDefaultTags

func (p *Parser) SetDefaultTags(tags map[string]string)

SetDefaultTags sets the default tags for every metric

Jump to

Keyboard shortcuts

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