meter

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Dec 1, 2018 License: MIT Imports: 19 Imported by: 0

README

go-meter

Metering for Go

Documentation

Index

Constants

View Source
const (
	DefaultKeyPrefix = "meter" // Prefix all keys
	DefaultSeparator = '^'     // Key separator
	DefaultScanSize  = 100     // Scan size for queries
)

DB defaults

View Source
const (
	QueryParamEvent      = "event"
	QueryParamResolution = "res"
	QueryParamStart      = "start"
	QueryParamEnd        = "end"
	QueryParamGroup      = "group"
	QueryParamMode       = "mode"
)
View Source
const (
	// DailyDateFormat is the date format used by the start/end query parameters
	DailyDateFormat  string = "2006-01-02"
	HourlyDateFormat string = "2006-01-02-15"
	MinlyDateFormat  string = "2006-01-02-15-04"
)
View Source
const (
	Minly   = time.Minute
	Hourly  = time.Hour
	Daily   = 24 * time.Hour
	Weekly  = 7 * Daily
	Monthly = 30 * Daily
	Yearly  = 365 * Daily
)

Variables

View Source
var (
	ErrDuplicateEvent    = errors.New("Duplicate event registration.")
	ErrNilRegistry       = errors.New("Registry is nil")
	ErrNilEvent          = errors.New("Event is nil")
	ErrNilDesc           = errors.New("Desc is nil")
	ErrUnregisteredEvent = errors.New("Unregistered event")
	ErrInvalidEventLabel = errors.New("Invalid event label")
	ErrInvalidGroupLabel = errors.New("Invalid group label")
	ErrInvalidResolution = errors.New("Invalid event resolution")
)
View Source
var (
	// NoResolution     = Resolution{"totals", 0, 0, NoResolutionCodec}
	ResolutionHourly = Resolution{"hourly", 0, Hourly, tcodec.LayoutCodec(HourlyDateFormat)}
	ResolutionDaily  = Resolution{"daily", 0, Daily, tcodec.LayoutCodec(DailyDateFormat)}
	ResolutionMinly  = Resolution{"minly", 0, Minly, tcodec.LayoutCodec(MinlyDateFormat)}
	ResolutionWeekly = Resolution{"weekly", 0, Weekly, tcodec.ISOWeekCodec}
)

Functions

func QueryPermutations added in v0.2.0

func QueryPermutations(input url.Values) []map[string]string

func TimeSequence

func TimeSequence(start time.Time, end time.Time, unit time.Duration) []time.Time

Types

type Client added in v0.4.0

type Client struct {
	URL string
	*http.Client
}

func (*Client) Batch added in v0.4.0

func (c *Client) Batch(logger *log.Logger, events ...*Event)

func (*Client) Run added in v0.4.0

func (c *Client) Run(ctx context.Context, interval time.Duration, logger *log.Logger, events ...*Event)

func (*Client) Sync added in v0.4.0

func (c *Client) Sync(e *Event) error

type Controller

type Controller struct {
	DB *DB
	*Registry
	Logger        *log.Logger
	TimeDecoder   tcodec.TimeDecoder
	FlushInterval time.Duration
	// contains filtered or unexported fields
}

func (*Controller) Close added in v0.4.0

func (c *Controller) Close()

func (*Controller) Flush added in v0.4.0

func (c *Controller) Flush(t time.Time)

func (*Controller) ServeHTTP

func (c *Controller) ServeHTTP(w http.ResponseWriter, r *http.Request)

type Counter

type Counter struct {
	Count  int64    `json:"n"`
	Values []string `json:"v"`
}

func (*Counter) Match added in v0.4.0

func (c *Counter) Match(values []string) bool

type DB

type DB struct {
	Redis        *redis.Pool
	KeyPrefix    string
	KeySeparator byte
	ScanSize     int64
}

func NewDB

func NewDB(r *redis.Pool) *DB

func (DB) AppendKey added in v0.2.0

func (db DB) AppendKey(data []byte, r Resolution, event string, t time.Time) []byte

func (*DB) Batch added in v0.4.0

func (db *DB) Batch(tm time.Time, events ...*Event) (err []error)

func (*DB) Gather added in v0.2.0

func (db *DB) Gather(tm time.Time, e *Event) error

func (DB) Key added in v0.2.0

func (db DB) Key(r Resolution, event string, t time.Time) (k string)

func (*DB) Query added in v0.2.0

func (db *DB) Query(queries ...Query) (Results, error)

type DataPoint

type DataPoint struct {
	Timestamp, Value int64
}

