go-vitess.v1: gopkg.in/src-d/go-vitess.v1/stats Index | Files

package stats

import "gopkg.in/src-d/go-vitess.v1/stats"

Package stats is a wrapper for expvar. It addtionally exports new types that can be used to track performance. It also provides a callback hook that allows a program to export the variables using methods other than /debug/vars. All variables support a String function that is expected to return a JSON representation of the variable. Any function named Add will add the specified number to the variable. Any function named Counts returns a map of counts that can be used by Rates to track rates over time.

Index

Package Files

counter.go counters.go duration.go export.go histogram.go kebab_case_converter.go multidimensional.go rates.go ring.go safe_label.go snake_case_converter.go timings.go variable_interface.go

func GetSnakeName Uses

func GetSnakeName(name string) string

GetSnakeName calls toSnakeName on the passed in string. It produces a snake-cased name from the provided camel-cased name. It memoizes the transformation and returns the stored result if available.

func Publish Uses

func Publish(name string, v expvar.Var)

Publish is expvar.Publish+hook

func PublishJSONFunc Uses

func PublishJSONFunc(name string, f func() string)

PublishJSONFunc publishes any function that returns a JSON string as a variable. The string is sent to expvar as is.

func Register Uses

func Register(nvh NewVarHook)

Register allows you to register a callback function that will be called whenever a new stats variable gets created. This can be used to build alternate methods of exporting stats variables.

func RegisterPushBackend Uses

func RegisterPushBackend(name string, backend PushBackend)

RegisterPushBackend allows modules to register PushBackend implementations. Should be called on init().

type CountTracker Uses

type CountTracker interface {
    // Counts returns a map which maps each category to a count.
    // Subsequent calls must return a monotonously increasing count for the same
    // category.
    // Optionally, an implementation may include the "All" category which has
    // the total count across all categories (e.g. timing.go does this).
    Counts() map[string]int64
}

CountTracker defines the interface that needs to be supported by a variable for being tracked by Rates.

func CounterForDimension Uses

func CounterForDimension(mt MultiTracker, dimension string) CountTracker

CounterForDimension returns a CountTracker for the provided dimension. It will panic if the dimension isn't a legal label for mt.

type Counter Uses

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

Counter tracks a cumulative count of a metric. For a one-dimensional or multi-dimensional counter, please use CountersWithSingleLabel or CountersWithMultiLabels instead.

func NewCounter Uses

func NewCounter(name string, help string) *Counter

NewCounter returns a new Counter.

func (*Counter) Add Uses

func (v *Counter) Add(delta int64)

Add adds the provided value to the Counter.

func (*Counter) Get Uses

func (v *Counter) Get() int64

Get returns the value.

func (*Counter) Help Uses

func (v *Counter) Help() string

Help returns the help string.

func (*Counter) Reset Uses

func (v *Counter) Reset()

Reset resets the counter value to 0.

func (*Counter) String Uses

func (v *Counter) String() string

String implements the expvar.Var interface.

type CounterDuration Uses

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

CounterDuration exports a time.Duration as counter.

func NewCounterDuration Uses

func NewCounterDuration(name, help string) *CounterDuration

NewCounterDuration returns a new CounterDuration.

func (*CounterDuration) Add Uses

func (cd *CounterDuration) Add(delta time.Duration)

Add adds the provided value to the CounterDuration.

func (*CounterDuration) Get Uses

func (cd *CounterDuration) Get() time.Duration

Get returns the value.

func (CounterDuration) Help Uses

func (cd CounterDuration) Help() string

Help implements the Variable interface.

func (CounterDuration) String Uses

func (cd CounterDuration) String() string

String is the implementation of expvar.var.

type CounterDurationFunc Uses

type CounterDurationFunc struct {
    F func() time.Duration
    // contains filtered or unexported fields
}

CounterDurationFunc allows to provide the value via a custom function.

func NewCounterDurationFunc Uses

func NewCounterDurationFunc(name string, help string, f func() time.Duration) *CounterDurationFunc

NewCounterDurationFunc creates a new CounterDurationFunc instance and publishes it if name is set.

