stats

package
v0.255.3 Latest Latest
Warning

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

Go to latest
Published: Jun 12, 2018 License: AGPL-3.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Counter = MetricType(iota) // A counter that sums its data points
	Gauge                      // A gauge that displays the latest value
	Trend                      // A trend, min/max/avg/med are interesting
	Rate                       // A rate, displays % of values that aren't 0
)

Possible values for MetricType.

View Source
const (
	Default = ValueType(iota) // Values are presented as-is
	Time                      // Values are timestamps (nanoseconds)
	Data                      // Values are data amounts (bytes)
)

Possible values for ValueType.

Variables

View Source
var ErrInvalidMetricType = errors.New("Invalid metric type")

The serialized metric type is invalid.

View Source
var ErrInvalidValueType = errors.New("Invalid value type")

The serialized value type is invalid.

Functions

func D added in v0.8.2

func D(d time.Duration) float64

D formats a duration for emission. The reverse of D() is ToD().

func ToD added in v0.8.2

func ToD(d float64) time.Duration

ToD converts an emitted duration to a time.Duration. The reverse of ToD() is D().

Types

type ConnectedSampleContainer added in v0.21.0

type ConnectedSampleContainer interface {
	SampleContainer
	GetTags() *SampleTags
	GetTime() time.Time
}

ConnectedSampleContainer is an extension of the SampleContainer interface that should be implemented when emitted samples are connected and share the same time and tags.

type ConnectedSamples added in v0.21.0

type ConnectedSamples struct {
	Samples []Sample
	Tags    *SampleTags
	Time    time.Time
}

ConnectedSamples is the simplest ConnectedSampleContainer implementation that will be used when there's no need for extra information

func (ConnectedSamples) GetSamples added in v0.21.0

func (cs ConnectedSamples) GetSamples() []Sample

GetSamples implements the SampleContainer and ConnectedSampleContainer interfaces and returns the stored slice with samples.

func (ConnectedSamples) GetTags added in v0.21.0

func (cs ConnectedSamples) GetTags() *SampleTags

GetTags implements ConnectedSampleContainer interface and returns stored tags.

func (ConnectedSamples) GetTime added in v0.21.0

func (cs ConnectedSamples) GetTime() time.Time

GetTime implements ConnectedSampleContainer interface and returns stored time.

type CounterSink

type CounterSink struct {
	Value float64
	First time.Time
}

func (*CounterSink) Add

func (c *CounterSink) Add(s Sample)

func (*CounterSink) Calc added in v0.18.0

func (c *CounterSink) Calc()

func (*CounterSink) Format

func (c *CounterSink) Format(t time.Duration) map[string]float64

type DummySink added in v0.5.0

type DummySink map[string]float64

func (DummySink) Add added in v0.5.0

func (d DummySink) Add(s Sample)

func (DummySink) Calc added in v0.18.0

func (d DummySink) Calc()

func (DummySink) Format added in v0.5.0

func (d DummySink) Format(t time.Duration) map[string]float64

type GaugeSink

type GaugeSink struct {
	Value    float64
	Max, Min float64
	// contains filtered or unexported fields
}

func (*GaugeSink) Add

func (g *GaugeSink) Add(s Sample)

func (*GaugeSink) Calc added in v0.18.0

func (g *GaugeSink) Calc()

func (*GaugeSink) Format

func (g *GaugeSink) Format(t time.Duration) map[string]float64

type Metric

type Metric struct {
	Name       string       `json:"name"`
	Type       MetricType   `json:"type"`
	Contains   ValueType    `json:"contains"`
	Tainted    null.Bool    `json:"tainted"`
	Thresholds Thresholds   `json:"thresholds"`
	Submetrics []*Submetric `json:"submetrics"`
	Sub        Submetric    `json:"sub,omitempty"`
	Sink       Sink         `json:"-"`
}

A Metric defines the shape of a set of data.

func New

func New(name string, typ MetricType, t ...ValueType) *Metric

func (*Metric) HumanizeValue

func (m *Metric) HumanizeValue(v float64, timeUnit string) string

func (*Metric) Summary added in v0.18.0

func (m *Metric) Summary(t time.Duration) *Summary

type MetricType

