protocol

package
v0.116.0 Latest Latest
Warning

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

Go to latest
Published: Dec 17, 2024 License: Apache-2.0 Imports: 11 Imported by: 1

Documentation

Index

Constants

View Source
const (
	DefaultMetricType    = TargetMetricType("")
	GaugeMetricType      = TargetMetricType("gauge")
	CumulativeMetricType = TargetMetricType("cumulative")
)

Values for enum TargetMetricType.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// Type of the parser to be used with the arriving data.
	Type string `mapstructure:"type"`

	// Config placeholder for the configuration object of the selected parser.
	Config ParserConfig `mapstructure:"config"`
}

Config is the general configuration for the parser to be used.

func (*Config) Unmarshal added in v0.92.0

func (cfg *Config) Unmarshal(cp *confmap.Conf) error

Unmarshal is used to load the parser configuration according to the specified parser type.

type ParsedPath

type ParsedPath struct {
	// MetricName extracted/generated by the parser.
	MetricName string
	// Attributes extracted/generated by the parser.
	Attributes pcommon.Map
	// MetricType instructs the helper to generate the metric as the specified
	// TargetMetricType.
	MetricType TargetMetricType
}

ParsedPath holds the result of parsing the <metric_path> with the ParsePath method on the PathParser interface.

type Parser

type Parser interface {
	// Parse receives the string with plaintext data, aka line, in the Carbon
	// format and transforms it to the collector metric format.
	//
	// The expected line is a text line in the following format:
	// 	"<metric_path> <metric_value> <metric_timestamp>"
	//
	// The <metric_path> is where there are variations that require selection
	// of specialized parsers to handle them, but include the metric name and
	// labels/dimensions for the metric.
	//
	// The <metric_value> is the textual representation of the metric value.
	//
	// The <metric_timestamp> is the Unix time text of when the measurement was
	// made.
	Parse(line string) (pmetric.Metric, error)
}

Parser abstracts the type of parsing being done by the receiver.

func NewParser

func NewParser(pathParser PathParser) (Parser, error)

NewParser creates a new Parser instance that receives plaintext Carbon data.

type ParserConfig

type ParserConfig interface {
	// BuildParser builds the respective parser of the configuration instance.
	BuildParser() (Parser, error)
}

ParserConfig is the configuration of a given parser.

type PathParser

type PathParser interface {
	// ParsePath parses the <metric_path> of a Carbon line (see Parse function
	// for description of the full line). The results of parsing the path are
	// stored on the parsedPath struct. Implementers of the interface can assume
	// that the PathParserHelper will never pass nil when calling this method.
	ParsePath(path string, parsedPath *ParsedPath) error
}

PathParser implements the code needed to handle only the <metric_path> part of a Carbon metric line:

<metric_path> <metric_value> <metric_timestamp>

See https://graphite.readthedocs.io/en/latest/feeding-carbon.html#the-plaintext-protocol, for more information.

The type PathParserHelper implements the common code for parsers that differ only by the way that they handle the <metric_path>.

type PathParserHelper

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

PathParserHelper implements the common code to parse a Carbon line taking a PathParser to implement a full parser.

func (*PathParserHelper) Parse

func (pph *PathParserHelper) Parse(line string) (pmetric.Metric, error)

Parse receives the string with plaintext data, aka line, in the Carbon format and transforms it to the collector metric format. See https://graphite.readthedocs.io/en/latest/feeding-carbon.html#the-plaintext-protocol.

The expected line is a text line in the following format:

"<metric_path> <metric_value> <metric_timestamp>"

The <metric_path> is where there are variations that require selection of specialized parsers to handle them, but include the metric name and labels/dimensions for the metric.

The <metric_value> is the textual representation of the metric value.

The <metric_timestamp> is the Unix time text of when the measurement was made.

type PlaintextConfig

type PlaintextConfig struct{}

PlaintextConfig holds the configuration for the plaintext parser.

func (*PlaintextConfig) BuildParser

func (p *PlaintextConfig) BuildParser() (Parser, error)

BuildParser creates a new Parser instance that receives plaintext Carbon data.

type PlaintextPathParser

type PlaintextPathParser struct{}

PlaintextPathParser converts a line of https://graphite.readthedocs.io/en/latest/feeding-carbon.html#the-plaintext-protocol, treating tags per spec at https://graphite.readthedocs.io/en/latest/tags.html#carbon.

func (*PlaintextPathParser) ParsePath

func (p *PlaintextPathParser) ParsePath(path string, parsedPath *ParsedPath) error

ParsePath converts the <metric_path> of a Carbon line (see Parse function for description of the full line). The metric path is expected to be in the following format:

<metric_name>[;tag0;...;tagN]

<metric_name> is the name of the metric and terminates either at the first ';' or at the end of the path.

tag is of the form "key=val", where key can contain any char except ";!^=" and val can contain any char except ";~".

type RegexParserConfig

type RegexParserConfig struct {
	// Rules contains the regular expression rules to be used by the parser.
	// The first rule that matches and applies the transformations configured in
	// the respective RegexRule struct. If no rules match the metric is then
	// processed by the "plaintext" parser.
	Rules []*RegexRule `mapstructure:"rules"`

	// MetricNameSeparator is used when joining the name prefix of each individual
	// rule and the respective named captures that start with the prefix
	// "name_" (see RegexRule for more information).
	MetricNameSeparator string `mapstructure:"name_separator"`
}

RegexParserConfig has the configuration for a parser that can breakdown a Carbon "metric path" and transform it in corresponding metric labels according to a series of regular expressions rules (see below for details).

This is typically used to extract labels from a "naming hierarchy", see https://graphite.readthedocs.io/en/latest/feeding-carbon.html#step-1-plan-a-naming-hierarchy

Examples:

1. Rule:

  • regexp: "(?P<key_svc>[^.]+)\.(?P<key_host>[^.]+)\.cpu\.seconds" name_prefix: cpu_seconds labels: k: v Metric path: "service_name.host00.cpu.seconds" Resulting metric: name: cpu_seconds label keys: {"svc", "host", "k"} label values: {"service_name", "host00", "k"}

2. Rule:

  • regexp: "^(?P<key_svc>[^.]+)\.(?P<key_host>[^.]+)\.(?P<name_0>[^.]+).(?P<name_1>[^.]+)$" Metric path: "svc_02.host02.avg.duration" Resulting metric: name: avgduration label keys: {"svc", "host"} label values: {"svc_02", "host02"}

func (*RegexParserConfig) BuildParser

func (rpc *RegexParserConfig) BuildParser() (Parser, error)

BuildParser builds the respective parser of the configuration instance.

type RegexRule

type RegexRule struct {
	// Regular expression from which named matches are used to extract label
	// keys and values from Carbon metric paths.
	Regexp string `mapstructure:"regexp"`

	// NamePrefix is the prefix added to the metric name after extracting the
	// parts that will form labels and final metric name.
	NamePrefix string `mapstructure:"name_prefix"`

	// Labels are key-value pairs added as labels to the metrics that match this
	// rule.
	Labels map[string]string `mapstructure:"labels"`

	// MetricType selects the type of metric to be generated, supported values are
	// "gauge" (the default) and "cumulative".
	MetricType string `mapstructure:"type"`
	// contains filtered or unexported fields
}

RegexRule describes how parts of the name of metric are going to be mapped to metric labels. The rule is only applied if the name matches the given regular expression.

type TargetMetricType

type TargetMetricType string

Jump to

Keyboard shortcuts

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