meter

package module
v2.0.0-beta9 Latest Latest
Warning

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

Go to latest
Published: Jul 17, 2019 License: MIT Imports: 17 Imported by: 0

README

go-meter

Metering for Go

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Register

func Register(scheme string, op Opener)

Types

type Counter

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

Counter counts events labeled by values

func (*Counter) Match

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

Match checks if values match counter's own values

type CounterSlice

type CounterSlice []Counter

CounterSlice is a slice of counters

func (CounterSlice) FilterZero

func (s CounterSlice) FilterZero() CounterSlice

FilterZero filters out empty counters in-place

func (CounterSlice) Reset

func (s CounterSlice) Reset() CounterSlice

Reset resets a snapshot

func (CounterSlice) Zero

func (s CounterSlice) Zero()

Zero resets all counters to zero count

type Counters

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

Counters is an index of counters safe for councurrent use

func NewCounters

func NewCounters(size int) *Counters

NewCounters creates a new counter index of size capacity

func (*Counters) Add

func (cs *Counters) Add(n int64, values ...string) int64

Add adds n to a specific counter

func (*Counters) Flush

func (cs *Counters) Flush(s CounterSlice) CounterSlice

Flush appends counters to a CounterSlice and resets all counters to zero

func (*Counters) Len

func (cs *Counters) Len() (n int)

Len returns the number of counters in an Event

func (*Counters) Merge

func (cs *Counters) Merge(s CounterSlice)

Merge adds all counters from a CounterSlice

func (*Counters) Pack

func (cs *Counters) Pack()

Pack packs the counter index dropping zero counters

type DB

type DB interface {
	Querier
	Storer(event string) Storer
	Close() error
}

func Open

func Open(configURL string) (DB, error)

type DataPoint

type DataPoint struct {
	Timestamp int64
	Value     float64
}

DataPoint is a time/value pair

func (DataPoint) AppendJSON

func (p DataPoint) AppendJSON(data []byte) []byte

AppendJSON appends JSON to a buffer

func (DataPoint) MarshalJSON

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

MarshalJSON implements json.Marshaler interface

func (*DataPoint) UnmarshalJSON

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

UnmarshalJSON implements json.Unmarshaler interface

type DataPoints

type DataPoints []DataPoint

DataPoints is a collection of DataPoints

func (DataPoints) AppendJSON

func (s DataPoints) AppendJSON(data []byte) []byte

AppendJSON appends points as JSON to a buffer

func (DataPoints) Avg

func (s DataPoints) Avg() float64

Avg returns the average value of all points

func (DataPoints) Copy

func (s DataPoints) Copy() DataPoints

Copy creates a copy of s

func (DataPoints) First

func (s DataPoints) First() *DataPoint

First returns a pointer to the first point

func (DataPoints) Get

func (s DataPoints) Get(i int) *DataPoint

Get returns a pointer to the i-th point

func (DataPoints) IndexOf

func (s DataPoints) IndexOf(ts int64) int

IndexOf returns the index of tm in the collection of data points

func (DataPoints) Last

func (s DataPoints) Last() *DataPoint

Last returns a pointer to the last point

func (DataPoints) Len

func (s DataPoints) Len() int

Len implements sort.Interface

func (DataPoints) Less

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

Less implements sort.Interface

func (DataPoints) MarshalJSON

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

MarshalJSON implements json.Marshal interface

func (DataPoints) Merge

func (s DataPoints) Merge(m Merger, data ...DataPoint) DataPoints

Merge merges other datapoints using m

func (DataPoints) MergeConsecutiveDuplicates

func (s DataPoints) MergeConsecutiveDuplicates(m Merger) DataPoints

MergeConsecutiveDuplicates merges sequential points with equal timestamps

func (DataPoints) MergePoint

func (s DataPoints) MergePoint(m Merger, t int64, v float64) DataPoints

MergePoint adds a point using Merger

func (DataPoints) MergeScalar

func (s DataPoints) MergeScalar(m Merger, v float64) DataPoints

MergeScalar merges a value to all datapoints using m

func (DataPoints) Sum

func (s DataPoints) Sum() (sum float64)

Sum returns the sum of the values of all points

func (DataPoints) Swap

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

Swap implements sort.Interface

func (DataPoints) ValueAt

func (s DataPoints) ValueAt(ts int64) float64

