stats

package
v0.1.5 Latest Latest
Warning

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

Go to latest
Published: Jul 6, 2021 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddFlags

func AddFlags()

AddFlags adds configuration flags for the global stats object

func AddToValue

func AddToValue(key string, value float64)

AddToValue adds to the value associated with the global key

func AreLogged

func AreLogged() bool

AreLogged returns whether global stats are getting logged

func Clear

func Clear()

Clear will empty out the global stats, all counters are set to 0, all values set to 0

func GetCounter

func GetCounter(key string) int64

GetCounter returns the global count associated with the key

func GetValue

func GetValue(key string) float64

GetValue returns the global value associated with the key

func IncrementCounter

func IncrementCounter(key string)

IncrementCounter increments the global counter associated with the key by 1

func IncrementCounterBy

func IncrementCounterBy(key string, value int64)

IncrementCounterBy increments the global counter associated with the key by the given value

func TrackTime

func TrackTime(key string, start time.Time, unit time.Duration)

TrackTime will track how much time was elapsed from start time, and add that value (in given unit) to the global value associated with the key should be used like this

func Something() {
  defer stats.TrackTime(key, time.Now(), time.Second)
  .. do some operation
}

func Write

func Write() error

Write will write all global stats to stderr and/or a file. configured through stats.OutputFile and stats.sLogToStderr

func WriteAndLogError

func WriteAndLogError()

WriteAndLogError is just a wrapper around Write which also logs the error to stderr if it occurs

Types

type Stats

type Stats struct {
	OutputFile  string
	LogToStderr bool
	// contains filtered or unexported fields
}

Stats encapsulates functionallity of incrementing counters and incrementing values

func New

func New() *Stats

New creates new Stats object

func (*Stats) AddFlags

func (s *Stats) AddFlags()

AddFlags adds configuration flags for a stats object

func (*Stats) AddToValue

func (s *Stats) AddToValue(key string, value float64)

AddToValue adds to the value associated with the key

func (*Stats) AreLogged

func (s *Stats) AreLogged() bool

AreLogged returns whether this stats object is getting logged can be used to determine whether to keep adding stuff to it or not if it's not being logged, one shouldn't even increment counters

func (*Stats) Clear

func (s *Stats) Clear()

Clear will empty out the stats, all counters are set to 0, all values set to 0

func (*Stats) GetCounter

func (s *Stats) GetCounter(key string) int64

GetCounter returns the count associated with the key

func (*Stats) GetValue

func (s *Stats) GetValue(key string) float64

GetValue returns the value associated with the key

func (*Stats) IncrementCounter

func (s *Stats) IncrementCounter(key string)

IncrementCounter increments the counter associated with the key by 1

func (*Stats) IncrementCounterBy

func (s *Stats) IncrementCounterBy(key string, value int64)

IncrementCounterBy increments the counter associated with the key by the given value

func (*Stats) TrackTime

func (s *Stats) TrackTime(key string, start time.Time, unit time.Duration)

TrackTime will track how much time was elapsed from start time, and add that value (in given unit) to the value associated with the key should be used like this

func Something() {
  defer stats.TrackTime(key, time.Now(), time.Second)
  .. do some operation
}

func (*Stats) Write

func (s *Stats) Write() error

Write will write all stats to stderr and/or a file. configured through stats.OutputFile and stats.sLogToStderr

func (*Stats) WriteAndLogError

func (s *Stats) WriteAndLogError()

WriteAndLogError is just a wrapper around Write which also logs the error to stderr if it occurs

Jump to

Keyboard shortcuts

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