stats

package
v1.1.2 Latest Latest
Warning

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

Go to latest
Published: Jan 4, 2022 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidFlushInterval = errors.New("FlushInterval cannot be 0")
	ErrCounterNotFound      = errors.New("counter not found")
	ErrMissingShutdownCtx   = errors.New("ServiceShutdownCtx cannot be nil")
	ErrMissingStorage       = errors.New("ErrMissingStorage cannot be empty")
)

Functions

This section is empty.

Types

type Config added in v1.0.0

type Config struct {
	// FlushInterval is how often the goroutine will flush a counter's value to time-series db
	FlushInterval time.Duration

	// ServiceShutdownCtx is used to signal all counters to flush and then cleanly close the database
	ServiceShutdownCtx context.Context

	Storage tstorage.Storage
}

type Counter added in v1.0.0

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

func (*Counter) GetConfig added in v1.0.0

func (c *Counter) GetConfig() *opts.Counter

GetConfig returns counter config

func (*Counter) GetTSHistory added in v1.0.0

func (c *Counter) GetTSHistory(from, to int64) ([]*tstorage.DataPoint, error)

GetTSHistory gets time-series history for the counter

func (*Counter) GetTotal added in v1.0.0

func (c *Counter) GetTotal() (float64, error)

GetTotal aggregates the in-memory and historical total

func (*Counter) Incr added in v1.0.0

func (c *Counter) Incr(i float64)

Incr increases the value of a counter by the value of i

func (*Counter) Value added in v1.0.0

func (c *Counter) Value() float64

Value returns the current value of a counter

type IStats added in v1.0.0

type IStats interface {
	AddCounter(cfg *opts.Counter) *Counter
	GetAllCounters() map[string]*Counter
	GetCounter(counterType opts.Counter_Type, resourceType opts.Counter_Resource, resourceID string) (*Counter, error)
	RemoveCounter(counter *Counter) error
}

type Stats added in v1.0.0

type Stats struct {
	*Config
	// contains filtered or unexported fields
}

func New added in v1.0.0

func New(cfg *Config) (*Stats, error)

New returns a configured struct for the statistics service

func (*Stats) AddCounter added in v1.0.0

func (s *Stats) AddCounter(cfg *opts.Counter) *Counter

AddCounter creates a new counter and launches a runFlusher() goroutine for it

func (*Stats) GetAllCounters added in v1.0.0

func (s *Stats) GetAllCounters() map[string]*Counter

GetAllCounters returns the entire counters map

func (*Stats) GetCounter added in v1.0.0

func (s *Stats) GetCounter(counterType opts.Counter_Type, resourceType opts.Counter_Resource, resourceID string) (*Counter, error)

GetCounter retrieves a single counter from the counters map

func (*Stats) RemoveCounter added in v1.0.0

func (s *Stats) RemoveCounter(c *Counter) error

RemoveCounter will flush a counter's value to persistent storage, stop the associated runFlusher() go routine, and delete the counter from the counters map

Jump to

Keyboard shortcuts

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