graphite

package
v0.0.0-...-fb5aed7 Latest Latest
Warning

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

Go to latest
Published: Jan 15, 2024 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package graphite contains the functionality for sending metrics to a Graphite server.

Index

Constants

View Source
const (
	// DefaultMaxBufferSize is the default maximum number of metrics to buffer
	// before sending them to the Graphite server.
	DefaultMaxBufferSize = 1000

	// DefaultMaxMetricsPerMessage is the default maximum number of metrics to
	// send to the Graphite server in a single request.
	DefaultMaxMetricsPerMessage = 1

	// DefaultMaxTries is the default maximum number of times to try sending
	// metrics to the Graphite server.
	DefaultMaxTries = 3
)

Variables

View Source
var (
	// ErrNoAddress is returned when no server address is specified for the
	// Graphite client.
	ErrNoAddress = errors.New(
		"graphite: no address specified for Graphite server",
	)
)

Functions

This section is empty.

Types

type Client

type Client interface {
	// SendMetric sends a metric to the Graphite server.
	SendMetric(ctx context.Context,
		metric MetricMetadata,
		value string,
		timestamp time.Time,
	) error

	// Submit submits the queued metrics to the Graphite server.
	Submit(ctx context.Context) error
}

Client is the interface defining a Graphite client.

func NewClient

func NewClient(ctx context.Context, opts ...ClientOption) (Client, error)

NewClient creates a new Graphite client.

type ClientOption

type ClientOption func(c *clientOptions)

ClientOption represents an option that can be set on the Graphite client.

func WithAddress

func WithAddress(addr url.URL) ClientOption

WithAddress sets the address of the Graphite server. This is used if [Conn] is not set.

func WithConnection

func WithConnection(conn net.Conn) ClientOption

WithConnection sets the connection to use when sending metrics to the Graphite server.

func WithMaxBufferSize

func WithMaxBufferSize(maxBufferSize int) ClientOption

WithMaxBufferSize sets the maximum number of metrics to buffer before sending them to the Graphite server.

func WithMaxMetricsPerMessage

func WithMaxMetricsPerMessage(maxMetricsPerMessage int) ClientOption

WithMaxMetricsPerMessage sets the maximum number of metrics to send to the Graphite server in a single request.

func WithMaxTries

func WithMaxTries(maxTries int) ClientOption

WithMaxTries sets the maximum number of times to retry sending metrics to the Graphite server.

type Metric

type Metric struct {
	MetricMetadata
	Value     string
	Timestamp time.Time
}

Metric represents a metric that has been queued for sending to the Graphite server.

func (Metric) String

func (m Metric) String() string

String returns the metric line for sending to Graphite.

type MetricMetadata

type MetricMetadata struct {
	Name []string
	Tags map[string]string
}

MetricMetadata represents a metric that can be sent to a Graphite server.

func (MetricMetadata) SubMetric

func (m MetricMetadata) SubMetric(name string, tags map[string]string) *MetricMetadata

SubMetric returns a new metric metadata with the given name appended to the current metric's name. This allows child metrics to be created from a parent metric.

Jump to

Keyboard shortcuts

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