metric

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Feb 3, 2021 License: BSD-3-Clause Imports: 3 Imported by: 1

Documentation

Overview

Package metric contains data structures for working with metrics.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Meter

type Meter struct {
	// contains filtered or unexported fields
}

Meter is a simple structure for tracking the volume of events observed from two points in time:

  1. When the Meter object was created (or when it was last reset)
  2. From the last snapshot point.

A meter can be updated by adding more observations. Statistics can be periodically extracted from the meter, reflecting the total observed volume as well as the volume in the most recent period.

A meter is not thread-safe. In the absence of locking, it should only be accessed from a single goroutine.

func NewMeter

func NewMeter(name string, snapshotInterval time.Duration) *Meter

NewMeter constructs a new meter object, with a given name and snapshot interval. The actual snapshotting of meter statistics is the responsibility of the goroutine that owns the meter.

func (*Meter) Add

func (m *Meter) Add(amount int64)

Add a value to the meter, contributing to the overall count and to the current interval.

func (*Meter) MaybeStats

func (m *Meter) MaybeStats() *MeterStats

MaybeStats conditionally returns a stats snapshot if the current sampling interval has lapsed. Otherwise, if the sampling interval is still valid, a nil is returned.

func (*Meter) MaybeStatsCall

func (m *Meter) MaybeStatsCall(cb MeterStatsCallback) bool

MaybeStatsCall conditionally invokes the given MeterStatsCallback if the current sampling interval has lapsed, returning true if the callback was invoked.

func (*Meter) MaybeStatsLog

func (m *Meter) MaybeStatsLog(logger scribe.Logger) bool

MaybeStatsLog conditionally logs the snapshot of the recent sampling interval if the latter has lapsed, returning true if an entry was logged.

func (*Meter) Reset

func (m *Meter) Reset()

Reset the meter to its initial state — clearing all counters and resetting the clocks.

func (Meter) String

func (m Meter) String() string

String produces a textual representation of a Meter object.

type MeterStats

type MeterStats struct {
	Name             string
	Start            time.Time
	TotalCount       int64
	TotalRatePerS    float64
	IntervalCount    int64
	IntervalRatePerS float64
}

MeterStats is an immutable snapshot of meter statistics.

func (MeterStats) String

func (s MeterStats) String() string

String produces a textual representation of a MeterStats object.

type MeterStatsCallback

type MeterStatsCallback func(stats MeterStats)

MeterStatsCallback is invoked by MaybeStatsCall().

Jump to

Keyboard shortcuts

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