stats

package
v0.1.12 Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2020 License: BSD-3-Clause Imports: 10 Imported by: 25

Documentation

Overview

Package stats implements a global repository of stats objects. Each object has a name and a value. Example:

bar1 := stats.NewInteger("foo/bar1")
bar2 := stats.NewFloat("foo/bar2")
bar3 := stats.NewCounter("foo/bar3")
bar1.Set(1)
bar2.Set(2)
bar3.Set(3)

The values can be retrieved with:

v, err := stats.Value("foo/bar1")

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Delete

func Delete(name string) error

Delete deletes a StatsObject and all its children, if any.

func NewCounter

func NewCounter(name string) *counter.Counter

NewCounter creates a new Counter StatsObject with the given name and returns a pointer to it.

func NewHistogram

func NewHistogram(name string, opts histogram.Options) *histogram.Histogram

NewHistogram creates a new Histogram StatsObject with the given name and returns a pointer to it.

func Value

func Value(name string) (interface{}, error)

Value returns the value of an object, or an error if the object doesn't exist.

Types

type Float

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

Float implements the StatsObject interface.

func NewFloat

func NewFloat(name string) *Float

NewFloat creates a new Float StatsObject with the given name and returns a pointer to it.

func (*Float) Incr

func (f *Float) Incr(delta float64)

Incr increments the value of the object.

func (*Float) LastUpdate

func (f *Float) LastUpdate() time.Time

LastUpdate returns the time at which the object was last updated.

func (*Float) Set

func (f *Float) Set(value float64)

Set sets the value of the object.

func (*Float) Value

func (f *Float) Value() interface{}

Value returns the current value of the object.

type GlobIterator

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

func Glob

func Glob(root string, pattern string, updatedSince time.Time, includeValues bool) *GlobIterator

Glob returns the name and (optionally) the value of all the objects that match the given pattern and have been updated since 'updatedSince'. The 'root' argument is the name of the object where the pattern starts. Example:

a/b/c
a/b/d
b/e/f

Glob("", "...", time.Time{}, true) will return "a/b/c", "a/b/d", "b/e/f" and their values. Glob("a/b", "*", time.Time{}, true) will return "c", "d" and their values.

func (*GlobIterator) Advance

func (i *GlobIterator) Advance() bool

Advance stages the next element so that the client can retrieve it with Value(). It returns true iff there is an element to retrieve. The client must call Advance() before calling Value(). Advance may block if an element is not immediately available.

func (GlobIterator) Err

func (i GlobIterator) Err() error

Err returns a non-nil error iff the stream encountered any errors. Err does not block.

func (GlobIterator) Value

func (i GlobIterator) Value() KeyValue

Value returns the element that was staged by Advance. Value does not block.

type Integer

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

Integer implements the StatsObject interface.

func NewInteger

func NewInteger(name string) *Integer

NewInteger creates a new Integer StatsObject with the given name and returns a pointer to it.

func (*Integer) Incr

func (i *Integer) Incr(delta int64)

Incr increments the value of the object.

func (*Integer) LastUpdate

func (i *Integer) LastUpdate() time.Time

LastUpdate returns the time at which the object was last updated.

func (*Integer) Set

func (i *Integer) Set(value int64)

Set sets the value of the object.

func (*Integer) Value

func (i *Integer) Value() interface{}

Value returns the current value of the object.

type KeyValue

type KeyValue struct {
	Key   string
	Value interface{}
}

KeyValue stores a Key and a Value.

type Map

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

Map implements the StatsObject interface. The map keys are strings and the values can be bool, int64, uint64, float64, string, or time.Time.

func NewMap

func NewMap(name string) *Map

NewMap creates a new Map StatsObject with the given name and returns a pointer to it.

func (*Map) Delete

func (m *Map) Delete(keys []string)

Delete deletes the given keys from the map object.

func (*Map) Incr

func (m *Map) Incr(key string, delta int64) interface{}

Incr increments the value of the given key and returns the new value.

func (*Map) Keys

func (m *Map) Keys() []string

Keys returns a sorted list of all the keys in the map.

func (*Map) LastUpdate

func (m *Map) LastUpdate() time.Time

LastUpdate always returns a zero-value Time for a Map.

func (*Map) Set

func (m *Map) Set(kvpairs []KeyValue)

Set sets the values of the given keys. There must be exactly one value for each key.

func (*Map) Value

func (m *Map) Value() interface{}

Value always returns nil for a Map.

type StatsObject

type StatsObject interface {
	// LastUpdate is used by WatchGlob to decide which updates to send.
	LastUpdate() time.Time
	// Value returns the current value of the object.
	Value() interface{}
}

StatsObject is the interface for objects stored in the stats repository.

func GetStatsObject

func GetStatsObject(name string) (StatsObject, error)

GetStatsObject returns the object with that given name, or an error if the object doesn't exist.

func NewFloatFunc

func NewFloatFunc(name string, function func() float64) StatsObject

NewFloatFunc creates a new StatsObject with the given name. The function argument must return a float64 value.

func NewIntegerFunc

func NewIntegerFunc(name string, function func() int64) StatsObject

NewIntegerFunc creates a new StatsObject with the given name. The function argument must return an int64 value.

func NewStringFunc

func NewStringFunc(name string, function func() string) StatsObject

NewStringFunc creates a new StatsObject with the given name. The function argument must return a string value.

type String

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

String implements the StatsObject interface.

func NewString

func NewString(name string) *String

NewString creates a new String StatsObject with the given name and returns a pointer to it.

func (*String) LastUpdate

func (s *String) LastUpdate() time.Time

LastUpdate returns the time at which the object was last updated.

func (*String) Set

func (s *String) Set(value string)

Set sets the value of the object.

func (*String) Value

func (s *String) Value() interface{}

Value returns the current value of the object.

Directories

Path Synopsis
Package counter implements counters that keeps track of their recent values over different periods of time.
Package counter implements counters that keeps track of their recent values over different periods of time.
Package histogram implements a basic histogram to keep track of data distribution.
Package histogram implements a basic histogram to keep track of data distribution.
Package sysstats implements system statistics and updates them periodically.
Package sysstats implements system statistics and updates them periodically.

Jump to

Keyboard shortcuts

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