func (CounterDurationFunc) Help Uses

func (cf CounterDurationFunc) Help() string

Help implements the Variable interface.

func (CounterDurationFunc) String Uses

func (cf CounterDurationFunc) String() string

String is the implementation of expvar.var.

type CounterFunc Uses

type CounterFunc struct {
    F func() int64
    // contains filtered or unexported fields
}

CounterFunc allows to provide the counter value via a custom function. For implementations that differentiate between Counters/Gauges, CounterFunc's values only go up (or are reset to 0).

func NewCounterFunc Uses

func NewCounterFunc(name string, help string, f func() int64) *CounterFunc

NewCounterFunc creates a new CounterFunc instance and publishes it if name is set.

func (CounterFunc) Help Uses

func (cf CounterFunc) Help() string

Help returns the help string.

func (CounterFunc) String Uses

func (cf CounterFunc) String() string

String implements expvar.Var.

type CountersFuncWithMultiLabels Uses

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

CountersFuncWithMultiLabels is a multidimensional counters implementation where names of categories are compound names made with joining multiple strings with '.'. Since the map is returned by the function, we assume it's in the right format (meaning each key is of the form 'aaa.bbb.ccc' with as many elements as there are in Labels).

Note that there is no CountersFuncWithSingleLabel object. That this because such an object would be identical to this one because these function-based counters have no Add() or Set() method which are different for the single vs. multiple labels cases. If you have only a single label, pass an array with a single element.

func NewCountersFuncWithMultiLabels Uses

func NewCountersFuncWithMultiLabels(name, help string, labels []string, f func() map[string]int64) *CountersFuncWithMultiLabels

NewCountersFuncWithMultiLabels creates a new CountersFuncWithMultiLabels mapping to the provided function.

func (CountersFuncWithMultiLabels) Counts Uses

func (c CountersFuncWithMultiLabels) Counts() map[string]int64

Counts returns a copy of the counters' map.

func (CountersFuncWithMultiLabels) Help Uses

func (c CountersFuncWithMultiLabels) Help() string

Help returns the help string.

func (CountersFuncWithMultiLabels) Labels Uses

func (c CountersFuncWithMultiLabels) Labels() []string

Labels returns the list of labels.

func (CountersFuncWithMultiLabels) String Uses

func (c CountersFuncWithMultiLabels) String() string

String implements the expvar.Var interface.

type CountersWithMultiLabels Uses

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

CountersWithMultiLabels is a multidimensional counters implementation. Internally, each tuple of dimensions ("labels") is stored as a single label value where all label values are joined with ".".

func NewCountersWithMultiLabels Uses

func NewCountersWithMultiLabels(name, help string, labels []string) *CountersWithMultiLabels

NewCountersWithMultiLabels creates a new CountersWithMultiLabels instance, and publishes it if name is set.

func (*CountersWithMultiLabels) Add Uses

func (mc *CountersWithMultiLabels) Add(names []string, value int64)

Add adds a value to a named counter. len(names) must be equal to len(Labels)

func (*CountersWithMultiLabels) Counts Uses

func (mc *CountersWithMultiLabels) Counts() map[string]int64

Counts returns a copy of the Counters' map. The key is a single string where all labels are joined by a "." e.g. "label1.label2".

func (*CountersWithMultiLabels) Help Uses

func (c *CountersWithMultiLabels) Help() string

Help returns the help string.

func (*CountersWithMultiLabels) Labels Uses

func (mc *CountersWithMultiLabels) Labels() []string

Labels returns the list of labels.

func (*CountersWithMultiLabels) Reset Uses

func (mc *CountersWithMultiLabels) Reset(names []string)

Reset resets the value of a named counter back to 0. len(names) must be equal to len(Labels).

func (*CountersWithMultiLabels) ResetAll Uses

func (c *CountersWithMultiLabels) ResetAll()

ResetAll resets all counter values and clears all keys.

func (*CountersWithMultiLabels) String Uses

func (c *CountersWithMultiLabels) String() string

String implements the expvar.Var interface.

func (*CountersWithMultiLabels) ZeroAll Uses

func (c *CountersWithMultiLabels) ZeroAll()