ValueAt searches for the value at a specific time

type Eval

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

Eval is a query expression of simple arthmetic between events

func ParseEval

func ParseEval(exp string) (*Eval, error)

ParseEval parses a query expression

func (*Eval) Events

func (e *Eval) Events() []string

Events returns the distinct event names referenced in the query expression

func (*Eval) Result

func (e *Eval) Result(results map[string]ScanResult) (r Result, err error)

Result calculates the result of an expression

func (*Eval) String

func (e *Eval) String() string

type Evaler

type Evaler interface {
	Eval(ctx context.Context, q Query, exp ...string) (Results, error)
}

Evaler runs eval queries

func QueryEvaler

func QueryEvaler(querier Querier) Evaler

QueryEvaler turns a Querier to an Evaler

type Event

type Event struct {
	Name   string   `json:"name"`
	Labels []string `json:"labels"`
	*Counters
}

Event stores counters for an event

func NewEvent

func NewEvent(name string, labels ...string) *Event

NewEvent creates a new Event using the specified labels

func (*Event) SyncTask

func (e *Event) SyncTask(db Storer) func(time.Time) error

SyncTask dumps an Event to an EventStore

type EventSummaries

type EventSummaries struct {
	Labels []string
	Events []string
	Data   []EventSummary
}

EventSummaries is a result summary format

func (*EventSummaries) Table

func (s *EventSummaries) Table() Table

Table returns event summaries as a table

type EventSummary

type EventSummary struct {
	Values []string
	Totals map[string]float64
}

EventSummary groups values with totals

func (*EventSummary) TableRow

func (r *EventSummary) TableRow(events []string) []interface{}

TableRow is a helper to convert event summary to table

type Field

type Field struct {
	Label string
	Value string
}

Field is a Label/Value pair

type FieldCache

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

FieldCache is an in memory cache of field ids

func (*FieldCache) BlobID

func (c *FieldCache) BlobID(blob []byte) (id uint64, ok bool)

BlobID returns the id of raw fields

func (*FieldCache) Fields

func (c *FieldCache) Fields(id uint64) (fields Fields)

Fields gets fields by id

func (*FieldCache) ID

func (c *FieldCache) ID(fields Fields) (uint64, bool)

ID gets the id of fields

func (*FieldCache) Labels

func (c *FieldCache) Labels() (labels []string)

Labels returns the distinct cached labels

func (*FieldCache) Set

func (c *FieldCache) Set(id uint64, fields Fields) Fields

Set set a field to an id

func (*FieldCache) SetBlob

func (c *FieldCache) SetBlob(id uint64, blob []byte) Fields

SetRaw sets a raw field value to an id

type FieldSummaries

type FieldSummaries []FieldSummary

FieldSummaries is a slice of FieldSummary results

type FieldSummary

type FieldSummary struct {
	Event  string             `json:"event"`
	Label  string             `json:"label"`
	Values map[string]float64 `json:"values"`
}

FieldSummary is a query result presented as a summary of field values

func (*FieldSummary) Add

func (s *FieldSummary) Add(value string, n float64)

Add ads a value to a field summary

type Fields

type Fields []Field

Fields is a collection of Label/Value pairs

func ZipFields

func ZipFields(labels []string, values []string) (fields Fields)

ZipFields creates a field collection zipping labels and values

func (Fields) Add

func (fields Fields) Add(field Field) Fields

func (Fields) AppendBlob

func (fields Fields) AppendBlob(b []byte) ([]byte, error)

AppendBlob implements blob.Appender interface

func (Fields) AppendValues

func (fields Fields) AppendValues(dst []string, empty string, labels ...string) []string

AppendValues appends the values for the labels in order

func (Fields) Copy

func (fields Fields) Copy() Fields

Copy clones a collection of fields

func (Fields) Equal

func (fields Fields) Equal(other Fields) bool

Equal checks if two Fields are equal

func (Fields) FromBlob

func (fields Fields) FromBlob(b []byte) (Fields, []byte)

ShiftBlob implements blob.Shifter interface

func (Fields) Get

func (fields Fields) Get(label string) (string, bool)

Get returns the value of label

func (Fields) GroupBy

func (fields Fields) GroupBy(empty string, groups []string) Fields

GroupBy groups fields by labels

func (Fields) Len

func (fields Fields) Len() int

