Documentation ¶
Overview ¶
Package metrics provides convenient facilities to record on-line high-level performance metrics.
Index ¶
Constants ¶
const Period = time.Minute
Period is the size of a RotatingLatency bucket. Each RotatingLatency will rotate once per Period.
Variables ¶
This section is empty.
Functions ¶
func PublishLatency ¶
func PublishLatency(key string, rl *RotatingLatency)
PublishLatency publishes rl as an expvar inside the global latency map (which is itself published under the key "latency").
Types ¶
type Latency ¶
type Latency struct {
// contains filtered or unexported fields
}
A Latency records information about the aggregate latency of an operation over time. Internally it holds an HDR histogram (to three significant figures) and a counter of attempts to record a value greater than the histogram's max.
func NewLatency ¶
NewLatency returns a new latency histogram with the given duration limit and with three significant figures of precision.
type RotatingLatency ¶
type RotatingLatency struct {
// contains filtered or unexported fields
}
A RotatingLatency holds a rotating circular buffer of Latency objects, that rotates once per Period time. It can be used as an expvar Val. Its exported methods are safe to call concurrently.
func NewRotatingLatency ¶
func NewRotatingLatency(n int, max time.Duration) *RotatingLatency
NewRotatingLatency returns a new rotating latency recorder with n buckets of history.
func (*RotatingLatency) Record ¶
func (r *RotatingLatency) Record(d time.Duration)
Record attempts to record a duration in the current Latency in r. If d is greater than the max allowed duration, it increments a counter instead.
func (*RotatingLatency) RecordSince ¶
func (r *RotatingLatency) RecordSince(t0 time.Time)
func (*RotatingLatency) String ¶
func (r *RotatingLatency) String() string
String returns r as a JSON string. This makes it suitable for use as an expvar.Val.
Example:
{ "NumRot": 204, "Buckets": [ { "Over": 4, "Histogram": { "LowestTrackableValue": 0, "HighestTrackableValue": 1000000000, "SignificantFigures": 2, "Counts": [2,0,15,...] } }, ... ] }
Note that the last bucket is actively recording values. To collect complete and accurate data over a long time, store the next-to-last bucket after each rotation. The last bucket is only useful for a "live" view with finer granularity than the rotation period (which is one minute).