Documentation ¶
Overview ¶
Package counter provides simple and rate counters and tracked datapoints
Index ¶
- Variables
- func NewRunner() (run *runner)
- type Averager
- type CachedCounters
- func (c *CachedCounters) CounterValues(counterID parl.CounterID) (counterValues parl.CounterValues)
- func (c *CachedCounters) DataPoint(counterID parl.CounterID) (datapointValue parl.DatapointValue)
- func (c *CachedCounters) RateCounter(counterID parl.CounterID) (rateCounterValues parl.RateCounterValues)
- type Counter
- type CounterConsumer
- type Counters
- func (cs *Counters) DatapointMax(name parl.CounterID) (datapointMax uint64)
- func (cs *Counters) DatapointMin(name parl.CounterID) (datapointMin uint64)
- func (cs *Counters) DatapointValue(name parl.CounterID) (datapointValue uint64)
- func (cs *Counters) Exists(name parl.CounterID) (exists bool)
- func (cs *Counters) Get(name parl.CounterID) (value, running, max uint64)
- func (cs *Counters) GetCounter(name parl.CounterID) (counter parl.Counter)
- func (cs *Counters) GetCounters() (list []parl.CounterID, m map[parl.CounterID]any)
- func (cs *Counters) GetDatapoint(name parl.CounterID) (value, max, min uint64, isValid bool, average float64, n uint64)
- func (cs *Counters) GetNamedCounter(name parl.CounterID) (counter any)
- func (cs *Counters) GetOrCreateCounter(name parl.CounterID, period ...time.Duration) (counter parl.Counter)
- func (cs *Counters) GetOrCreateDatapoint(name parl.CounterID, period time.Duration) (datapoint parl.Datapoint)
- func (cs *Counters) Rates(name parl.CounterID) (rates map[parl.RateType]float64)
- func (cs *Counters) ResetCounters(stopRateCounters bool)
- func (cs *Counters) Value(name parl.CounterID) (value uint64)
- type Datapoint
- func (dt *Datapoint) CloneDatapoint() (datapoint parl.Datapoint)
- func (dt *Datapoint) CloneDatapointReset() (datapoint parl.Datapoint)
- func (dt *Datapoint) DatapointMax() (max uint64)
- func (dt *Datapoint) DatapointMin() (min uint64)
- func (dt *Datapoint) DatapointValue() (value uint64)
- func (dt *Datapoint) GetDatapoint() (value, max, min uint64, isValid bool, average float64, n uint64)
- func (dt *Datapoint) SetValue(value uint64) (datapoint parl.Datapoint)
- type Rate
- type RateCounter
- type RateRunner
- type RateRunnerTask
- type RateType
Constants ¶
This section is empty.
Variables ¶
var CountersFactory parl.CountersFactory = &countersFactory{}
Functions ¶
Types ¶
type Averager ¶
type Averager struct {
// contains filtered or unexported fields
}
Averager is a fixed-sized 64-bit container returning float64 averages per time
func NewAverager ¶ added in v0.4.101
NewAverager returns an 64-bit averager over size values
type CachedCounters ¶ added in v0.4.100
type CachedCounters struct {
// contains filtered or unexported fields
}
CachedCounters reduces counter map contention by only looking up the counterID once
func NewCachedCounters ¶ added in v0.4.100
func NewCachedCounters(counterStore parl.CounterStore) (cachedCounters *CachedCounters)
NewCachedCounters returns a cache of parl.CounterID reducing map contention
func (*CachedCounters) CounterValues ¶ added in v0.4.100
func (c *CachedCounters) CounterValues(counterID parl.CounterID) (counterValues parl.CounterValues)
CounterValues never returns nil
- returns consumer interface for regular counter: Get and Value methods
func (*CachedCounters) DataPoint ¶ added in v0.4.100
func (c *CachedCounters) DataPoint(counterID parl.CounterID) (datapointValue parl.DatapointValue)
RateCounter may return nil
- returns consumer interface for rate counter: Get Value Rates methods
func (*CachedCounters) RateCounter ¶ added in v0.4.100
func (c *CachedCounters) RateCounter(counterID parl.CounterID) (rateCounterValues parl.RateCounterValues)
RateCounter may return nil
- returns consumer interface for rate counter: Get Value Rates methods
type Counter ¶
type Counter struct {
CounterConsumer
}
Counter is a counter without rate information. Thread-safe.
- provider methods: Inc Dec Add
- consumer methods: Get GetReset Value Running Max
- initialization-free
func (*Counter) Consumer ¶ added in v0.4.100
func (c *Counter) Consumer() (consumer parl.CounterValues)
Consumer return the read-only consumer interface for this counter
type CounterConsumer ¶ added in v0.4.100
type CounterConsumer struct {
// contains filtered or unexported fields
}
CounterConsumer is accessible value/running/max values
func (*CounterConsumer) Get ¶ added in v0.4.100
func (c *CounterConsumer) Get() (value, running, max uint64)
Get returns value/running/max with integrity. Thread-Safe
- value is the monotonically increasing value
- running is the fluctuating running value
- max is the highest value running has had
func (*CounterConsumer) GetReset ¶ added in v0.4.100
func (c *CounterConsumer) GetReset() (value, running, max uint64)
GetReset returns value/running/max with integrity and resets the counter. Thread-Safe
- value is the monotonically increasing value
- running is the fluctuating running value
- max is the highest value running has had
func (*CounterConsumer) Max ¶ added in v0.4.100
func (c *CounterConsumer) Max() (max uint64)
Max returns the highest value running has had
func (*CounterConsumer) Running ¶ added in v0.4.100
func (c *CounterConsumer) Running() (running uint64)
Running returns the fluctuating running value
- number of Inc less Dec invocations and sum of Adds
- never below 0
func (*CounterConsumer) Value ¶ added in v0.4.100
func (c *CounterConsumer) Value() (value uint64)
Value returns the monotonically increasing value
- number of Inc invocations and positive Adds
type Counters ¶
type Counters struct { RateRunner // contains filtered or unexported fields }
Counters is a container for counters, rate-counters and datapoints. Thread-Safe.
- a counter is Inc-Dec with: value running max
- a rate-counter is a counter with addtional measuring over short time periods:
- — value: rate of increase: current/max/average
- — running: rate up or down, max increase/decrease rate,
func (*Counters) DatapointMax ¶ added in v0.4.41
func (*Counters) DatapointMin ¶ added in v0.4.41
func (*Counters) DatapointValue ¶ added in v0.4.41
func (*Counters) GetCounter ¶ added in v0.4.100
func (*Counters) GetCounters ¶
func (*Counters) GetDatapoint ¶ added in v0.4.41
func (*Counters) GetNamedCounter ¶ added in v0.4.100
func (*Counters) GetOrCreateCounter ¶
func (*Counters) GetOrCreateDatapoint ¶
func (*Counters) ResetCounters ¶
type Datapoint ¶
type Datapoint struct {
// contains filtered or unexported fields
}
Datapoint tracks a fluctuating value with average. Thread-safe.
func (*Datapoint) CloneDatapoint ¶
func (*Datapoint) CloneDatapointReset ¶
func (*Datapoint) DatapointMax ¶
func (*Datapoint) DatapointMin ¶
func (*Datapoint) DatapointValue ¶
func (*Datapoint) GetDatapoint ¶
type RateCounter ¶
type RateCounter struct { Counter // value-running-max atomic-access container // contains filtered or unexported fields }
RateCounter is a value/running/max counter with averaging.
- rate of increase, maximum and average rate of increase in value
- rate of increase, maximum increase and decrease rates and average of value
func (*RateCounter) Do ¶
func (r *RateCounter) Do(at time.Time)
Do completes rate-calculations for a period
- Do is invoked by the task container
- at is an accurate timestamp, ie. not from a time.Interval
type RateRunner ¶
type RateRunner struct {
// contains filtered or unexported fields
}
RateRunner is a container managing threads executing rate-counter tasks by their period
func NewRateRunner ¶
func NewRateRunner(g0 parl.GoGen) (rr *RateRunner)
NewRateRunner returns a thread-container for running rate-counter averaging
func (*RateRunner) AddTask ¶
func (rr *RateRunner) AddTask(period time.Duration, task RateRunnerTask)
AddTask adds a new rate-counter to the container
type RateRunnerTask ¶
type RateRunnerTask interface {
Do(at time.Time) // Do executes averaging for an accurate timestamp
}
RateRunnerTask describes a rate counter