ZeroAll resets all counter values to zero

type CountersWithSingleLabel Uses

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

CountersWithSingleLabel tracks multiple counter values for a single dimension ("label"). It provides a Counts method which can be used for tracking rates.

func NewCountersWithSingleLabel Uses

func NewCountersWithSingleLabel(name, help, label string, tags ...string) *CountersWithSingleLabel

NewCountersWithSingleLabel create a new Counters instance. If name is set, the variable gets published. The function also accepts an optional list of tags that pre-creates them initialized to 0. label is a category name used to organize the tags. It is currently only used by Prometheus, but not by the expvar package.

func (*CountersWithSingleLabel) Add Uses

func (c *CountersWithSingleLabel) Add(name string, value int64)

Add adds a value to a named counter.

func (*CountersWithSingleLabel) Counts Uses

func (c *CountersWithSingleLabel) Counts() map[string]int64

Counts returns a copy of the Counters' map.

func (*CountersWithSingleLabel) Help Uses

func (c *CountersWithSingleLabel) Help() string

Help returns the help string.

func (*CountersWithSingleLabel) Label Uses

func (c *CountersWithSingleLabel) Label() string

Label returns the label name.

func (*CountersWithSingleLabel) Reset Uses

func (c *CountersWithSingleLabel) Reset(name string)

Reset resets a specific counter value to 0.

func (*CountersWithSingleLabel) ResetAll Uses

func (c *CountersWithSingleLabel) ResetAll()

ResetAll clears the counters

func (*CountersWithSingleLabel) String Uses

func (c *CountersWithSingleLabel) String() string

String implements the expvar.Var interface.

func (*CountersWithSingleLabel) ZeroAll Uses

func (c *CountersWithSingleLabel) ZeroAll()

ZeroAll resets all counter values to zero

type FloatFunc Uses

type FloatFunc func() float64

FloatFunc converts a function that returns a float64 as an expvar.

func (FloatFunc) Help Uses

func (f FloatFunc) Help() string

Help returns the help string (undefined currently)

func (FloatFunc) String Uses

func (f FloatFunc) String() string

String is the implementation of expvar.var

type Gauge Uses

type Gauge struct {
    Counter
}

Gauge tracks the current value of an integer metric. The emphasis here is on *current* i.e. this is not a cumulative counter. For a one-dimensional or multi-dimensional gauge, please use GaugeWithSingleLabel or GaugesWithMultiLabels instead.

func NewGauge Uses

func NewGauge(name string, help string) *Gauge

NewGauge creates a new Gauge and publishes it if name is set.

func (*Gauge) Add Uses

func (v *Gauge) Add(delta int64)

Add adds the provided value to the Gauge.

func (*Gauge) Set Uses

func (v *Gauge) Set(value int64)

Set overwrites the current value.

type GaugeDuration Uses

type GaugeDuration struct {
    CounterDuration
}

GaugeDuration exports a time.Duration as gauge. In addition to CounterDuration, it also has Set() which allows overriding the current value.

func NewGaugeDuration Uses

func NewGaugeDuration(name, help string) *GaugeDuration

NewGaugeDuration returns a new GaugeDuration.

func (*GaugeDuration) Set Uses

func (gd *GaugeDuration) Set(value time.Duration)

Set sets the value.

type GaugeDurationFunc Uses

type GaugeDurationFunc struct {
    CounterDurationFunc
}

GaugeDurationFunc allows to provide the value via a custom function.

func NewGaugeDurationFunc Uses

func NewGaugeDurationFunc(name string, help string, f func() time.Duration) *GaugeDurationFunc

NewGaugeDurationFunc creates a new GaugeDurationFunc instance and publishes it if name is set.

type GaugeFunc Uses

type GaugeFunc struct {
    CounterFunc
}

GaugeFunc is the same as CounterFunc but meant for gauges. It's a wrapper around CounterFunc for values that go up/down for implementations (like Prometheus) that need to differ between Counters and Gauges.

func NewGaugeFunc Uses

func NewGaugeFunc(name string, help string, f func() int64) *GaugeFunc

