stats

package
v0.0.0-...-9a5932e Latest Latest
Warning

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

Go to latest
Published: Mar 10, 2014 License: BSD-3-Clause Imports: 8 Imported by: 0

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func Publish

func Publish(name string, v expvar.Var)

Publish is expvar.Publish+hook

func PublishJSONFunc

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

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.

Types

type CountTracker

type CountTracker interface {
	Counts() map[string]int64
}

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

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

func NewCounters(name string) *Counters

func (*Counters) Add

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

func (*Counters) Counts

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

func (*Counters) Set

func (c *Counters) Set(name string, value int64)

func (*Counters) String

func (c *Counters) String() string

type CountersFunc

type CountersFunc func() map[string]int64

CountersFunc converts a function that returns a map of int64 as an expvar.

func (CountersFunc) Counts

func (f CountersFunc) Counts() map[string]int64

func (CountersFunc) String

func (f CountersFunc) String() string

type Duration

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

Duration exports a time.Duration

func NewDuration

func NewDuration(name string) *Duration

func (*Duration) Add

func (v *Duration) Add(delta time.Duration)

func (*Duration) Get

func (v *Duration) Get() time.Duration

func (*Duration) Set

func (v *Duration) Set(value time.Duration)

func (*Duration) String

func (v *Duration) String() string

type DurationFunc

type DurationFunc func() time.Duration

DurationFunc converts a function that returns an time.Duration as an expvar.

func (DurationFunc) String

func (f DurationFunc) String() string

type Float

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

Float is expvar.Float+Get+hook

func NewFloat

func NewFloat(name string) *Float

func (*Float) Add

func (v *Float) Add(delta float64)

func (*Float) Get

func (v *Float) Get() float64

func (*Float) Set

func (v *Float) Set(value float64)

func (*Float) String

func (v *Float) String() string

type FloatFunc

type FloatFunc func() float64

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

func (FloatFunc) String

func (f FloatFunc) String() string

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

func NewHistogram(name 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 "Max".

func (*Histogram) Add

func (h *Histogram) Add(value int64)

func (*Histogram) Count

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

func (*Histogram) CountLabel

func (h *Histogram) CountLabel() string

func (*Histogram) Counts

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

func (*Histogram) MarshalJSON

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

func (*Histogram) String

func (h *Histogram) String() string

func (*Histogram) Total

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

func (*Histogram) TotalLabel

func (h *Histogram) TotalLabel() string

type Int

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

Int is expvar.Int+Get+hook

func NewInt

func NewInt(name string) *Int

func (*Int) Add

func (v *Int) Add(delta int64)

func (*Int) Get

func (v *Int) Get() int64

func (*Int) Set

func (v *Int) Set(value int64)

func (*Int) String

func (v *Int) String() string

type IntFunc

type IntFunc func() int64

IntFunc converts a function that returns an int64 as an expvar.

func (IntFunc) String

func (f IntFunc) String() string

type JsonFunc

type JsonFunc func() string

func (JsonFunc) String

func (f JsonFunc) String() string

type Matrix

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

Matrix provides a two-dimentional map from string.string to int64. It also provides a Data method which can be used for dumping data.

func NewMatrix

func NewMatrix(name, labelX, labelY string) *Matrix

func (*Matrix) Add

func (m *Matrix) Add(name1, name2 string, value int64)

func (*Matrix) Data

func (m *Matrix) Data() map[string]map[string]int64

func (*Matrix) LabelX

func (m *Matrix) LabelX() string

func (*Matrix) LabelY

func (m *Matrix) LabelY() string

func (*Matrix) String

func (m *Matrix) String() string

type MatrixFunc

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

MatrixFunc converts a function that returns a two-dimentional map of int64 as an expvar.

func NewMatrixFunc

func NewMatrixFunc(labelX, labelY string, f func() map[string]map[string]int64) *MatrixFunc

func (*MatrixFunc) Data

func (m *MatrixFunc) Data() map[string]map[string]int64

func (*MatrixFunc) LabelX

func (m *MatrixFunc) LabelX() string

func (*MatrixFunc) LabelY

func (m *MatrixFunc) LabelY() string

func (*MatrixFunc) String

func (m *MatrixFunc) String() string

type MatrixType

type MatrixType interface {
	LabelX() string
	LabelY() string
	Data() map[string]map[string]int64
}

MatrixType provides a common interface for Matrix and MatrixFunc.

type NewVarHook

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

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.

func NewRates

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.

func (*Rates) Get

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

func (*Rates) String

func (rt *Rates) String() string

type RingInt64

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

Ring of int64 values Not thread safe

func NewRingInt64

func NewRingInt64(capacity int) *RingInt64

func (*RingInt64) Add

func (ri *RingInt64) Add(val int64)

func (*RingInt64) Values

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

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)

func NewStates

func NewStates(name string, labels []string, startTime time.Time, initialState int64) *States

NewStates creates a states tracker. If name is empty, the variable is not published.

func (*States) Get

func (s *States) Get() (state int64)

Get returns the current state.

func (*States) SetState

func (s *States) SetState(state int64)

func (*States) String

func (s *States) String() string

type String

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

String is expvar.String+Get+hook

func NewString

func NewString(name string) *String

func (*String) Get

func (v *String) Get() string

func (*String) Set

func (v *String) Set(value string)

func (*String) String

func (v *String) String() string

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

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

func NewTimings(name string) *Timings

func (*Timings) Add

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

func (*Timings) Count

func (t *Timings) Count() int64

func (*Timings) Counts

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

func (*Timings) Histograms

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

func (*Timings) Record

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

func (t *Timings) String() string

func (*Timings) Time

func (t *Timings) Time() int64

Jump to

Keyboard shortcuts

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