type MetricType int

A MetricType specifies the type of a metric.

func (MetricType) MarshalJSON

func (t MetricType) MarshalJSON() ([]byte, error)

MarshalJSON serializes a MetricType as a human readable string.

func (MetricType) String

func (t MetricType) String() string

func (*MetricType) UnmarshalJSON

func (t *MetricType) UnmarshalJSON(data []byte) error

UnmarshalJSON deserializes a MetricType from a string representation.

type RateSink

type RateSink struct {
	Trues int64
	Total int64
}

func (*RateSink) Add

func (r *RateSink) Add(s Sample)

func (RateSink) Calc added in v0.18.0

func (r RateSink) Calc()

func (RateSink) Format

func (r RateSink) Format(t time.Duration) map[string]float64

type Sample

type Sample struct {
	Metric *Metric
	Time   time.Time
	Tags   *SampleTags
	Value  float64
}

A Sample is a single measurement.

func (Sample) GetSamples added in v0.21.0

func (s Sample) GetSamples() []Sample

GetSamples implement the ConnectedSampleContainer interface for a single Sample, since it's obviously connected with itself :)

func (Sample) GetTags added in v0.21.0

func (s Sample) GetTags() *SampleTags

GetTags implements ConnectedSampleContainer interface and returns the sample's tags.

func (Sample) GetTime added in v0.21.0

func (s Sample) GetTime() time.Time

GetTime just implements ConnectedSampleContainer interface and returns the sample's time.

type SampleContainer added in v0.21.0

type SampleContainer interface {
	GetSamples() []Sample
}

SampleContainer is a simple abstraction that allows sample producers to attach extra information to samples they return

type SampleTags added in v0.21.0

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

SampleTags is an immutable string[string] map for tags. Once a tag set is created, direct modification is prohibited. It has copy-on-write semantics and uses pointers for faster comparison between maps, since the same tag set is often used for multiple samples. All methods should not panic, even if they are called on a nil pointer.

func IntoSampleTags added in v0.21.0

func IntoSampleTags(data *map[string]string) *SampleTags

IntoSampleTags "consumes" the passed map and creates a new SampleTags struct with the data. The map is set to nil as a hint that it shouldn't be changed after it has been transformed into an "immutable" tag set. Oh, how I miss Rust and move semantics... :)

func NewSampleTags added in v0.21.0

func NewSampleTags(data map[string]string) *SampleTags

NewSampleTags *copies* the supplied tag set and returns a new SampleTags instance with the key-value pairs from it.

func (*SampleTags) CloneTags added in v0.21.0

func (st *SampleTags) CloneTags() map[string]string

CloneTags copies the underlying set of a sample tags and returns it. If the receiver is nil, it returns an empty non-nil map.

func (*SampleTags) Contains added in v0.21.0

func (st *SampleTags) Contains(other *SampleTags) bool

func (*SampleTags) Get added in v0.21.0

func (st *SampleTags) Get(key string) (string, bool)

Get returns an empty string and false if the the requested key is not present or its value and true if it is.

func (*SampleTags) IsEmpty added in v0.21.0

func (st *SampleTags) IsEmpty() bool

IsEmpty checks for a nil pointer or zero tags. It's necessary because of this envconfig issue: https://github.com/kelseyhightower/envconfig/issues/113

func (*SampleTags) IsEqual added in v0.21.0

func (st *SampleTags) IsEqual(other *SampleTags) bool

IsEqual tries to compare two tag sets with maximum efficiency.

func (*SampleTags) MarshalJSON added in v0.21.0

func (st *SampleTags) MarshalJSON() ([]byte, error)

MarshalJSON serializes SampleTags to a JSON string and caches the result. It is not thread safe in the sense that the Go race detector will complain if it's used concurrently, but no data should be corrupted.

func (*SampleTags) UnmarshalJSON added in v0.21.0

func (st *SampleTags) UnmarshalJSON(data []byte) error

UnmarshalJSON deserializes SampleTags from a JSON string.

type Samples added in v0.21.0

type Samples []Sample

Samples is just the simplest SampleContainer implementation that will be used when there's no need for extra information

func (Samples) GetSamples added in v0.21.0

