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)
- 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) Count() (count int64)
- func (h *Histogram) CountLabel() string
- func (h *Histogram) Counts() map[string]int64
- 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 Matrix
- type MatrixFunc
- type MatrixType
- type NewVarHook
- type Rates
- type RingInt64
- type States
- type String
- type StringFunc
- 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.
Types ¶
type CountTracker ¶
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 ¶
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
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 ¶
type DurationFunc ¶
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
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 "Max".
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 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.
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) LabelX ¶
func (m *MatrixFunc) LabelX() string
func (*MatrixFunc) LabelY ¶
func (m *MatrixFunc) LabelY() string
func (*MatrixFunc) String ¶
func (m *MatrixFunc) String() string
type MatrixType ¶
MatrixType provides a common interface for Matrix and MatrixFunc.
type NewVarHook ¶
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
type Timings ¶
type Timings struct {
// contains filtered or unexported fields
}
Timings is meant to tracks timing data by named categories as well as histograms.