metrics

package module
Version: v0.1.22 Latest Latest
Warning

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

Go to latest
Published: Apr 13, 2021 License: CC0-1.0, CC0-1.0 Imports: 14 Imported by: 20

Documentation

Index

Constants

View Source
const Discard = discard(0)

Discard discards all metrics.

Variables

This section is empty.

Functions

func DeleteGlobalTag

func DeleteGlobalTag(key string)

DeleteGlobalTag removes the tag with given key from the list of global tags.

func IsFieldValueValid

func IsFieldValueValid(value interface{}) (bool, error)

IsFieldValueValid validates the given field value, returning true if and only if value validates. A valid field value is one of the following types:

* time.Time
* time.Duration
* int, int8, int16, int32, int64
* uint, uint8, uint16, uint32, uint64
* float64
* bool
* string

Any other type is considered invalid. In addition:

* if the value is a string, it must have length < 32768;
* if the value is a float64, it must not be NaN.

If validation fails, an error will be returned describing the problem.

func IsKeyValid

func IsKeyValid(key string) (bool, error)

IsKeyValid validates the given key, returning true if and only if the key validates. A valid key must satisfy:

* non-empty
* length < 256

with characters consisting only of the ASCII characters:

* a-z, A-Z, and 0-9
* '.', '-', and '_'.

Any other character is considered invalid. In order to maintain compatibility with InfluxDB, the key "time" is prohibited. If validation fails, an error will be returned describing the problem.

func IsNameValid

func IsNameValid(name string) (bool, error)

IsNameValid validates the given name, returning true if and only if the name validates. A valid name must satisfy:

* non-empty
* length < 256

with characters consisting only of the ASCII characters:

* a-z, A-Z, and 0-9
* '.', '-', and '_'.

Any other character is considered invalid. In order to maintain compatibility with InfluxDB, the name "time" is prohibited. If validation fails, an error will be returned describing the problem.

func IsTagValueValid

func IsTagValueValid(value string) (bool, error)

IsTagValueValid validates the given tag value, returning true if and only if the value validates. A valid tag value must satisfy:

* length < 256

If validation fails, an error will be returned describing the problem.

func SetGlobalTag

func SetGlobalTag(key string, value string) error

SetGlobalTag adds the tag with given key and value to the list of global tags. Any existing global tag with the same key will have its value replaced. Global tags are automatically added to the tags for any point created with NewPoint or NewPointWithTimestamp. If a tag is provided to NewPoint or NewPointWithTimestamp with the same key as a global tag, then the point will use the provided value rather than the global value.

func SetMetrics

func SetMetrics(m Interface)

SetMetrics changes the global metrics endpoint to m.

func SubmitPoints

func SubmitPoints(ctx context.Context, m Interface, itr PointIterator) error

SubmitPoints will submit the points in the given iterator to m. If m satisfies the interface

type SubmitPointser interface {
	SubmitPoints(context.Context, PointIterator) error
}

then m's SubmitPoints method will be used. Otherwise, if m satisfies the interface

type SubmitSlicer interface {
	SubmitSlice(context.Context, []*Point) error
}

then m's SubmitSlice method will be used.

func SubmitSlice

func SubmitSlice(ctx context.Context, m Interface, pts []*Point) error

SubmitSlice will submit the given slice of points to m. If m satisfies the interface

type SubmitSlicer interface {
	SubmitSlice(context.Context, []*Point) error
}

then m's SubmitSlice method will be used. Otherwise, if m satisfies the interface

type SubmitPointser interface {
	SubmitPoints(context.Context, PointIterator) error
}

then m's SubmitPoints method will be used.

Types

type BasicMetricsable

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

BasicMetricsable provides an embeddable implementation of a Metricsable.

func (*BasicMetricsable) Metrics

func (b *BasicMetricsable) Metrics() Interface

Metrics returns the metrics endpoint.

func (*BasicMetricsable) SetMetrics

func (b *BasicMetricsable) SetMetrics(m Interface)

SetMetrics sets a metrics endpoint.

type Fields

type Fields map[string]interface{}

Fields is a map of field names and values. The values must take one of the following types:

time.Time
time.Duration
int, int8, int16, int32, int64
uint, uint8, uint16, uint32, uint64
float64
bool
string

func (Fields) Copy

func (f Fields) Copy() Fields

Copy returns a copy of the fields.

func (*Fields) GobDecode

func (f *Fields) GobDecode(b []byte) error

GobDecode overwrites the receiver, which must be a pointer, with the value represented by the byte slice, which was written by GobEncode.

