metrics API

metrics

package

API reference for the metrics package.

I
interface

Counter

pkg/metrics/metrics.go:9-13
type Counter interface

Methods

Inc
Method
func Inc(...)
Add
Method

Parameters

int64
func Add(...)
Value
Method

Returns

int64
func Value(...)
I
interface

Gauge

pkg/metrics/metrics.go:15-22
type Gauge interface

Methods

Set
Method

Parameters

float64
func Set(...)
Inc
Method
func Inc(...)
Dec
Method
func Dec(...)
Add
Method

Parameters

float64
func Add(...)
Sub
Method

Parameters

float64
func Sub(...)
Value
Method

Returns

float64
func Value(...)
I
interface

Histogram

pkg/metrics/metrics.go:24-26
type Histogram interface

Methods

Observe
Method

Parameters

float64
func Observe(...)
I
interface

Timer

pkg/metrics/metrics.go:28-31
type Timer interface

Methods

Start
Method

Returns

func Start(...)
func ObserveDuration(...)
S
struct

Timing

pkg/metrics/metrics.go:33-35
type Timing struct

Methods

Stop
Method

Returns

func (*Timing) Stop() time.Duration
{
	return time.Since(t.start)
}

Fields

Name Type Description
start time.Time
S
struct

SimpleCounter

pkg/metrics/metrics.go:41-44
type SimpleCounter struct

Methods

Inc
Method
func (*SimpleCounter) Inc()
{ c.Add(1) }
Add
Method

Parameters

n int64
func (*SimpleCounter) Add(n int64)
{
	c.mu.Lock()
	defer c.mu.Unlock()
	c.v += n
}
Value
Method

Returns

int64
func (*SimpleCounter) Value() int64
{
	c.mu.Lock()
	defer c.mu.Unlock()
	return c.v
}

Fields

Name Type Description
mu sync.Mutex
v int64
F
function

NewCounter

Returns

pkg/metrics/metrics.go:46-46
func NewCounter() *SimpleCounter

{ return &SimpleCounter{} }
S
struct

SimpleGauge

pkg/metrics/metrics.go:59-62
type SimpleGauge struct

Methods

Set
Method

Parameters

v float64
func (*SimpleGauge) Set(v float64)
{
	g.mu.Lock()
	defer g.mu.Unlock()
	g.v = v
}
Inc
Method
func (*SimpleGauge) Inc()
{ g.Add(1) }
Dec
Method
func (*SimpleGauge) Dec()
{ g.Sub(1) }
Add
Method

Parameters

v float64
func (*SimpleGauge) Add(v float64)
{
	g.mu.Lock()
	defer g.mu.Unlock()
	g.v += v
}
Sub
Method

Parameters

v float64
func (*SimpleGauge) Sub(v float64)
{
	g.mu.Lock()
	defer g.mu.Unlock()
	g.v -= v
}
Value
Method

Returns

float64
func (*SimpleGauge) Value() float64
{
	g.mu.Lock()
	defer g.mu.Unlock()
	return g.v
}

Fields

Name Type Description
mu sync.Mutex
v float64
F
function

NewGauge

Returns

pkg/metrics/metrics.go:64-64
func NewGauge() *SimpleGauge

{ return &SimpleGauge{} }
S
struct

SimpleHistogram

pkg/metrics/metrics.go:88-94
type SimpleHistogram struct

Methods

Observe
Method

Parameters

v float64
func (*SimpleHistogram) Observe(v float64)
{
	h.mu.Lock()
	defer h.mu.Unlock()
	h.total++
	h.sum += v
	for i, b := range h.buckets {
		if v <= b {
			h.counts[i]++
			return
		}
	}
	h.counts[len(h.counts)-1]++
}

Fields

Name Type Description
mu sync.Mutex
buckets []float64
counts []int64
total int64
sum float64
F
function

NewHistogram

Parameters

buckets
[]float64

Returns

pkg/metrics/metrics.go:96-103
func NewHistogram(buckets []float64) *SimpleHistogram

{
	sorted := append([]float64(nil), buckets...)
	sort.Float64s(sorted)
	return &SimpleHistogram{
		buckets: sorted,
		counts:  make([]int64, len(sorted)+1),
	}
}
S
struct

SimpleTimer

pkg/metrics/metrics.go:119-119
type SimpleTimer struct

Methods

Start
Method

Returns

func (*SimpleTimer) Start() *Timing
{
	return &Timing{start: time.Now()}
}
F
function

NewTimer

Returns

pkg/metrics/metrics.go:121-121
func NewTimer() *SimpleTimer

{ return &SimpleTimer{} }