Documentation ¶
Overview ¶
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 ¶
- func Publish(name string, v expvar.Var)
- func PublishJSONFunc(name string, f func() string)
- func Register(nvh NewVarHook)
- func RegisterPushBackend(name string, backend PushBackend)
- type CountTracker
- type Counters
- type CountersFunc
- type Duration
- type DurationFunc
- type Float
- type FloatFunc
- type Histogram
- func (h *Histogram) Add(value int64)
- func (h *Histogram) Buckets() []int64
- func (h *Histogram) Count() (count int64)
- func (h *Histogram) CountLabel() string
- func (h *Histogram) Counts() map[string]int64
- func (h *Histogram) Labels() []string
- func (h *Histogram) MarshalJSON() ([]byte, error)
- func (h *Histogram) String() string
- func (h *Histogram) Total() (total int64)
- func (h *Histogram) TotalLabel() string
- type Int
- type IntFunc
- type JSONFunc
- type MultiCounters
- type MultiCountersFunc
- type MultiTimings
- type MultiTracker
- type NewVarHook
- type PushBackend
- type Rates
- type RingInt64
- type States
- type String
- type StringFunc
- type StringMap
- type StringMapFunc
- type Timings
- func (t *Timings) Add(name string, elapsed time.Duration)
- func (t *Timings) Count() int64
- func (t *Timings) Counts() map[string]int64
- func (t *Timings) Histograms() (h map[string]*Histogram)
- func (t *Timings) Record(name string, startTime time.Time)
- func (t *Timings) String() string
- func (t *Timings) Time() int64
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func PublishJSONFunc ¶
PublishJSONFunc publishes any function that returns a JSON string as a variable. The string is sent to expvar as is.
func Register ¶
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 ¶
func RegisterPushBackend(name string, backend PushBackend)
RegisterPushBackend allows modules to register PushBackend implementations. Should be called on init().
Types ¶
type CountTracker ¶
CountTracker defines the interface that needs to be supported by a variable for being tracked by Rates.
func CounterForDimension ¶
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 Counters ¶
type Counters struct {
// contains filtered or unexported fields
}
Counters is similar to expvar.Map, except that it doesn't allow floats. In addition, it provides a Counts method which can be used for tracking rates.
func NewCounters ¶
NewCounters create a new Counters instance. If name is set, the variable gets published. The functional also accepts an optional list of tags that pre-creates them initialized to 0.
type CountersFunc ¶
CountersFunc converts a function that returns a map of int64 as an expvar.
func (CountersFunc) Counts ¶
func (f CountersFunc) Counts() map[string]int64
Counts returns a copy of the Counters' map.
type Duration ¶
type Duration struct {
// contains filtered or unexported fields
}
Duration exports a time.Duration
type DurationFunc ¶
DurationFunc converts a function that returns an time.Duration as an expvar.
func (DurationFunc) String ¶
func (f DurationFunc) String() string
String is the implementation of expvar.var
type Float ¶
type Float struct {
// contains filtered or unexported fields
}
Float is expvar.Float+Get+hook
type FloatFunc ¶
type FloatFunc func() float64
FloatFunc converts a function that returns a float64 as an expvar.
type Histogram ¶
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 ¶
func NewGenericHistogram(name 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 ¶
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) CountLabel ¶
func (*Histogram) MarshalJSON ¶
func (*Histogram) TotalLabel ¶
type IntFunc ¶
type IntFunc func() int64
IntFunc converts a function that returns an int64 as an expvar.
type JSONFunc ¶
type JSONFunc func() string
JSONFunc is the public type for a single function that returns json directly.
type MultiCounters ¶
type MultiCounters struct { Counters // contains filtered or unexported fields }
MultiCounters is a multidimensional Counters implementation where names of categories are compound names made with joining multiple strings with '.'.
func NewMultiCounters ¶
func NewMultiCounters(name string, labels []string) *MultiCounters
NewMultiCounters creates a new MultiCounters instance, and publishes it if name is set.
func (*MultiCounters) Add ¶
func (mc *MultiCounters) Add(names []string, value int64)
Add adds a value to a named counter. len(names) must be equal to len(Labels)
func (*MultiCounters) Labels ¶
func (mc *MultiCounters) Labels() []string
Labels returns the list of labels.
func (*MultiCounters) Set ¶
func (mc *MultiCounters) Set(names []string, value int64)
Set sets the value of a named counter. len(names) must be equal to len(Labels)
type MultiCountersFunc ¶
type MultiCountersFunc struct { CountersFunc // contains filtered or unexported fields }
MultiCountersFunc is a multidimensional CountersFunc 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 rigth format (meaning each key is of the form 'aaa.bbb.ccc' with as many elements as there are in Labels).
func NewMultiCountersFunc ¶
func NewMultiCountersFunc(name string, labels []string, f CountersFunc) *MultiCountersFunc
NewMultiCountersFunc creates a new MultiCountersFunc mapping to the provided function.
func (*MultiCountersFunc) Labels ¶
func (mcf *MultiCountersFunc) Labels() []string
Labels returns the list of labels.
type MultiTimings ¶
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 ¶
func NewMultiTimings(name string, labels []string) *MultiTimings
NewMultiTimings creates a new MultiTimings object.
func (*MultiTimings) Add ¶
func (mt *MultiTimings) Add(names []string, elapsed time.Duration)
Add will add a new value to the named histogram.
func (*MultiTimings) Labels ¶
func (mt *MultiTimings) Labels() []string
Labels returns descriptions of the parts of each compound category name.
type MultiTracker ¶
type MultiTracker interface { CountTracker Labels() []string }
MultiTracker is a CountTracker that tracks counts grouping them by more than one dimension.
type NewVarHook ¶
NewVarHook is the type of a hook to export variables in a different way
type PushBackend ¶
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 ¶
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.
type RingInt64 ¶
type RingInt64 struct {
// contains filtered or unexported fields
}
Ring of int64 values Not thread safe
func NewRingInt64 ¶
type States ¶
type States struct {
// contains filtered or unexported fields
}
The States structure keeps historical data about a state machine state, and exports them using expvar: - our current state - how long we have been in each state - how many times we transitioned into a state (not counting initial state)
type String ¶
type String struct {
// contains filtered or unexported fields
}
String is expvar.String+Get+hook
type StringFunc ¶
type StringFunc func() string
StringFunc converts a function that returns an string as an expvar.
func (StringFunc) String ¶
func (f StringFunc) String() string
String is the implementation of expvar.var
type StringMap ¶
type StringMap struct {
// contains filtered or unexported fields
}
StringMap is a map of string -> string
type StringMapFunc ¶
StringMapFunc is the function equivalent of StringMap
type Timings ¶
type Timings struct {
// contains filtered or unexported fields
}
Timings is meant to tracks timing data by named categories as well as histograms.
func NewTimings ¶
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) Histograms ¶
Histograms returns a map pointing at the histograms.
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
Package influxdbbackend is useful for publishing metrics to an InfluxDB backend (tested on v0.88).
|
Package influxdbbackend is useful for publishing metrics to an InfluxDB backend (tested on v0.88). |