func (DataPoint) MarshalJSON

func (p DataPoint) MarshalJSON() (data []byte, err error)

func (*DataPoint) UnmarshalJSON added in v0.2.0

func (p *DataPoint) UnmarshalJSON(data []byte) (err error)

type DataPoints added in v0.2.0

type DataPoints []DataPoint

func (DataPoints) Find added in v0.2.0

func (data DataPoints) Find(tm time.Time) (int64, bool)

func (DataPoints) IndexOf added in v0.2.0

func (data DataPoints) IndexOf(tm time.Time) int

func (DataPoints) Len added in v0.2.0

func (s DataPoints) Len() int

func (DataPoints) Less added in v0.2.0

func (s DataPoints) Less(i, j int) bool

func (DataPoints) MarshalJSON added in v0.2.0

func (s DataPoints) MarshalJSON() (data []byte, err error)

func (DataPoints) Sort added in v0.2.0

func (s DataPoints) Sort()

func (DataPoints) Swap added in v0.2.0

func (s DataPoints) Swap(i, j int)

type Desc added in v0.2.0

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

func NewCounterDesc added in v0.2.0

func NewCounterDesc(name string, labels []string, res ...Resolution) *Desc

func NewDesc added in v0.2.0

func NewDesc(t MetricType, name string, labels []string, res ...Resolution) *Desc

func NewValueDesc added in v0.2.0

func NewValueDesc(name string, labels []string, res ...Resolution) *Desc

func (*Desc) Describe added in v0.2.0

func (d *Desc) Describe() *Desc

func (*Desc) Error added in v0.2.0

func (d *Desc) Error() error

func (*Desc) HasLabel added in v0.2.0

func (d *Desc) HasLabel(label string) bool
func (d *Desc) LabelIndex(label string) int {
	return indexOf(d.labels, label)
}

func (*Desc) Labels added in v0.2.0

func (d *Desc) Labels() []string

func (*Desc) MatchingQueries added in v0.2.0

func (d *Desc) MatchingQueries(q url.Values) url.Values

func (*Desc) Name added in v0.2.0

func (d *Desc) Name() string

func (*Desc) Resolution added in v0.2.0

func (d *Desc) Resolution(name string) (r Resolution, ok bool)

func (*Desc) Resolutions added in v0.2.0

func (d *Desc) Resolutions() []Resolution

func (*Desc) Type added in v0.2.0

func (d *Desc) Type() MetricType

type Descriptor added in v0.2.0

type Descriptor interface {
	Describe() *Desc
}

type Event

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

func NewEvent

func NewEvent(desc *Desc) *Event

func (*Event) Add added in v0.4.0

func (e *Event) Add(n int64, values ...string) int64

func (*Event) AddVolatile added in v0.4.0

func (e *Event) AddVolatile(n int64, values ...string) int64

func (*Event) Describe added in v0.4.0

func (e *Event) Describe() *Desc

func (*Event) Flush added in v0.4.0

func (e *Event) Flush(s Snapshot) Snapshot

func (*Event) Len added in v0.4.0

func (e *Event) Len() (n int)

func (*Event) Merge added in v0.4.0

func (e *Event) Merge(s Snapshot)

func (*Event) Pack added in v0.4.0

func (e *Event) Pack()

Pack packs the event index dropping zero counters

type FrequencyMap added in v0.2.0

type FrequencyMap map[string]map[string]int64

type MetricType added in v0.2.0

type MetricType uint8
const (
	MetricTypeIncrement  MetricType // Increment value on store
	MetricTypeUpdateOnce            // Update value once on store
	MetricTypeUpdate                // Update value on store
)

func (MetricType) RedisCmd added in v0.4.0

func (t MetricType) RedisCmd() string

type Query

type Query struct {
	Mode       QueryMode
	Event      Descriptor
	Start, End time.Time
	Group      []string
	Resolution Resolution
	Values     []map[string]string
	// contains filtered or unexported fields
}

func (*Query) Error added in v0.2.0

func (q *Query) Error() error

type QueryBuilder added in v0.2.0

type QueryBuilder struct {
	Mode       QueryMode
	Events     []string
	Start, End time.Time
	Group      []string
	Query      url.Values
	Resolution string
}

func NewQueryBuilder added in v0.2.0

func NewQueryBuilder() QueryBuilder

func ParseQuery added in v0.2.0

func ParseQuery(q url.Values, tdec tcodec.TimeDecoder) (s QueryBuilder, err error)

func (QueryBuilder) At added in v0.2.0

func (QueryBuilder) Between added in v0.2.0

