stats

package
v0.0.0-...-ee0e00b Latest Latest
Warning

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

Go to latest
Published: Mar 16, 2023 License: Apache-2.0 Imports: 10 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	GLOBAL_STATS     Stats     = nil
	GLOBAL_REPORTING Reporting = nil
)

Global stats and reporting instances.

Functions

func Init

func Init(stats Stats, reporting Reporting) error

Init initializes the global stats and reporting instances.

func InitDefault

func InitDefault() error

InitDefault initializes the global stats and reporting instances with a DefaultStatsAndReporting instance.

Types

type Bucket

type Bucket struct {
	Count    uint64
	Bytes    uint64
	Interval time.Duration
}

func Diff

func Diff(a, b *Bucket) *Bucket

type Context

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

Context is a Stats implementation that adds a prefix to all events.

func (*Context) Log

func (ctx *Context) Log(event string)

Log records an event.

func (*Context) LogBytes

func (ctx *Context) LogBytes(event string, bytes uint64)

func (*Context) LogInterval

func (ctx *Context) LogInterval(event string, interval time.Duration)

Log records an event.

func (*Context) Logger

func (ctx *Context) Logger() *zap.SugaredLogger

Logger returns a logger that adds a prefix to all events.

func (*Context) Name

func (ctx *Context) Name() string

Name returns the name of this Stats instance.

func (*Context) WithContext

func (ctx *Context) WithContext(name string) Stats

WithContext returns a new Stats instance that adds a prefix to all events.

type DefaultStatsAndReporting

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

DefaultStatsAndReporting is a Stats and Reporting implementation that records events in memory.

func NewDefaultStatsAndReporting

func NewDefaultStatsAndReporting() *DefaultStatsAndReporting

NewDefaultStatsAndReporting returns a new DefaultStatsAndReporting instance.

func (*DefaultStatsAndReporting) Count

func (ds *DefaultStatsAndReporting) Count(event string) uint64

Count returns the number of times the given event has been recorded.

func (*DefaultStatsAndReporting) Log

func (ds *DefaultStatsAndReporting) Log(event string)

Log records an event.

func (*DefaultStatsAndReporting) LogBytes

func (ds *DefaultStatsAndReporting) LogBytes(event string, bytes uint64)

func (*DefaultStatsAndReporting) LogInterval

func (ds *DefaultStatsAndReporting) LogInterval(event string, interval time.Duration)

func (*DefaultStatsAndReporting) Logger

Logger returns a logger that adds a prefix to all events.

func (*DefaultStatsAndReporting) Name

func (ds *DefaultStatsAndReporting) Name() string

Name returns the name of this DefaultStatsAndReporting instance.

func (*DefaultStatsAndReporting) Snapshot

func (ds *DefaultStatsAndReporting) Snapshot() *Snapshot

Snapshot returns a snapshot of the current DefaultStatsAndReporting instance.

func (*DefaultStatsAndReporting) WithContext

func (ds *DefaultStatsAndReporting) WithContext(name string) Stats

WithContext returns a new Context instance that adds a prefix to all events.

type Reporting

type Reporting interface {
	Count(string) uint64
	Snapshot() *Snapshot
}

Reporting is an interface for reporting stats.

type Snapshot

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

Snapshot is a snapshot of a Stats instance.

func (*Snapshot) Bytes

func (snap *Snapshot) Bytes(event string) uint64

func (*Snapshot) Count

func (snap *Snapshot) Count(event string) uint64

Count returns the number of times the given event has been recorded.

func (*Snapshot) Diff

func (snap *Snapshot) Diff(other *Snapshot) *Snapshot

Diff returns a new Snapshot that contains the difference between this Snapshot and the given Snapshot.

func (*Snapshot) Filter

func (snap *Snapshot) Filter(prefix string) *Snapshot

Filter returns a new Snapshot that contains only the events that match the given prefix.

func (*Snapshot) Interval

func (snap *Snapshot) Interval(event string) time.Duration

func (*Snapshot) Keys

func (snap *Snapshot) Keys() []string

Keys returns a sorted list of all events that have been recorded.

func (*Snapshot) MarshalJSON

func (snap *Snapshot) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface.

func (*Snapshot) Write

func (snap *Snapshot) Write(log *zap.SugaredLogger)

Write writes the snapshot to the given logger.

type Stats

type Stats interface {
	// Log records an event.
	Log(string)
	// LogInterval records an interval in nanoseconds.
	LogInterval(string, time.Duration)
	// LogBytes records an amount in bytes.
	LogBytes(string, uint64)
	// WithContext returns a new Stats instance that adds a prefix to all events.
	WithContext(string) Stats
	// Logger returns a logger that adds a prefix to all events.
	Logger() *zap.SugaredLogger
	// Name returns the name of this Stats instance.
	Name() string
}

Stats is an interface for recording events.

Jump to

Keyboard shortcuts

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