func (s Samples) GetSamples() []Sample

GetSamples just implements the SampleContainer interface

type Sink

type Sink interface {
	Add(s Sample)                              // Add a sample to the sink.
	Calc()                                     // Make final calculations.
	Format(t time.Duration) map[string]float64 // Data for thresholds.
}

type Submetric added in v0.13.0

type Submetric struct {
	Name   string      `json:"name"`
	Parent string      `json:"parent"`
	Suffix string      `json:"suffix"`
	Tags   *SampleTags `json:"tags"`
	Metric *Metric     `json:"-"`
}

A Submetric represents a filtered dataset based on a parent metric.

func NewSubmetric added in v0.13.0

func NewSubmetric(name string) (parentName string, sm *Submetric)

Creates a submetric from a name.

type Summary added in v0.18.0

type Summary struct {
	Metric  *Metric            `json:"metric"`
	Summary map[string]float64 `json:"summary"`
}

type Threshold added in v0.13.0

type Threshold struct {
	Source           string
	Failed           bool
	AbortOnFail      bool
	AbortGracePeriod types.NullDuration
	// contains filtered or unexported fields
}

func NewThreshold added in v0.13.0

func NewThreshold(src string, rt *goja.Runtime, abortOnFail bool, gracePeriod types.NullDuration) (*Threshold, error)

func (*Threshold) Run added in v0.13.0

func (t *Threshold) Run() (bool, error)

func (Threshold) RunNoTaint added in v0.13.0

func (t Threshold) RunNoTaint() (bool, error)

type ThresholdConfig added in v0.20.0

type ThresholdConfig struct {
	Threshold        string             `json:"threshold"`
	AbortOnFail      bool               `json:"abortOnFail"`
	AbortGracePeriod types.NullDuration `json:"delayAbortEval"`
}

func (ThresholdConfig) MarshalJSON added in v0.20.0

func (tc ThresholdConfig) MarshalJSON() ([]byte, error)

func (*ThresholdConfig) UnmarshalJSON added in v0.20.0

func (tc *ThresholdConfig) UnmarshalJSON(data []byte) error

type Thresholds added in v0.13.0

type Thresholds struct {
	Runtime    *goja.Runtime
	Thresholds []*Threshold
	Abort      bool
}

func NewThresholds added in v0.13.0

func NewThresholds(sources []string) (Thresholds, error)

func NewThresholdsWithConfig added in v0.20.0

func NewThresholdsWithConfig(configs []ThresholdConfig) (Thresholds, error)

func (Thresholds) MarshalJSON added in v0.13.0

func (ts Thresholds) MarshalJSON() ([]byte, error)

func (*Thresholds) Run added in v0.13.0

func (ts *Thresholds) Run(sink Sink, t time.Duration) (bool, error)

func (*Thresholds) RunAll added in v0.13.0

func (ts *Thresholds) RunAll(t time.Duration) (bool, error)

func (*Thresholds) UnmarshalJSON added in v0.13.0

func (ts *Thresholds) UnmarshalJSON(data []byte) error

func (*Thresholds) UpdateVM added in v0.13.0

func (ts *Thresholds) UpdateVM(sink Sink, t time.Duration) error

type TrendSink

type TrendSink struct {
	Values []float64

	Count    uint64
	Min, Max float64
	Sum, Avg float64
	Med      float64
	// contains filtered or unexported fields
}

func (*TrendSink) Add

func (t *TrendSink) Add(s Sample)

func (*TrendSink) Calc added in v0.18.0

func (t *TrendSink) Calc()

func (*TrendSink) Format

func (t *TrendSink) Format(tt time.Duration) map[string]float64

func (*TrendSink) P

func (t *TrendSink) P(pct float64) float64

P calculates the given percentile from sink values.

type ValueType

type ValueType int

The type of values a metric contains.

func (ValueType) MarshalJSON

func (t ValueType) MarshalJSON() ([]byte, error)

MarshalJSON serializes a ValueType as a human readable string.

func (ValueType) String

func (t ValueType) String() string

func (*ValueType) UnmarshalJSON

func (t *ValueType) UnmarshalJSON(data []byte) error

UnmarshalJSON deserializes a ValueType from a string representation.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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