func (q QueryBuilder) Between(start, end time.Time) QueryBuilder

func (QueryBuilder) Exact added in v0.2.0

func (q QueryBuilder) Exact() QueryBuilder

func (QueryBuilder) From added in v0.2.0

func (q QueryBuilder) From(event ...string) QueryBuilder

func (QueryBuilder) GroupBy added in v0.2.0

func (q QueryBuilder) GroupBy(label ...string) QueryBuilder

func (QueryBuilder) Queries added in v0.2.0

func (qb QueryBuilder) Queries(events Resolver) (queries []Query)

func (QueryBuilder) QueryValues added in v0.2.0

func (q QueryBuilder) QueryValues(d *Desc) []map[string]string

func (QueryBuilder) Scan added in v0.3.0

func (q QueryBuilder) Scan() QueryBuilder

func (QueryBuilder) Values added in v0.3.0

func (q QueryBuilder) Values() QueryBuilder

func (QueryBuilder) Where added in v0.2.0

func (q QueryBuilder) Where(label string, value ...string) QueryBuilder

type QueryMode added in v0.2.0

type QueryMode uint8
const (
	ModeScan QueryMode = iota
	ModeExact
	ModeValues
)

func (QueryMode) String added in v0.2.0

func (m QueryMode) String() string

type Queryer added in v0.2.3

type Queryer interface {
	Query(queries ...Query) (Results, error)
}

type Registries added in v0.2.0

type Registries []*Registry

func (Registries) Get added in v0.2.0

func (r Registries) Get(name string) *Event

type Registry

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

func NewRegistry

func NewRegistry() *Registry

func NewRegistryEvents added in v0.3.5

func NewRegistryEvents(events ...*Event) *Registry

func (*Registry) Events added in v0.2.0

func (c *Registry) Events() []*Event

func (*Registry) Get

func (c *Registry) Get(name string) (e *Event)

func (*Registry) MustRegister

func (c *Registry) MustRegister(events ...*Event)

func (*Registry) Register

func (c *Registry) Register(event *Event) error

type Resolution

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

func NewResolution

func NewResolution(name string, step, ttl time.Duration) Resolution

func (Resolution) AddSteps added in v0.2.0

func (r Resolution) AddSteps(t time.Time, n int) time.Time

func (Resolution) IsZero added in v0.2.0

func (r Resolution) IsZero() bool

func (Resolution) MarshalTime

func (r Resolution) MarshalTime(t time.Time) string

func (Resolution) Name

func (r Resolution) Name() string

func (Resolution) Round

func (r Resolution) Round(t time.Time) time.Time

func (Resolution) Step

func (r Resolution) Step() time.Duration

func (Resolution) TTL

func (r Resolution) TTL() time.Duration

func (Resolution) TimeSequence

func (r Resolution) TimeSequence(s, e time.Time) []time.Time

func (Resolution) UnmarshalTime

func (r Resolution) UnmarshalTime(s string) (t time.Time, err error)

func (Resolution) WithCodec added in v0.2.0

func (r Resolution) WithCodec(codec tcodec.TimeCodec) Resolution

func (Resolution) WithLayout added in v0.2.0

func (r Resolution) WithLayout(layout string) Resolution

func (Resolution) WithName added in v0.2.0

func (r Resolution) WithName(name string) Resolution

func (Resolution) WithStep added in v0.2.0

func (r Resolution) WithStep(step time.Duration) Resolution

func (Resolution) WithTTL

func (r Resolution) WithTTL(ttl time.Duration) Resolution

type Resolver added in v0.3.0

type Resolver interface {
	Get(eventName string) *Event
}

type ResolverFunc added in v0.3.0

type ResolverFunc func(eventName string) Event

func (ResolverFunc) Get added in v0.3.0

func (rf ResolverFunc) Get(eventName string) Event

type Result

type Result struct {
	Event  string
	Labels map[string]string
	Data   DataPoints
}

func (*Result) Match added in v0.4.0

func (r *Result) Match(values map[string]string) bool

type Results added in v0.2.0

type Results []Result

func (Results) Find added in v0.2.0

func (rs Results) Find(event string, values map[string]string) *Result

func (Results) FrequencyMap added in v0.2.3

func (rs Results) FrequencyMap() FrequencyMap

func (Results) IndexOf added in v0.2.0

func (rs Results) IndexOf(event string, values map[string]string) int

type Snapshot added in v0.4.0

type Snapshot []Counter

func (Snapshot) FilterZero added in v0.4.1

func (s Snapshot) FilterZero() Snapshot

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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