NewGaugeFunc creates a new GaugeFunc instance and publishes it if name is set.

type GaugesFuncWithMultiLabels Uses

type GaugesFuncWithMultiLabels struct {
    CountersFuncWithMultiLabels
}

GaugesFuncWithMultiLabels is a wrapper around CountersFuncWithMultiLabels for values that go up/down for implementations (like Prometheus) that need to differ between Counters and Gauges.

func NewGaugesFuncWithMultiLabels Uses

func NewGaugesFuncWithMultiLabels(name, help string, labels []string, f func() map[string]int64) *GaugesFuncWithMultiLabels

NewGaugesFuncWithMultiLabels creates a new GaugesFuncWithMultiLabels mapping to the provided function.

type GaugesWithMultiLabels Uses

type GaugesWithMultiLabels struct {
    CountersWithMultiLabels
}

GaugesWithMultiLabels is a CountersWithMultiLabels implementation where the values can go up and down.

func NewGaugesWithMultiLabels Uses

func NewGaugesWithMultiLabels(name, help string, labels []string) *GaugesWithMultiLabels

NewGaugesWithMultiLabels creates a new GaugesWithMultiLabels instance, and publishes it if name is set.

func (*GaugesWithMultiLabels) Add Uses

func (mg *GaugesWithMultiLabels) Add(names []string, value int64)

Add adds a value to a named gauge. len(names) must be equal to len(Labels).

func (*GaugesWithMultiLabels) Help Uses

func (c *GaugesWithMultiLabels) Help() string

Help returns the help string.

func (*GaugesWithMultiLabels) ResetAll Uses

func (c *GaugesWithMultiLabels) ResetAll()

ResetAll resets all counter values and clears all keys.

func (*GaugesWithMultiLabels) Set Uses

func (mg *GaugesWithMultiLabels) Set(names []string, value int64)

Set sets the value of a named counter. len(names) must be equal to len(Labels).

func (*GaugesWithMultiLabels) String Uses

func (c *GaugesWithMultiLabels) String() string

String implements the expvar.Var interface.

func (*GaugesWithMultiLabels) ZeroAll Uses

func (c *GaugesWithMultiLabels) ZeroAll()

ZeroAll resets all counter values to zero

type GaugesWithSingleLabel Uses

type GaugesWithSingleLabel struct {
    CountersWithSingleLabel
}

GaugesWithSingleLabel is similar to CountersWithSingleLabel, except its meant to track the current value and not a cumulative count.

func NewGaugesWithSingleLabel Uses

func NewGaugesWithSingleLabel(name, help, label string, tags ...string) *GaugesWithSingleLabel

NewGaugesWithSingleLabel creates a new GaugesWithSingleLabel and publishes it if the name is set.

func (*GaugesWithSingleLabel) Add Uses

func (g *GaugesWithSingleLabel) Add(name string, value int64)

Add adds a value to a named gauge.

func (*GaugesWithSingleLabel) Counts Uses

func (c *GaugesWithSingleLabel) Counts() map[string]int64

Counts returns a copy of the Counters' map.

func (*GaugesWithSingleLabel) Help Uses

func (c *GaugesWithSingleLabel) Help() string

Help returns the help string.

func (*GaugesWithSingleLabel) Reset Uses

func (c *GaugesWithSingleLabel) Reset(name string)

Reset resets a specific counter value to 0.

func (*GaugesWithSingleLabel) Set Uses

func (g *GaugesWithSingleLabel) Set(name string, value int64)

Set sets the value of a named gauge.

func (*GaugesWithSingleLabel) String Uses

func (c *GaugesWithSingleLabel) String() string

String implements the expvar.Var interface.

func (*GaugesWithSingleLabel) ZeroAll Uses

func (c *GaugesWithSingleLabel) ZeroAll()

ZeroAll resets all counter values to zero

type Histogram Uses

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

Histogram tracks counts and totals while splitting the counts under different buckets using specified cutoffs.

func NewGenericHistogram Uses

func NewGenericHistogram(name, help string, cutoffs []int64, labels []string, countLabel, totalLabel string) *Histogram

