stata

package module
v1.0.8 Latest Latest
Warning

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

Go to latest
Published: Jan 11, 2021 License: MIT Imports: 6 Imported by: 4

README

Stata

Stata is a library that handles time-series counters in analytics.

install json datasource

Grafana JSON Datasource

grafana-cli plugins install simpod-json-datasource

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Bins bins = bins{
	Total: Bin{Name: "total", Format: func(t time.Time) time.Time {
		return time.Unix(0, 0)
	}},
	Year: Bin{Name: "y", Format: func(t time.Time) time.Time {
		return time.Date(t.Year(), 0, 0, 0, 0, 0, 0, t.Location())
	}},
	Month: Bin{Name: "m", Format: func(t time.Time) time.Time {
		return time.Date(t.Year(), t.Month(), 0, 0, 0, 0, 0, t.Location())
	}},
	Day: Bin{Name: "d", Format: func(t time.Time) time.Time {
		return time.Date(t.Year(), t.Month(), t.Day(), 0, 0, 0, 0, t.Location())
	}},
	Hour: Bin{Name: "h", Format: func(t time.Time) time.Time {
		return time.Date(t.Year(), t.Month(), t.Day(), t.Hour(), 0, 0, 0, t.Location())
	}},
	Minute: Bin{Name: "1min", Format: func(t time.Time) time.Time {
		return time.Date(t.Year(), t.Month(), t.Day(), t.Hour(), t.Minute(), 0, 0, t.Location())
	}},
}

Bins list of default bins

View Source
var (
	// ErrNotImplemented means feature is not implemented yet
	ErrNotImplemented = errors.New("not implemented")
)

Functions

This section is empty.

Types

type Bin

type Bin struct {
	Name   string                      // bin name e.g 1m, h, d, month, y
	Format func(t time.Time) time.Time // rounds time to particular time-series bin
}

Bin keys

type Config

type Config struct {
	Storage *Storage
}

Config config

type Event

type Event struct {
	Name string
	// contains filtered or unexported fields
}

Event simple counter

func (*Event) Inc

func (e *Event) Inc() error

Inc increments counters for event

type EventAvg added in v1.0.7

type EventAvg struct {
	Name string
	// contains filtered or unexported fields
}

EventAvg calcs avg between increment executions

func (*EventAvg) Inc added in v1.0.7

func (e *EventAvg) Inc(val int64) error

Inc calculates average value among all passed values for every bin

type EventConfig added in v1.0.4

type EventConfig struct {
	Bins []Bin
	Mode *Mode
}

EventConfig config params for event

type Key

type Key struct {
	Name      string
	Timestamp time.Time
	Bin       Bin
}

Key represents key parts

type KeyRange

type KeyRange struct {
	From Key
	To   Key
}

KeyRange for queries

type KeyValue

type KeyValue struct {
	Key   Key
	Value Value
}

KeyValue key-value pair

type Mode added in v1.0.4

type Mode struct {
	NeedWriteKey func(key KeyValue) bool
}

Mode mode manages storage behavior while writing keys

var ModeDefault Mode = Mode{
	NeedWriteKey: func(kv KeyValue) bool {

		return true
	},
}

ModeDefault this mode writes every update to storage, bypassing cache

var ModeReduceWorkload Mode = Mode{
	NeedWriteKey: func(kv KeyValue) bool {
		if kv.Value%10 == 0 {
			return true
		}

		return false
	},
}

ModeReduceWorkload this mode reduces workload to storage by using in-memory cache layer

type Stata

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

Stata Stata realtime stat tool

func New

func New(config *Config) *Stata

New creates new stata client

func (*Stata) Event

func (s *Stata) Event(name string, config EventConfig) *Event

Event creates new event

func (*Stata) EventAvg added in v1.0.7

func (s *Stata) EventAvg(name string, config EventConfig) *EventAvg

EventAvg creates avg event

func (*Stata) Get

func (s *Stata) Get(key Key) (Value, error)

Get increments all counters for that event

func (*Stata) GetEvents

func (s *Stata) GetEvents() []*Event

GetEvents returns list of events

func (*Stata) GetRange

func (s *Stata) GetRange(keyRange KeyRange) ([]KeyValue, error)

GetRange gets range of keys

type Storage

type Storage struct {
	Get      func(key Key) (Value, error)
	Set      func(key Key, val Value) error
	GetRange func(keyRange KeyRange) ([]KeyValue, error)
	IncrBy   func(keys []Key, value Value) error
	Clear    func() error // removes data from storage
}

Storage storage interface for stata

func NewMemoryStorage added in v1.0.4

func NewMemoryStorage() *Storage

NewMemoryStorage creates in-memory storage for stata counters

type Value added in v1.0.3

type Value = int64

Value is counter value

Directories

Path Synopsis
fdb module
foundationdb module
memory module
redis module

Jump to

Keyboard shortcuts

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