v.io: v.io/x/ref/lib/stats Index | Files | Directories

package stats

import "v.io/x/ref/lib/stats"

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

Package Files

counter.go float.go func.go glob.go histogram.go integer.go map.go stats.go string.go

func Delete Uses

func Delete(name string) error

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

func NewCounter Uses

func NewCounter(name string) *counter.Counter

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

func NewHistogram Uses

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 Uses

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

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

type Float Uses

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

Float implements the StatsObject interface.

func NewFloat Uses

func NewFloat(name string) *Float

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

func (*Float) Incr Uses

func (f *Float) Incr(delta float64)

Incr increments the value of the object.

func (*Float) LastUpdate Uses

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

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

func (*Float) Set Uses

func (f *Float) Set(value float64)

Set sets the value of the object.

func (*Float) Value Uses

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

Value returns the current value of the object.

type GlobIterator Uses

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

func Glob Uses

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 Uses

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 Uses

func (i GlobIterator) Err() error

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

func (GlobIterator) Value Uses

func (i GlobIterator) Value() KeyValue

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

type Integer Uses

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

Integer implements the StatsObject interface.

func NewInteger Uses

func NewInteger(name string) *Integer

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

func (*Integer) Incr Uses

func (i *Integer) Incr(delta int64)

Incr increments the value of the object.

func (*Integer) LastUpdate Uses

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

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

func (*Integer) Set Uses

func (i *Integer) Set(value int64)

Set sets the value of the object.

func (*Integer) Value Uses

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

Value returns the current value of the object.

type KeyValue Uses

type KeyValue struct {
    Key   string
    Value interface{}
}

KeyValue stores a Key and a Value.

type Map Uses

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 Uses

func NewMap(name string) *Map

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

func (*Map) Delete Uses

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

Delete deletes the given keys from the map object.

func (*Map) Incr Uses

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 Uses

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

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

func (*Map) LastUpdate Uses

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

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

func (*Map) Set Uses

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 Uses

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

Value always returns nil for a Map.

type StatsObject Uses

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. nolint:golint // API change required.

func GetStatsObject Uses

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 Uses

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 Uses

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 Uses

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 Uses

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

String implements the StatsObject interface.

func NewString Uses

func NewString(name string) *String

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

func (*String) LastUpdate Uses

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

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

func (*String) Set Uses

func (s *String) Set(value string)

Set sets the value of the object.

func (*String) Value Uses

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

Value returns the current value of the object.

Directories

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

Package stats imports 10 packages (graph) and is imported by 39 packages. Updated 2020-10-22. Refresh now. Tools for package owners.