NewGenericHistogram creates a histogram where all the labels are supplied by the caller. The number of labels has to be one more than the number of cutoffs because the last label captures everything that exceeds the highest cutoff.

func NewHistogram Uses

func NewHistogram(name, help string, cutoffs []int64) *Histogram

NewHistogram creates a histogram with auto-generated labels based on the cutoffs. The buckets are categorized using the following criterion: cutoff[i-1] < value <= cutoff[i]. Anything higher than the highest cutoff is labeled as "inf".

func (*Histogram) Add Uses

func (h *Histogram) Add(value int64)

Add adds a new measurement to the Histogram.

func (*Histogram) Buckets Uses

func (h *Histogram) Buckets() []int64

Buckets returns a snapshot of the current values in all buckets.

func (*Histogram) Count Uses

func (h *Histogram) Count() (count int64)

Count returns the number of times Add has been called.

func (*Histogram) CountLabel Uses

func (h *Histogram) CountLabel() string

CountLabel returns the count label that was set when this Histogram was created.

func (*Histogram) Counts Uses

func (h *Histogram) Counts() map[string]int64

Counts returns a map from labels to the current count in the Histogram for that label.

func (*Histogram) Cutoffs Uses

func (h *Histogram) Cutoffs() []int64

Cutoffs returns the cutoffs that were set when this Histogram was created.

func (*Histogram) Help Uses

func (h *Histogram) Help() string

Help returns the help string.

func (*Histogram) Labels Uses

func (h *Histogram) Labels() []string

Labels returns the labels that were set when this Histogram was created.

func (*Histogram) MarshalJSON Uses

func (h *Histogram) MarshalJSON() ([]byte, error)

MarshalJSON returns a JSON representation of the Histogram. Note that sum of all buckets may not be equal to the total temporarily, because Add() increments bucket and total with two atomic operations.

func (*Histogram) String Uses

func (h *Histogram) String() string

String returns a string representation of the Histogram. Note that sum of all buckets may not be equal to the total temporarily, because Add() increments bucket and total with two atomic operations.

func (*Histogram) Total Uses

func (h *Histogram) Total() (total int64)

Total returns the sum of all values that have been added to this Histogram.

func (*Histogram) TotalLabel Uses

func (h *Histogram) TotalLabel() string

TotalLabel returns the total label that was set when this Histogram was created.

type JSONFunc Uses

type JSONFunc func() string

JSONFunc is the public type for a single function that returns json directly.

func (JSONFunc) String Uses

func (f JSONFunc) String() string

String is the implementation of expvar.var

type MultiTimings Uses

type MultiTimings struct {
    Timings
    // contains filtered or unexported fields
}

MultiTimings is meant to tracks timing data by categories as well as histograms. The names of the categories are compound names made with joining multiple strings with '.'.

func NewMultiTimings Uses

func NewMultiTimings(name string, help string, labels []string) *MultiTimings

NewMultiTimings creates a new MultiTimings object.

func (*MultiTimings) Add Uses

func (mt *MultiTimings) Add(names []string, elapsed time.Duration)

Add will add a new value to the named histogram.

func (*MultiTimings) Cutoffs Uses

func (mt *MultiTimings) Cutoffs() []int64

Cutoffs returns the cutoffs used in the component histograms. Do not change the returned slice.

func (*MultiTimings) Labels Uses

func (mt *MultiTimings) Labels() []string

Labels returns descriptions of the parts of each compound category name.

func (*MultiTimings) Record Uses

func (mt *MultiTimings) Record(names []string, startTime time.Time)

Record is a convenience function that records completion timing data based on the provided start time of an event.

type MultiTracker Uses

type MultiTracker interface {
    CountTracker
    Labels() []string
}

MultiTracker is a CountTracker that tracks counts grouping them by more than one dimension.

type NewVarHook Uses

type NewVarHook func(name string, v expvar.Var)

NewVarHook is the type of a hook to export variables in a different way

type PushBackend Uses

type PushBackend interface {
    // PushAll pushes all stats from expvar to the backend
    PushAll() error
}

