meter

package module
v0.3.2 Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2017 License: MIT Imports: 12 Imported by: 0

README

go-meter

Metering for Go

Documentation

Index

Constants

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
)
View Source
const DefaultKeyPrefix = "meter"
View Source
const FieldTerminator = '\x1e'
View Source
const LabelSeparator = '\x1f'
View Source
const NilByte byte = 0

Variables

View Source
var (
	ErrInvalidEventLabel = errors.New("Invalid event label")
	ErrInvalidGroupLabel = errors.New("Invalid group label")
	ErrInvalidResolution = errors.New("Invalid event resolution")
)
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")
)
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 AppendField added in v0.2.0

func AppendField(data []byte, labels, values []string) []byte

func AppendMatch added in v0.2.0

func AppendMatch(data []byte, s string) []byte

func AppendMatchField added in v0.2.0

func AppendMatchField(data []byte, labels []string, group []string, q map[string]string) []byte

func CollectResults added in v0.2.2

func CollectResults(scan <-chan ScanResult) <-chan Results

func Field added in v0.2.5

func Field(labels, values []string) (f string)

func MatchField added in v0.2.3

func MatchField(labels []string, group []string, q map[string]string) (f string)

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 Collector added in v0.2.0

type Collector interface {
	Collect(chan<- Metric)
	Len() int
}

type Controller

type Controller struct {
	Q           Queryer
	Events      Resolver
	TimeDecoder tcodec.TimeDecoder
}

func (*Controller) ServeHTTP

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

type Counter

type Counter interface {
	Count() int64
	Add(n int64) int64
	Values() []string
	Set(n int64) int64
}

type Counters

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

func NewCounters

func NewCounters() *Counters

func (*Counters) MergeInto added in v0.2.0

func (cc *Counters) MergeInto(e Event)

func (*Counters) Reset added in v0.2.0

func (cc *Counters) Reset()

func (*Counters) WithLabelValues added in v0.2.0

func (cs *Counters) WithLabelValues(values ...string) (c Counter)

type DB

type DB struct {
	Redis     redis.UniversalClient
	KeyPrefix string
}

func NewDB

func NewDB(r redis.UniversalClient) *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) ExactQuery added in v0.2.0

func (db *DB) ExactQuery(results chan<- ScanResult, q Query) error

func (*DB) Gather added in v0.2.0

func (db *DB) Gather(col Collector, tm time.Time) (err 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)

func (*DB) ScanQuery added in v0.2.0

func (db *DB) ScanQuery(results chan<- ScanResult, q Query) (err error)

func (*DB) ValueScan added in v0.2.0

func (db *DB) ValueScan(results chan<- ScanResult, q Query) error

ValueScan return a frequency map of event label values

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 (*Desc) LabelIndex added in v0.2.0

func (d *Desc) LabelIndex(label string) int

func (*Desc) LabelValues added in v0.2.0

func (d *Desc) LabelValues(values []string) LabelValues

func (*Desc) Labels added in v0.2.0

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

func (*Desc) MatchingQueries added in v0.2.0

func (e *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 interface {
	WithLabels(labels LabelValues) Counter
	WithLabelValues(values ...string) Counter
	Descriptor
	Collector
}

func NewEvent

func NewEvent(desc *Desc) Event

type FrequencyMap added in v0.2.0

type FrequencyMap map[string]map[string]int64

type Gatherer added in v0.2.0

type Gatherer interface {
	Gather(col Collector, tm time.Time) error
}

type LabelValues added in v0.2.0

type LabelValues map[string]string

func FieldLabels added in v0.2.2

func FieldLabels(field []string) LabelValues

func (LabelValues) Equal added in v0.2.0

func (values LabelValues) Equal(other LabelValues) bool

func (LabelValues) Values added in v0.2.0

func (values LabelValues) Values(labels []string) []string

type Metric added in v0.2.0

type Metric interface {
	Counter
	Descriptor
}

func NewMetric added in v0.2.0

func NewMetric(n int64, values []string, desc *Desc) Metric

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
)

type Query

type Query struct {
	Mode       QueryMode
	Event      Descriptor
	Start, End time.Time
	Group      []string
	Values     []map[string]string
	Resolution Resolution
	// 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 (*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(event Event)

func (*Registry) Register

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

type Resetable added in v0.2.0

type Resetable interface {
	Reset()
}

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 LabelValues
	Data   DataPoints
}

type Results added in v0.2.0

type Results []Result

func (Results) Find added in v0.2.0

func (s Results) Find(event string, values LabelValues) *Result

func (Results) FrequencyMap added in v0.2.3

func (s Results) FrequencyMap() FrequencyMap

func (Results) IndexOf added in v0.2.0

func (s Results) IndexOf(event string, values LabelValues) int

type ScanQuery added in v0.2.3

type ScanQuery struct {
	Mode       QueryMode
	Event      *Desc
	Start, End time.Time
	Group      []string
	Resolution Resolution
	Values     []LabelValues
	// contains filtered or unexported fields
}

func (ScanQuery) Error added in v0.2.3

func (q ScanQuery) Error() error

type ScanResult added in v0.2.0

type ScanResult struct {
	Event  string
	Group  []string
	Time   time.Time
	Values LabelValues
	// contains filtered or unexported fields
}

func (ScanResult) AppendTo added in v0.2.3

func (r ScanResult) AppendTo(results Results) Results

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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