func (Fields) GobEncode

func (f Fields) GobEncode() ([]byte, error)

GobEncode returns a byte slice representing the encoding of the fields.

func (Fields) IsValid

func (f Fields) IsValid() (bool, error)

IsValid returns true if and only if the fields are valid. If false, an error will be returned describing the problem. The fields are considered valid if and only if:

* the keys satisfy IsKeyValid;
* the values satisfy IsFieldValueValid.

func (Fields) Keys

func (f Fields) Keys() []string

Keys returns a slice of keys of the fields. The keys are returned sorted using sort.Strings.

func (Fields) String

func (f Fields) String() string

String returns a string representation of the fields.

type Interface

type Interface interface {
	Submit(ctx context.Context, p *Point) error // Submit submits the given point.
}

Interface is a metrics endpoint that stores metric points.

func Metrics

func Metrics() Interface

Metrics returns the current global metrics endpoint.

func TagWith

func TagWith(m Interface, tags Tags) Interface

TagWith wraps the given Interface so that all metrics will have the given tags included. Any duplicate tag keys on Interface with will be replaced with the new tag values. If the given tags fail to validate, this will panic.

type Logger

type Logger struct {
	Log log.Interface // The destination log
}

Logger will log all metrics to a log.Interface.

func (*Logger) Submit

func (l *Logger) Submit(_ context.Context, p *Point) error

Submit logs the given point.

type Metricsable

type Metricsable interface {
	SetMetricser
	Metricser
}

Metricsable is the interface satisfied by the SetMetrics and Metrics methods. It indicates an object that supports metrics reporting.

type Metricser

type Metricser interface {
	Metrics() Interface // Metrics returns the metrics endpoint.
}

Metricser is the interface satisfied by the Metrics method.

type Point

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

Point represents a point for a metric. That is, a unique tuple of name, fields, tags, and timestamp.

func NewPoint

func NewPoint(name string, fields Fields, tags Tags) (*Point, error)

NewPoint returns a new point with the given data. Any global tags will also be included in the tags for this point. If a tag is provided with the same key as a global tag, then the point will use the provided value rather than the global value. The timestamp will be set to the current time. The data is considered valid if and only if:

* the name satisfies IsNameValid;
* the fields satisfy fields.IsValid;
* the tags satisfy tags.IsValid.

If validation fails, an error will be returned describing the problem.

func NewPointWithTimestamp

func NewPointWithTimestamp(name string, fields Fields, tags Tags, timestamp time.Time) (*Point, error)

NewPointWithTimestamp returns a new point with the given data. Any global tags will also be included in the tags for this point. If a tag is provided with the same key as a global tag, then the point will use the provided value rather than the global value. The data is considered valid if and only if:

* the name satisfies IsNameValid;
* the fields satisfy fields.IsValid;
* the tags satisfy tags.IsValid;
* the timestamp is non-zero.

If validation fails, an error will be returned describing the problem.

func RawPoint

func RawPoint(name string, fields Fields, tags Tags, timestamp time.Time) (*Point, error)

RawPoint returns a new point with the given data. Unlike in the case of NewPoint and NewPointWithTimestamp, global tags will not be included in the returned point. The data is considered valid if and only if:

* the name satisfies IsNameValid;
* the fields satisfy fields.IsValid;
* the tags satisfy tags.IsValid;
* the timestamp is non-zero.

If validation fails, an error will be returned describing the problem.

func (*Point) Fields

func (p *Point) Fields() Fields

Fields returns (a copy of) the fields associated with this point.

func (*Point) GobDecode

func (p *Point) GobDecode(b []byte) error

GobDecode overwrites the receiver, which must be a valid pointer, with the value represented by the byte slice, which was written by GobEncode.

func (*Point) GobEncode

func (p *Point) GobEncode() ([]byte, error)

GobEncode returns a byte slice representing the encoding of the point.

func (*Point) Name

func (p *Point) Name() string

Name returns the name associated with this point.

func (*Point) String

func (p *Point) String() string

String returns a string description of the point.

func (*Point) Tags

func (p *Point) Tags() Tags

Tags returns (a copy of) the tags associated with this point.

func (*Point) Timestamp

func (p *Point) Timestamp() time.Time

Timestamp returns the timestamp associated with this point.

type PointIterator

