metrics API

metrics

package

API reference for the metrics package.

I
interface

Counter

Counter tracks a monotonically increasing integer value.

pkg/metrics/metrics.go:10-14
type Counter interface

Methods

Inc
Method
func Inc(...)
Add
Method

Parameters

int64
func Add(...)
Value
Method

Returns

int64
func Value(...)
I
interface

Gauge

Gauge tracks a float64 value that can go up and down.

pkg/metrics/metrics.go:17-24
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

Histogram records observed float64 values in buckets.

pkg/metrics/metrics.go:27-29
type Histogram interface

Methods

Observe
Method

Parameters

float64
func Observe(...)
I
interface

Timer

Timer measures elapsed time for an operation.

pkg/metrics/metrics.go:32-35
type Timer interface

Methods

Start
Method

Returns

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

Timing

Timing holds a start time for measuring duration.

pkg/metrics/metrics.go:38-40
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

SimpleCounter is a mutex-protected Counter implementation.

pkg/metrics/metrics.go:47-50
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

NewCounter creates a new SimpleCounter.

Returns

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

{ return &SimpleCounter{} }
S
struct

SimpleGauge

SimpleGauge is a mutex-protected Gauge implementation.

pkg/metrics/metrics.go:67-70
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

NewGauge creates a new SimpleGauge.

Returns

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

{ return &SimpleGauge{} }
S
struct

SimpleHistogram

SimpleHistogram is a mutex-protected Histogram implementation.

pkg/metrics/metrics.go:98-104
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

NewHistogram creates a new SimpleHistogram with the given bucket boundaries.

Parameters

buckets
[]float64

Returns

pkg/metrics/metrics.go:107-114
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
Implements: Timer

SimpleTimer

SimpleTimer is a basic Timer implementation.

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

Methods

Start
Method

Returns

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

NewTimer

NewTimer creates a new SimpleTimer.

Returns

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

{ return &SimpleTimer{} }