metrics

package
v0.0.0-...-394be08 Latest Latest
Warning

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

Go to latest
Published: Aug 26, 2015 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

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

Index

Constants

This section is empty.

Variables

View Source
var (
	// MetricUpdateTime contains the timestamp of the last update of a metric.
	// TODO(jaq): move this global value to be a property of the Store.
	MetricUpdateTime atomic.Value
)

Functions

This section is empty.

Types

type Datum

type Datum struct {
	sync.RWMutex
	Value int64
	Time  time.Time
}

Datum describes a LabelSet's or LabelValue's value at a given timestamp.

func (*Datum) Get

func (d *Datum) Get() int64

Get returns the value of the Datum.

func (*Datum) IncBy

func (d *Datum) IncBy(delta int64, timestamp time.Time)

IncBy implements the Incrementable interface for a Datum.

func (*Datum) Set

func (d *Datum) Set(value int64, timestamp time.Time)

Set implements the Settable interface for a Datum.

func (*Datum) String

func (d *Datum) String() string

type Incrementable

type Incrementable interface {
	IncBy(delta int64, ts time.Time)
}

Incrementable describes an interface for Counter MetricTypes, that must be nondecreasing.

type LabelSet

type LabelSet struct {
	Labels map[string]string
	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
}

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

func (*LabelValue) String

func (lv *LabelValue) String() string

type Metric

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

Metric is an object that describes a metric, with its name, the creator and owner program name, its MetricType, 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 MetricType, keys ...string) *Metric

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

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) GetDatum

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

GetDatum returns the datum named by a sequence of string label values from a Metric.

func (*Metric) String

func (m *Metric) String() string

type MetricType

type MetricType int

MetricType enumerates the types of metrics supported.

const (
	// Counter is a MetricType that is nondecreasing, typically only
	// incrementable.
	Counter MetricType = iota
	// Gauge is a MetricType that can take on any value, and may be set
	// discontinuously from its previous value.
	Gauge
)

func (MetricType) String

func (m MetricType) String() string

type Metrics

type Metrics []*Metric

Metrics defines a Sortable type for a slice of metrics.

func (Metrics) Len

func (ms Metrics) Len() int

func (Metrics) Less

func (ms Metrics) Less(i, j int) bool

func (Metrics) Swap

func (ms Metrics) Swap(i, j int)

type Settable

type Settable interface {
	Set(value int64, ts time.Time)
}

Settable describes an interface for Gauge MetricTypes, that can be set to any value discontinuously from its previous.

type Store

type Store struct {
	sync.RWMutex
	Metrics []*Metric
}

Store contains Metrics.

func (*Store) Add

func (ms *Store) Add(m ...*Metric)

Add is used to add one or more metrics in the Store.

func (*Store) ClearMetrics

func (ms *Store) ClearMetrics()

ClearMetrics empties the store of all metrics.

Jump to

Keyboard shortcuts

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