metrics

package
v0.0.0-...-5655933 Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2023 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package metrics provides storage for metrics being recorded by mtail programs.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Less

func Less(m1, m2 *Metric) bool

Types

type Kind

type Kind int

Kind enumerates the types of metrics supported.

const (

	// Counter is a monotonically nondecreasing metric.
	Counter Kind

	// Gauge is a Kind that can take on any value, and may be set
	// discontinuously from its previous value.
	Gauge

	// Timer is a specialisation of Gauge that can be used to store time
	// intervals, such as latency and durations.  It enables certain behaviour
	// in exporters that handle time intervals such as StatsD.
	Timer

	// Text is a special metric type for free text, usually for operating as a 'hidden' metric, as often these values cannot be exported.
	Text

	// Histogram is a Kind that observes a value and stores the value
	// in a bucket.
	Histogram
)

func (Kind) Generate

func (Kind) Generate(rand *rand.Rand, size int) reflect.Value

Generate implements the quick.Generator interface for Kind.

func (Kind) String

func (m Kind) String() string

type LabelSet

type LabelSet struct {
	Labels map[string]string
	Datum  datum.Datum
}

LabelSet is an object that maps the keys of a Metric to the labels naming a Datum, for use when enumerating Datums from a Metric.

type LabelValue

type LabelValue struct {
	Labels []string `json:",omitempty"`
	Value  datum.Datum
	// After this time of inactivity, the LabelValue is removed from the metric.
	Expiry time.Duration `json:",omitempty"`
}

LabelValue is an object that names a Datum value with a list of label strings.

func (*LabelValue) UnmarshalJSON

func (lv *LabelValue) UnmarshalJSON(b []byte) error

UnmarshalJSON converts a JSON byte string into a LabelValue.

type Metric

type Metric struct {
	sync.RWMutex
	Name        string // Name
	Program     string // Instantiating program
	Kind        Kind
	Type        Type
	Hidden      bool          `json:",omitempty"`
	Keys        []string      `json:",omitempty"`
	LabelValues []*LabelValue `json:",omitempty"`

	Source  string        `json:",omitempty"`
	Buckets []datum.Range `json:",omitempty"`
	Limit   int           `json:",omitempty"`
	// contains filtered or unexported fields
}

Metric is an object that describes a metric, with its name, the creator and owner program name, its Kind, a sequence of Keys that may be used to add dimension to the metric, and a list of LabelValues that contain data for labels in each dimension of the Keys.

func NewMetric

func NewMetric(name string, prog string, kind Kind, typ Type, keys ...string) *Metric

NewMetric returns a new empty metric of dimension len(keys).

func (*Metric) AppendLabelValue

func (m *Metric) AppendLabelValue(lv *LabelValue) error

func (*Metric) EmitLabelSets

func (m *Metric) EmitLabelSets(c chan *LabelSet)

EmitLabelSets enumerates the LabelSets corresponding to the LabelValues of a Metric. It emits them onto the provided channel, then closes the channel to signal completion.

func (*Metric) ExpireDatum

func (m *Metric) ExpireDatum(expiry time.Duration, labelvalues ...string) error

func (*Metric) FindLabelValueOrNil

func (m *Metric) FindLabelValueOrNil(labelvalues []string) *LabelValue

func (*Metric) GetDatum

func (m *Metric) GetDatum(labelvalues ...string) (d datum.Datum, err error)

GetDatum returns the datum named by a sequence of string label values from a Metric. If the sequence of label values does not yet exist, it is created.

func (*Metric) RemoveDatum

func (m *Metric) RemoveDatum(labelvalues ...string) error

RemoveDatum removes the Datum described by labelvalues from the Metric m.

func (*Metric) RemoveOldestDatum

func (m *Metric) RemoveOldestDatum()

RemoveOldestDatum scans the Metric's LabelValues for the Datum with the oldest timestamp, and removes it.

func (*Metric) SetSource

func (m *Metric) SetSource(source string)

SetSource sets the source of a metric, describing where in user programmes it was defined.

func (*Metric) String

func (m *Metric) String() string

type MetricSlice

type MetricSlice []*Metric

func (MetricSlice) Len

func (s MetricSlice) Len() int

func (MetricSlice) Less

func (s MetricSlice) Less(i, j int) bool

func (MetricSlice) Swap

func (s MetricSlice) Swap(i, j int)

type Store

type Store struct {
	Metrics map[string][]*Metric
	// contains filtered or unexported fields
}

Store contains Metrics.

func NewStore

func NewStore() (s *Store)

NewStore returns a new metric Store.

func (*Store) Add

func (s *Store) Add(m *Metric) error

Add is used to add one metric to the Store.

func (*Store) ClearMetrics

func (s *Store) ClearMetrics()

ClearMetrics empties the store of all metrics.

func (*Store) FindMetricOrNil

func (s *Store) FindMetricOrNil(name, prog string) *Metric

FindMetricOrNil returns a metric in a store, or returns nil if not found.

func (*Store) Gc

func (s *Store) Gc() error

Gc iterates through the Store looking for metrics that can be tidied up, if they are passed their expiry or sized greater than their limit.

func (*Store) MarshalJSON

func (s *Store) MarshalJSON() (b []byte, err error)

MarshalJSON returns a JSON byte string representing the Store.

func (*Store) Range

func (s *Store) Range(f func(*Metric) error) error

Range calls f sequentially for each Metric present in the store. The Metric is not locked when f is called. If f returns non nil error, Range stops the iteration. This looks a lot like sync.Map, ay.

func (*Store) StartGcLoop

func (s *Store) StartGcLoop(ctx context.Context, duration time.Duration)

StartGcLoop runs a permanent goroutine to expire metrics every duration.

func (*Store) WriteMetrics

func (s *Store) WriteMetrics(w io.Writer) error

WriteMetrics dumps the current state of the metrics store in JSON format to the io.Writer.

type Type

type Type int

Type describes the type of value stored in a Datum.

const (
	// Int indicates this metric is an integer metric type.
	Int Type = iota
	// Float indicates this metric is a floating-point metric type.
	Float
	// String indicates this metric contains printable string values.
	String
	// Buckets indicates this metric is a histogram metric type.
	Buckets
)

func (Type) Generate

func (Type) Generate(rand *rand.Rand, size int) reflect.Value

Generate implements the quick.Generator interface for Type.

func (Type) String

func (t Type) String() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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