func (Fields) Less

func (fields Fields) Less(i, j int) bool

func (Fields) Map

func (fields Fields) Map() map[string][]string

Map converts a Fields collection to a map

func (Fields) MarshalJSON

func (fields Fields) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler interface

func (Fields) MatchSorted

func (fields Fields) MatchSorted(match Fields) bool

MatchSorted matches fields agaist a sorted collection of Fields

func (Fields) Merge

func (fields Fields) Merge(other ...Field) Fields

func (Fields) Reset

func (fields Fields) Reset() Fields

Reset resets Fields to empty

func (*Fields) ShiftBlob

func (fields *Fields) ShiftBlob(b []byte) ([]byte, error)

ShiftBlob implements blob.Shifter interface

func (Fields) Sorted

func (fields Fields) Sorted() Fields

Sorted returns a copy of fields sorted by label

func (Fields) Swap

func (fields Fields) Swap(i, j int)

func (*Fields) UnmarshalBinary

func (fields *Fields) UnmarshalBinary(b []byte) error

func (*Fields) UnmarshalJSON

func (fields *Fields) UnmarshalJSON(data []byte) error

UnmarshalJSON implements json.Marshaler interface

type MemoryStore

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

MemoryStore is an in-memory EventStore for debugging

func (*MemoryStore) Last

func (m *MemoryStore) Last() *Snapshot

Last retuns the last posted StoreRequest

func (*MemoryStore) Scan

func (m *MemoryStore) Scan(ctx context.Context, span TimeRange, match Fields) (results ScanResults, err error)

Scan implements the Scanner interface

func (*MemoryStore) Scanner

func (m *MemoryStore) Scanner(event string) Scanner

Scanner implements the EventScanner interface

func (*MemoryStore) Store

func (m *MemoryStore) Store(req *Snapshot) error

Store implements EventStore interface

type MergeAvg

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

MergeAvg merges values to their average

func (*MergeAvg) Merge

func (avg *MergeAvg) Merge(_, b float64) float64

Merge implements Merger

type MergeDiff

type MergeDiff struct{}

MergeDiff subtracts values

func (MergeDiff) Merge

func (MergeDiff) Merge(a, b float64) float64

Merge implements Merger

type MergeDiv

type MergeDiv struct{}

MergeDiv divides values

func (MergeDiv) Merge

func (MergeDiv) Merge(a, b float64) float64

Merge implements Merger

type MergeFunc

type MergeFunc func(a, b float64) float64

MergeFunc is a closure Merger

func (MergeFunc) Merge

func (f MergeFunc) Merge(a, b float64) float64

Merge implements Merger

type MergeMax

type MergeMax struct{}

MergeMax keeps max value

func (MergeMax) Merge

func (MergeMax) Merge(a, b float64) float64

Merge implements Merger

type MergeMin

type MergeMin struct{}

MergeMin keeps min value

func (MergeMin) Merge

func (MergeMin) Merge(a, b float64) float64

Merge implements Merger

type MergeMul

type MergeMul struct{}

MergeMul multiplies values

func (MergeMul) Merge

func (MergeMul) Merge(a, b float64) float64

Merge implements Merger

type MergeSum

type MergeSum struct{}

MergeSum adds values

func (MergeSum) Merge

func (MergeSum) Merge(a, b float64) float64

Merge implements Merger

type Merger

type Merger interface {
	Merge(a, b float64) float64
}

Merger provides a method to merge values

type Opener

type Opener interface {
	Open(configURL string) (DB, error)
}

type Querier

type Querier interface {
	Query(ctx context.Context, q Query, events ...string) (Results, error)
}

Querier runs queries

func ScanQuerier

func ScanQuerier(s Scanners) Querier

ScanQuerier turns a Scanners to a Querier

type Query

type Query struct {
	TimeRange
	Match      Fields   `json:"match,omitempty"`
	Group      []string `json:"group,omitempty"`
	EmptyValue string   `json:"empty,omitempty"`
}

Query is a query for event results

func (Query) At

func (q Query) At(step time.Duration) Query

func (Query) Between

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

func (Query) GroupBy

func (q Query) GroupBy(group ...string) Query

func (*Query) Scan

func (q *Query) Scan(ctx context.Context, s Scanners, events ...string) (Results, error)

Scan executes a query using scanners

func (Query) Where