type PointIterator interface {
	Close() error  // Close closes the iterator, preventing further iteration.
	Err() error    // Err returns the last error, if any, encountered during iteration. Err may be called after Close.
	Next() bool    // Next advances the iterator. Returns true if there are more points in the iterator; false otherwise. Next must be called before the first call to Value.
	Value() *Point // Value returns the current point in the iterator. Attempting to call Value after the iterator is closed, or without a previous successful call to Next, may panic.
}

PointIterator describe an iterator for Point data.

func IteratorFromSlice

func IteratorFromSlice(S []*Point) PointIterator

IteratorFromSlice returns a PointIterator based on S.

type SetMetricser

type SetMetricser interface {
	SetMetrics(m Interface) // SetMetrics sets a metrics endpoint.
}

SetMetricser is the interface satisfied by the SetMetrics method.

type SwapMetrics

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

SwapMetrics wraps an Interface that may be safely replaced while other go routines use the SwapMetrics concurrently. The zero value for a SwapMetrics will discard all metrics without error.

func (*SwapMetrics) Close

func (s *SwapMetrics) Close() error

Close calls Close on the wrapped Interface, if the wrapped Interface satisfies the io.Closer interface. Otherwise it does nothing.

func (*SwapMetrics) Submit

func (s *SwapMetrics) Submit(ctx context.Context, p *Point) error

Submit submits the given point to the wrapped Interface.

func (*SwapMetrics) SubmitPoints

func (s *SwapMetrics) SubmitPoints(ctx context.Context, itr PointIterator) error

SubmitPoints submits the points in the given iterator to the wrapped Interface.

func (*SwapMetrics) SubmitSlice

func (s *SwapMetrics) SubmitSlice(ctx context.Context, ps []*Point) error

SubmitSlice submits the given slice of points to the wrapped Interface.

func (*SwapMetrics) Swap

func (s *SwapMetrics) Swap(m Interface)

Swap replaces the currently wrapped Interface with m. This will panic if s is nil.

func (*SwapMetrics) Unwrap

func (s *SwapMetrics) Unwrap() Interface

Unwrap returns the wrapped Interface. If the wrapped Interface is nil, then Discard is returned.

type Tags

type Tags map[string]string

Tags is a map of tag names and values.

func (Tags) Copy

func (t Tags) Copy() Tags

Copy returns a copy of the tags.

func (Tags) IsValid

func (t Tags) IsValid() (bool, error)

IsValid returns true if and only if the tags are valid. If false, an error will be returned describing the problem. The tags are considered valid if and only if:

* the keys satisfy IsKeyValid;
* the values satisfy IsTagValueValid.

func (Tags) Keys

func (t Tags) Keys() []string

Keys returns a slice of keys of the tags. The keys are returned sorted using sort.Strings.

func (Tags) String

func (t Tags) String() string

String returns a string representation of the tags.

type ToMany

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

ToMany combines multiple Interfaces, sending all metrics to each of the Interfaces. ToMany is safe to be used concurrently. The zero value for a ToMany will discard all metrics without an error.

func (*ToMany) Append

func (s *ToMany) Append(m ...Interface)

Append appends the given Interfaces to the slice of Interfaces being used. This will panic if s is nil.

func (*ToMany) Close

func (s *ToMany) Close() (err error)

Close calls Close on each of the associated Interfaces, if the Interface satisfies the io.Closer interface.

func (*ToMany) Len

func (s *ToMany) Len() (n int)

Len returns the number of Interfaces being used.

func (*ToMany) Metrics

func (s *ToMany) Metrics() []Interface

Metrics returns the slice of Interfaces being used.

func (*ToMany) Reset

func (s *ToMany) Reset() []Interface

Reset returns the current slice of Interfaces being used, and empties this slice.

func (*ToMany) Submit

func (s *ToMany) Submit(ctx context.Context, p *Point) (err error)

Submit submits the given point to the Interfaces.

func (*ToMany) SubmitSlice

func (s *ToMany) SubmitSlice(ctx context.Context, ps []*Point) (err error)

SubmitSlice submits the given slice of points to the Interfaces.

Directories

Path Synopsis
cmd
Package influxdb provides an InfluxDB endpoint for metrics data.
Package influxdb provides an InfluxDB endpoint for metrics data.
metricsdbflag
Package metricsdbflag provides a standard flag set for configuring the metrics package and starting metrics collection.
Package metricsdbflag provides a standard flag set for configuring the metrics package and starting metrics collection.
Package metricsreporter provides a reporter for metrics data collected by package "github.com/rcrowley/go-metrics".
Package metricsreporter provides a reporter for metrics data collected by package "github.com/rcrowley/go-metrics".

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL