counter

package
v0.4.171 Latest Latest
Warning

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

Go to latest
Published: May 12, 2024 License: ISC Imports: 10 Imported by: 1

Documentation

Overview

Package counter provides simple and rate counters and tracked datapoints

Index

Constants

This section is empty.

Variables

View Source
var CountersFactory parl.CountersFactory = &countersFactory{}

Functions

func NewRunner

func NewRunner() (run *runner)

runner returns a container for rate-counters of a particular interval

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

func NewAverager(size int) (averager *Averager)

NewAverager returns an 64-bit averager over size values

func (*Averager) Add

func (av *Averager) Add(value uint64, duration time.Duration) (average float64)

Add adds a new value and computes current average

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) Add

func (c *Counter) Add(delta int64) (counter parl.Counter)

Add adds a positive or negative delta. Thread-Safe, method chaining

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

func (*Counter) Dec

func (c *Counter) Dec() (counter parl.Counter)

Dec decrements the counter but not below zero. Thread-Safe, method chaining

func (*Counter) Inc

func (c *Counter) Inc() (counter parl.Counter)

Inc increments the counter. Thread-Safe, method chaining

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 (cs *Counters) DatapointMax(name parl.CounterID) (datapointMax uint64)

func (*Counters) DatapointMin added in v0.4.41

func (cs *Counters) DatapointMin(name parl.CounterID) (datapointMin uint64)

func (*Counters) DatapointValue added in v0.4.41

func (cs *Counters) DatapointValue(name parl.CounterID) (datapointValue uint64)

func (*Counters) Exists added in v0.4.41

func (cs *Counters) Exists(name parl.CounterID) (exists bool)

func (*Counters) Get added in v0.4.47

func (cs *Counters) Get(name parl.CounterID) (value, running, max uint64)

func (*Counters) GetCounter added in v0.4.100

func (cs *Counters) GetCounter(name parl.CounterID) (counter parl.Counter)

func (*Counters) GetCounters

func (cs *Counters) GetCounters() (list []parl.CounterID, m map[parl.CounterID]any)

func (*Counters) GetDatapoint added in v0.4.41

func (cs *Counters) GetDatapoint(name parl.CounterID) (value, max, min uint64, isValid bool, average float64, n uint64)

func (*Counters) GetNamedCounter added in v0.4.100

func (cs *Counters) GetNamedCounter(name parl.CounterID) (counter any)

func (*Counters) GetOrCreateCounter

func (cs *Counters) GetOrCreateCounter(name parl.CounterID, period ...time.Duration) (counter parl.Counter)

func (*Counters) GetOrCreateDatapoint

func (cs *Counters) GetOrCreateDatapoint(name parl.CounterID, period time.Duration) (datapoint parl.Datapoint)

func (*Counters) Rates added in v0.4.41

func (cs *Counters) Rates(name parl.CounterID) (rates map[parl.RateType]float64)

func (*Counters) ResetCounters

func (cs *Counters) ResetCounters(stopRateCounters bool)

func (*Counters) Value added in v0.4.41

func (cs *Counters) Value(name parl.CounterID) (value uint64)

type Datapoint

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

Datapoint tracks a fluctuating value with average. Thread-safe.

func (*Datapoint) CloneDatapoint

func (dt *Datapoint) CloneDatapoint() (datapoint parl.Datapoint)

func (*Datapoint) CloneDatapointReset

func (dt *Datapoint) CloneDatapointReset() (datapoint parl.Datapoint)

func (*Datapoint) DatapointMax

func (dt *Datapoint) DatapointMax() (max uint64)

func (*Datapoint) DatapointMin

func (dt *Datapoint) DatapointMin() (min uint64)

func (*Datapoint) DatapointValue

func (dt *Datapoint) DatapointValue() (value uint64)

func (*Datapoint) GetDatapoint

func (dt *Datapoint) GetDatapoint() (value, max, min uint64, isValid bool, average float64, n uint64)

func (*Datapoint) SetValue

func (dt *Datapoint) SetValue(value uint64) (datapoint parl.Datapoint)

SetValue records a new datapoint value

type Rate

type Rate struct {
	RateType // String()
	// contains filtered or unexported fields
}

func (*Rate) Clone

func (rt *Rate) Clone() (rate parl.Rate)

func (*Rate) Delta

func (rt *Rate) Delta() (delta uint64)

func (*Rate) Duration

func (rt *Rate) Duration() (duration time.Duration)

func (*Rate) HasValue

func (rt *Rate) HasValue() (hasValue bool)

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

func (*RateCounter) Rates

func (r *RateCounter) Rates() (rates map[parl.RateType]float64)

Rates returns a map of current rate-results

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

type RateType

type RateType parl.RateType

func (RateType) String

func (rt RateType) String() (s string)

Jump to

Keyboard shortcuts

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