package graphite

import "github.com/influxdata/influxdb/services/graphite"

Package graphite provides a service for InfluxDB to ingest data via the graphite protocol.

Index

Constants

const (
	// DefaultBindAddress is the default binding interface if none is specified.
	DefaultBindAddress = ":2003"

	// DefaultDatabase is the default database if none is specified.
	DefaultDatabase = "graphite"

	// DefaultProtocol is the default IP protocol used by the Graphite input.
	DefaultProtocol = "tcp"

	// DefaultConsistencyLevel is the default write consistency for the Graphite input.
	DefaultConsistencyLevel = "one"

	// DefaultSeparator is the default join character to use when joining multiple
	// measurement parts in a template.
	DefaultSeparator = "."

	// DefaultBatchSize is the default write batch size.
	DefaultBatchSize = 5000

	// DefaultBatchPending is the default number of pending write batches.
	DefaultBatchPending = 10

	// DefaultBatchTimeout is the default Graphite batch timeout.
	DefaultBatchTimeout = time.Second

	// DefaultUDPReadBuffer is the default buffer size for the UDP listener.
	// Sets the size of the operating system's receive buffer associated with
	// the UDP traffic. Keep in mind that the OS must be able
	// to handle the number set here or the UDP listener will error and exit.
	//
	// DefaultReadBuffer = 0 means to use the OS default, which is usually too
	// small for high UDP performance.
	//
	// Increasing OS buffer limits:
	//     Linux:      sudo sysctl -w net.core.rmem_max=<read-buffer>
	//     BSD/Darwin: sudo sysctl -w kern.ipc.maxsockbuf=<read-buffer>
	DefaultUDPReadBuffer = 0
)

Variables

var (
	// The minimum graphite timestamp allowed.
	MinDate = time.Date(1901, 12, 13, 0, 0, 0, 0, time.UTC)

	// The maximum graphite timestamp allowed.
	MaxDate = time.Date(2038, 1, 19, 0, 0, 0, 0, time.UTC)
)

Minimum and maximum supported dates for timestamps.

Types

type Config

type Config struct {
	Enabled          bool          `toml:"enabled"`
	BindAddress      string        `toml:"bind-address"`
	Database         string        `toml:"database"`
	RetentionPolicy  string        `toml:"retention-policy"`
	Protocol         string        `toml:"protocol"`
	BatchSize        int           `toml:"batch-size"`
	BatchPending     int           `toml:"batch-pending"`
	BatchTimeout     toml.Duration `toml:"batch-timeout"`
	ConsistencyLevel string        `toml:"consistency-level"`
	Templates        []string      `toml:"templates"`
	Tags             []string      `toml:"tags"`
	Separator        string        `toml:"separator"`
	UDPReadBuffer    int           `toml:"udp-read-buffer"`
}

Config represents the configuration for Graphite endpoints.

func NewConfig

func NewConfig() Config

NewConfig returns a new instance of Config with defaults.

func (*Config) DefaultTags

func (c *Config) DefaultTags() models.Tags

DefaultTags returns the config's tags.

func (*Config) Validate

func (c *Config) Validate() error

Validate validates the config's templates and tags.

func (*Config) WithDefaults

func (c *Config) WithDefaults() *Config

WithDefaults takes the given config and returns a new config with any required default values set.

type Configs

type Configs []Config

Configs wraps a slice of Config to aggregate diagnostics.

func (Configs) Diagnostics

func (c Configs) Diagnostics() (*diagnostics.Diagnostics, error)

Diagnostics returns one set of diagnostics for all of the Configs.

func (Configs) Enabled

func (c Configs) Enabled() bool

Enabled returns true if any underlying Config is Enabled.

type Options

type Options struct {
	Separator   string
	Templates   []string
	DefaultTags models.Tags
}

Options are configurable values that can be provided to a Parser.

type Parser

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

Parser encapsulates a Graphite Parser.

func NewParser

func NewParser(templates []string, defaultTags models.Tags) (*Parser, error)

NewParser returns a GraphiteParser instance.

func NewParserWithOptions

func NewParserWithOptions(options Options) (*Parser, error)

NewParserWithOptions returns a graphite parser using the given options.

func (*Parser) ApplyTemplate

func (p *Parser) ApplyTemplate(line string) (string, map[string]string, string, error)

ApplyTemplate extracts the template fields from the given line and returns the measurement name and tags.

func (*Parser) Parse

func (p *Parser) Parse(line string) (models.Point, error)

Parse performs Graphite parsing of a single line.

type Service

type Service struct {
	Monitor interface {
		RegisterDiagnosticsClient(name string, client diagnostics.Client)
		DeregisterDiagnosticsClient(name string)
	}
	PointsWriter interface {
		WritePointsPrivileged(ctx tsdb.WriteContext, database, retentionPolicy string, consistencyLevel models.ConsistencyLevel, points []models.Point) error
	}
	MetaClient interface {
		CreateDatabaseWithRetentionPolicy(name string, spec *meta.RetentionPolicySpec) (*meta.DatabaseInfo, error)
		CreateRetentionPolicy(database string, spec *meta.RetentionPolicySpec, makeDefault bool) (*meta.RetentionPolicyInfo, error)
		Database(name string) *meta.DatabaseInfo
		RetentionPolicy(database, name string) (*meta.RetentionPolicyInfo, error)
	}
	// contains filtered or unexported fields
}

Service represents a Graphite service.

func NewService

func NewService(c Config) (*Service, error)

NewService returns an instance of the Graphite service.

func (*Service) Addr

func (s *Service) Addr() net.Addr

Addr returns the address the Service binds to.

func (*Service) Close

func (s *Service) Close() error

Close stops all data processing on the Graphite input.

func (*Service) Closed

func (s *Service) Closed() bool

Closed returns true if the service is currently closed.

func (*Service) Diagnostics

func (s *Service) Diagnostics() (*diagnostics.Diagnostics, error)

Diagnostics returns diagnostics of the graphite service.

func (*Service) Open

func (s *Service) Open() error

Open starts the Graphite input processing data.

func (*Service) Statistics

func (s *Service) Statistics(tags map[string]string) []models.Statistic

Statistics returns statistics for periodic monitoring.

func (*Service) WithLogger

func (s *Service) WithLogger(log *zap.Logger)

WithLogger sets the logger on the service.

type Statistics

type Statistics struct {
	PointsReceived      int64
	BytesReceived       int64
	PointsParseFail     int64
	PointsNaNFail       int64
	BatchesTransmitted  int64
	PointsTransmitted   int64
	BatchesTransmitFail int64
	ActiveConnections   int64
	HandledConnections  int64
}

Statistics maintains statistics for the graphite service.

type Template

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

Template represents a pattern and tags to map a graphite metric string to a influxdb Point.

func NewTemplate

func NewTemplate(pattern string, defaultTags models.Tags, separator string) (*Template, error)

NewTemplate returns a new template ensuring it has a measurement specified.

func (*Template) Apply

func (t *Template) Apply(line string) (string, map[string]string, string, error)

Apply extracts the template fields from the given line and returns the measurement name and tags.

type UnsupportedValueError

type UnsupportedValueError struct {
	Field string
	Value float64
}

An UnsupportedValueError is returned when a parsed value is not supported.

func (*UnsupportedValueError) Error

func (err *UnsupportedValueError) Error() string

Source Files

config.go errors.go parser.go service.go

Version
v1.12.0 (latest)
Published
Apr 8, 2025
Platform
linux/amd64
Imports
17 packages
Last checked
2 days ago

Tools for package owners.