PushBackend is an interface for any stats/metrics backend that requires data to be pushed to it. It's used to support push-based metrics backends, as expvar by default only supports pull-based ones.

type Rates Uses

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

Rates is capable of reporting the rate (typically QPS) for any variable that satisfies the CountTracker interface.

func NewRates Uses

func NewRates(name string, countTracker CountTracker, samples int, interval time.Duration) *Rates

NewRates reports rolling rate information for countTracker. samples specifies the number of samples to report, and interval specifies the time interval between samples. The minimum interval is 1 second. If passing the special value of -1s as interval, we don't snapshot. (use this for tests).

func (*Rates) Get Uses

func (rt *Rates) Get() (rateMap map[string][]float64)

Get returns for each category (string) its latest rates (up to X values where X is the configured number of samples of the Rates struct). Rates are ordered from least recent (index 0) to most recent (end of slice).

func (*Rates) String Uses

func (rt *Rates) String() string

func (*Rates) TotalRate Uses

func (rt *Rates) TotalRate() float64

TotalRate returns the current total rate (counted across categories).

type RingInt64 Uses

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

Ring of int64 values Not thread safe

func NewRingInt64 Uses

func NewRingInt64(capacity int) *RingInt64

func (*RingInt64) Add Uses

func (ri *RingInt64) Add(val int64)

func (*RingInt64) Values Uses

func (ri *RingInt64) Values() (values []int64)

type String Uses

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

String is expvar.String+Get+hook

func NewString Uses

func NewString(name string) *String

NewString returns a new String

func (*String) Get Uses

func (v *String) Get() string

Get returns the value

func (*String) Set Uses

func (v *String) Set(value string)

Set sets the value

func (*String) String Uses

func (v *String) String() string

String is the implementation of expvar.var

type StringFunc Uses

type StringFunc func() string

StringFunc converts a function that returns an string as an expvar.

func (StringFunc) String Uses

func (f StringFunc) String() string

String is the implementation of expvar.var

type StringMapFunc Uses

type StringMapFunc func() map[string]string

StringMapFunc is the function equivalent of StringMap

func (StringMapFunc) String Uses

func (f StringMapFunc) String() string

String is used by expvar.

type Timings Uses

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

Timings is meant to tracks timing data by named categories as well as histograms.

func NewTimings Uses

func NewTimings(name, help, label string, categories ...string) *Timings

NewTimings creates a new Timings object, and publishes it if name is set. categories is an optional list of categories to initialize to 0. Categories that aren't initialized will be missing from the map until the first time they are updated.

func (*Timings) Add Uses

func (t *Timings) Add(name string, elapsed time.Duration)

Add will add a new value to the named histogram.

func (*Timings) Count Uses

func (t *Timings) Count() int64

Count returns the total count for all values.

func (*Timings) Counts Uses

func (t *Timings) Counts() map[string]int64

Counts returns the total count for each value.

func (*Timings) Cutoffs Uses

func (t *Timings) Cutoffs() []int64

Cutoffs returns the cutoffs used in the component histograms. Do not change the returned slice.

func (*Timings) Help Uses

func (t *Timings) Help() string

Help returns the help string.

func (*Timings) Histograms Uses

func (t *Timings) Histograms() (h map[string]*Histogram)

Histograms returns a map pointing at the histograms.

func (*Timings) Label Uses

func (t *Timings) Label() string

Label returns the label name.

func (*Timings) Record Uses

func (t *Timings) Record(name string, startTime time.Time)

Record is a convenience function that records completion timing data based on the provided start time of an event.

func (*Timings) String Uses

func (t *Timings) String() string

String is for expvar.

func (*Timings) Time Uses

func (t *Timings) Time() int64

Time returns the total time elapsed for all values.

type Variable Uses

type Variable interface {
    // Help returns the description of the variable.
    Help() string

    // String must implement String() from the expvar.Var interface.
    String() string
}

Variable is the minimal interface which each type in this "stats" package must implement. When integrating the Vitess stats types ("variables") with the different monitoring systems, you can rely on this interface.

Package stats imports 15 packages (graph) and is imported by 47 packages. Updated 2019-06-13. Refresh now. Tools for package owners.