meter

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 17, 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 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)
}

type Controller

type Controller struct {
	DB          *DB
	Registry    *Registry
	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
	// *Registry
	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) (pipelineSize int64, 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) Scan added in v0.2.0

func (db *DB) Scan(key, match string, group []string, r ScanResult, results chan<- ScanResult) (err 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(event Descriptor, res Resolution, start, end time.Time) FrequencyMap

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

type EventSampler struct {
	*SafeSampler
	// contains filtered or unexported fields
}

func (EventSampler) Cap added in v0.2.0

func (s EventSampler) Cap() int

Cap returns the capacity of a sample circular buffer

func (*EventSampler) Describe added in v0.2.0

func (s *EventSampler) Describe() *Desc

func (*EventSampler) LabelValues added in v0.2.0

func (s *EventSampler) LabelValues() (lvs LabelValues)

func (EventSampler) ObserveAt added in v0.2.0

func (s EventSampler) ObserveAt(ts int64, v float64)

ObserveAt records a sample at a specific point in time

func (*EventSampler) Values added in v0.2.0

func (s *EventSampler) Values() []string

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 (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 {
	Event      Descriptor
	Mode       QueryMode
	Start, End time.Time
	Group      []string
	Values     url.Values
	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 {
	Events     []string
	Mode       QueryMode
	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(r ...*Registry) (queries []Query)

func (QueryBuilder) QueryValues added in v0.2.0

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

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 (
	QueryModeScan QueryMode = iota
	QueryModeExact
)

func (QueryMode) String added in v0.2.0

func (m QueryMode) String() string

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 Result

type Result struct {
	Event string
	// Group  LabelValues
	Labels LabelValues
	Data   DataPoints
}

type Results added in v0.2.0

type Results []Result

func (Results) Append added in v0.2.0

func (results Results) Append(r ScanResult) Results

func (Results) Find added in v0.2.0

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

func (Results) IndexOf added in v0.2.0

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

type SafeSampler added in v0.2.0

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

SafeSampler is a thread safe Sampler

func NewSafeSampler added in v0.2.0

func NewSafeSampler(size int) *SafeSampler

NewSafeSampler initializes a SafeSampler

func (*SafeSampler) Avg added in v0.2.0

func (s *SafeSampler) Avg(since time.Time, q int) (avg float64)

Avg returns the average of sample diffs up to a specific point in time

func (SafeSampler) Cap added in v0.2.0

func (s SafeSampler) Cap() int

Cap returns the capacity of a sample circular buffer

func (*SafeSampler) Diff added in v0.2.0

func (s *SafeSampler) Diff(since time.Time, q int) (v float64)

Diff returns the sum of sample diffs up to a specific point in time

func (*SafeSampler) Len added in v0.2.0

func (s *SafeSampler) Len() (n int)

Len returns the number of samples in the circular buffer

func (*SafeSampler) Observe added in v0.2.0

func (s *SafeSampler) Observe(v float64)

Observe records a value at the current time

func (SafeSampler) ObserveAt added in v0.2.0

func (s SafeSampler) ObserveAt(ts int64, v float64)

ObserveAt records a sample at a specific point in time

type Sample added in v0.2.0

type Sample struct {
	Value     float64
	Timestamp int64
}

Sample holds the value at a specific time with second granularity

type Sampler added in v0.2.0

type Sampler interface {
	Len() int
	Cap() int
	Diff(since time.Time, q int) float64
	Avg(since time.Time, q int) float64
	// Rate(depth time.Duration, q int) float64
	Observe(v float64)
}

Sampler is the interface for sampling values over time

func NewSampler added in v0.2.0

func NewSampler(size int) Sampler

NewSampler creates a non thread safe Sampler

type Samplers added in v0.2.0

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

func NewSamplers added in v0.2.0

func NewSamplers(size int, desc *Desc) *Samplers

func (*Samplers) WithLabelValues added in v0.2.0

func (s *Samplers) WithLabelValues(values ...string) (ss *SafeSampler)

func (*Samplers) WithLabels added in v0.2.0

func (s *Samplers) WithLabels(lvs LabelValues) *SafeSampler

type ScanResult added in v0.2.0

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

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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