stat

package
v2.5.0 Latest Latest
Warning

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

Go to latest
Published: Feb 25, 2021 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// DefStatistics is a base set of statistics used by package-level calls
	// When using multiple statistics, avoid using overlapping event names
	DefStatistics = NewStatistics()
)

Functions

func Bind

func Bind(eventName string, inc int) event.Bindable

Bind returns a binding that will increment the given event by 'inc'

func Inc

func Inc(eventName string)

Inc triggers an event, incrementing the given statistic by one

func IsTimedStat

func IsTimedStat(s string) bool

IsTimedStat returns whether the given stat name is a part of this statistics' set of timed stats

func TimedBind

func TimedBind(eventName string, on bool) event.Bindable

TimedBind returns a binding that will trigger toggling on or off the given event

func TimedOff

func TimedOff(eventName string) event.Bindable

TimedOff returns a binding that will trigger toggling off the given event

func TimedOn

func TimedOn(eventName string) event.Bindable

TimedOn returns a binding that will trigger toggling on the given event

func TrackStats

func TrackStats(no int, data interface{}) int

TrackStats records a stat event to the Statistics map and creates the statistic if it does not already exist

func TrackTimeStats

func TrackTimeStats(no int, data interface{}) int

TrackTimeStats acts like TrackStats, but tracks durations of events. If the event has not started, it logs a start time, and then when the event ends it will log the delta since the start.

func Trigger

func Trigger(eventName string, inc int)

Trigger triggers the given event with a given increment to update a statistic

func TriggerOff

func TriggerOff(eventName string)

TriggerOff triggers the given event, toggling it off

func TriggerOn

func TriggerOn(eventName string)

TriggerOn triggers the given event, toggling it on

func TriggerTimed

func TriggerTimed(eventName string, on bool)

TriggerTimed triggers the given event, toggling it on or off

Types

type Event

type Event struct {
	Timestamp time.Time
	Val       int
}

An Event ties a value to a timestamp

type History

type History struct {
	Name   string
	Events []Event
}

A History keeps track of any recorded occurrences of this statstic and their magnitude

func NewHistory

func NewHistory(statName string, time time.Time) *History

NewHistory creates a stat

func (*History) Total

func (h *History) Total() int

Total takes a statistics history and finds the sum.

type Statistics

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

Statistics stores the ongoing results of TrackStats and TrackTimeStats

func NewStatistics

func NewStatistics() *Statistics

NewStatistics creates an empty statistics set

func (*Statistics) Inc

func (st *Statistics) Inc(eventName string)

Inc triggers an event, incrementing the given statistic by one

func (*Statistics) IsTimedStat

func (st *Statistics) IsTimedStat(s string) bool

IsTimedStat returns whether the given stat name is a part of this statistics' set of timed stats

func (*Statistics) TrackStats

func (st *Statistics) TrackStats(no int, data interface{}) int

TrackStats records a stat event to the Statistics map and creates the statistic if it does not already exist

func (*Statistics) TrackTimeStats

func (st *Statistics) TrackTimeStats(no int, data interface{}) int

TrackTimeStats acts like TrackStats, but tracks durations of events. If the event has not started, it logs a start time, and then when the event ends it will log the delta since the start.

func (*Statistics) Trigger

func (st *Statistics) Trigger(eventName string, inc int)

Trigger triggers the given event with a given increment to update a statistic

func (*Statistics) TriggerOff

func (st *Statistics) TriggerOff(eventName string)

TriggerOff triggers the given event, toggling it off

func (*Statistics) TriggerOn

func (st *Statistics) TriggerOn(eventName string)

TriggerOn triggers the given event, toggling it on

func (*Statistics) TriggerTimed

func (st *Statistics) TriggerTimed(eventName string, on bool)

TriggerTimed triggers the given event, toggling it on or off

Jump to

Keyboard shortcuts

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