metrics

package
v0.0.0-...-4e0ae02 Latest Latest
Warning

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

Go to latest
Published: Nov 29, 2016 License: AGPL-3.0 Imports: 7 Imported by: 0

Documentation

Overview

Package metrics provides convenient facilities to record on-line high-level performance metrics.

Index

Constants

View Source
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

func NewLatency(limit time.Duration) *Latency

NewLatency returns a new latency histogram with the given duration limit and with three significant figures of precision.

func (*Latency) Record

func (l *Latency) Record(d time.Duration)

Record attempts to record a duration in the histogram. If d is greater than the max allowed duration, it increments a counter instead.

func (*Latency) Reset

func (l *Latency) Reset()

Reset resets l to is original empty state.

func (*Latency) String

func (l *Latency) String() string

String returns l as a JSON string. This makes it suitable for use as an expvar.Val.

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).

Jump to

Keyboard shortcuts

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