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:
- When the Meter object was created (or when it was last reset)
- 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 ¶
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 ¶
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 ¶
MaybeStatsLog conditionally logs the snapshot of the recent sampling interval if the latter has lapsed, returning true if an entry was logged.
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().