func (q Query) Where(label string, values ...string) Query

type Result

type Result struct {
	ScanResult
	Event string `json:"event,omitempty"`
}

Result is a query result

type ResultType

type ResultType int

ResultType is a type of result

const (
	ArrayResult ResultType = iota
	TotalsResult
	EventSummaryResult
	FieldSummaryResult
)

Result types

func ResultTypeFromString

func ResultTypeFromString(s string) ResultType

ResultTypeFromString converts a string to ResultType

type Results

type Results []Result

Results is a slice of results

func (Results) Add

func (results Results) Add(event string, fields Fields, ts int64, n float64) Results

Add adds a result

func (Results) ByEvent

func (results Results) ByEvent() map[string]ScanResult

func (Results) EventSummaries

func (results Results) EventSummaries(empty string) *EventSummaries

EventSummaries groups results as EventSummaries

func (Results) FieldSummaries

func (results Results) FieldSummaries() (s FieldSummaries)

FieldSummaries converts a series of results to a slice of FieldSummary results

func (Results) Totals

func (results Results) Totals() (totals Totals)

Totals returns a totals-only Results slice

type ScanResult

type ScanResult struct {
	Fields Fields     `json:"fields,omitempty"`
	Data   DataPoints `json:"data,omitempty"`
}

ScanResult is result of a scan

func (*ScanResult) Merge

func (r *ScanResult) Merge(other *ScanResult, m Merger)

func (*ScanResult) Reset

func (r *ScanResult) Reset()

Reset resets a result

type ScanResults

type ScanResults []ScanResult

ScanResults are results from a scan

func (ScanResults) Add

func (results ScanResults) Add(fields Fields, t int64, v float64) ScanResults

Add adds a result

func (ScanResults) GroupBy

func (results ScanResults) GroupBy(labels []string, empty string) (grouped ScanResults)

func (ScanResults) Merge

func (results ScanResults) Merge(fields Fields, data ...DataPoint) ScanResults

type Scanner

type Scanner interface {
	Scan(ctx context.Context, span TimeRange, match Fields) (ScanResults, error)
}

Scanner scans stored data according to a query

type ScannerIndex

type ScannerIndex map[string]Scanner

ScannerIndex is an index of scanners that implements Scanners interface

func (ScannerIndex) Scanner

func (s ScannerIndex) Scanner(event string) Scanner

Scanner implements Scanners interface

type Scanners

type Scanners interface {
	Scanner(event string) Scanner
}

Scanners provides a Scanner for an event

type Snapshot

type Snapshot struct {
	Time     time.Time    `json:"time,omitempty"`
	Labels   []string     `json:"labels"`
	Counters CounterSlice `json:"counters"`
}

Snapshot is a snaphot of event counters

type Storer

type Storer interface {
	Store(s *Snapshot) error
}

Storer stores events

func TeeStore

func TeeStore(stores ...Storer) Storer

TeeStore stores to multiple stores

type Table

type Table struct {
	Columns []interface{}   `json:"cols"`
	Data    [][]interface{} `json:"data"`
}

Table holds generic tabular data

type TimeRange

type TimeRange struct {
	Start time.Time     `json:"start"`
	End   time.Time     `json:"end"`
	Step  time.Duration `json:"step"`
}

TimeRange is a range of time with a specific step

func (*TimeRange) Truncate

func (tr *TimeRange) Truncate(tm time.Time) time.Time

type Total

type Total struct {
	Event  string  `json:"event"`
	Fields Fields  `json:"fields,omitempty"`
	Total  float64 `json:"total"`
}

type Totals

type Totals []Total

type UnsafeCounters

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

UnsafeCounters is an index of counters not safe for concurrent use

func (*UnsafeCounters) Add

func (cs *UnsafeCounters) Add(n int64, values ...string) int64

Add increments a counter matching values by n

func (*UnsafeCounters) Flush

Flush appends all counters to a snapshot and resets them to zero

func (*UnsafeCounters) Get

func (cs *UnsafeCounters) Get(i int) *Counter

Get returns the counter at index i

func (*UnsafeCounters) Len

func (cs *UnsafeCounters) Len() int

Len returns the number of counters in an Event

func (*UnsafeCounters) Pack

func (cs *UnsafeCounters) Pack()

Pack packs the counter index dropping zero counters

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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