meter

package module
v0.1.12 Latest Latest
Warning

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

Go to latest
Published: Jul 31, 2017 License: MIT Imports: 16 Imported by: 0

README

go-meter

Metering for Go

Documentation

Index

Constants

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 DefaultMaxResults = 10000
View Source
const LabelSeparator = ':'

Variables

View Source
var (
	NilEventError          = errors.New("Event is nil.")
	NilResolutionError     = errors.New("Resolution is nil.")
	InvalidEventLabelError = errors.New("Invalid event label.")
)
View Source
var (
	NoResolution     = &Resolution{"totals", 0, 0, NoResolutionCodec}
	ResolutionHourly = &Resolution{"hourly", 0, Hourly, tc.LayoutCodec(HourlyDateFormat)}
	ResolutionDaily  = &Resolution{"daily", 0, Daily, tc.LayoutCodec(DailyDateFormat)}
	ResolutionMinly  = &Resolution{"minly", 0, Minly, tc.LayoutCodec(MinlyDateFormat)}
	ResolutionWeekly = &Resolution{"weekly", 0, Weekly, tc.ISOWeekCodec}
)
View Source
var (
	DuplicateTypeError = errors.New("Duplicate type registration.")
)
View Source
var (
	MaxRecordsError = errors.New("Max records reached")
)
View Source
var NoResolutionCodec = tc.NewTimeCodec(func(t time.Time) string {
	return "*"
}, func(s string) (t time.Time, e error) {
	return
})
View Source
var (
	UnregisteredEventError = errors.New("Unregistered event type")
)

Functions

func Alias

func Alias(s string) string

func IsTemplateName

func IsTemplateName(name string) bool

func Join

func Join(sep string, parts ...string) string

func Label

func Label(s string) string

func Log

func Log(name string, n int64, labels ...string) error

func LogEvent

func LogEvent(e *Event, n int64, labels ...string)

func MustLog

func MustLog(name string, n int64, labels ...string)

func MustPersist

func MustPersist(tm time.Time, r *redis.Client)

func MustRegister

func MustRegister(name string, t *Event)

func NormalizeLabels

func NormalizeLabels(labels ...string) (out []string)

func PermutationPairs

func PermutationPairs(input url.Values) [][]string

func Persist

func Persist(tm time.Time, r *redis.Client) error

func ReadRecords

func ReadRecords(r redis.UniversalClient, records []*Record) error

func Register

func Register(name string, t *Event) error

func Replacer

func Replacer(labels ...string) *strings.Replacer

func SetAlias

func SetAlias(label string, aliases ...string)

func TimeSequence

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

Types

type Aliases

type Aliases map[string]string

func AliasesFromValues

func AliasesFromValues(input url.Values) Aliases

func NewAliases

func NewAliases() Aliases

func (Aliases) Alias

func (a Aliases) Alias(s string) string

func (Aliases) Set

func (a Aliases) Set(label string, aliases ...string)

type Batch

type Batch map[string]int64

type Controller

type Controller struct {
	Resolution *Resolution
	DB         *DB
	MaxRecords int
}

func (*Controller) ServeHTTP

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

type Counter

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

func (*Counter) Get

func (v *Counter) Get() int64

func (*Counter) Inc

func (v *Counter) Inc(d int64) int64

func (*Counter) Set

func (v *Counter) Set(n int64) int64

type Counters

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

func NewCounters

func NewCounters() *Counters

func (*Counters) BatchIncrement

func (c *Counters) BatchIncrement(b Batch)

func (*Counters) Flush

func (c *Counters) Flush() Batch

func (*Counters) Increment

func (c *Counters) Increment(key string, n int64) int64

func (*Counters) Snapshot

func (c *Counters) Snapshot() Batch

type DB

type DB struct {
	Aliases  Aliases
	Registry *Registry
	Redis    redis.UniversalClient
}

func NewDB

func NewDB(r redis.UniversalClient) *DB

func (*DB) Mux

func (db *DB) Mux(maxrecords int, resolutions ...*Resolution) *http.ServeMux

func (*DB) Records

func (db *DB) Records(q Query) (rs RecordSequence, err error)

func (*DB) Results

func (db *DB) Results(q Query) (results []*Result, err error)

func (*DB) SummaryScan added in v0.1.11

func (db *DB) SummaryScan(q SummaryQuery) (sum Summary, err error)

type DataPoint

type DataPoint struct {
	Timestamp int64
	Value     int64
}

func (*DataPoint) MarshalJSON

func (d *DataPoint) MarshalJSON() ([]byte, error)

type DateRangeParserFunc

type DateRangeParserFunc func(string, string, time.Duration) (time.Time, time.Time, error)

func DateRangeParser

func DateRangeParser(dec tc.TimeDecoder) DateRangeParserFunc

type Dimension

type Dimension []string

func Dim

func Dim(labels ...string) Dimension

func LabelDimensions

func LabelDimensions(labels ...string) []Dimension

type Event

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

func GetEvent

func GetEvent(name string) *Event

func NewEvent

func NewEvent(name string, labels []string, res ...*Resolution) *Event

func (*Event) AliasedLabels

func (e *Event) AliasedLabels(input []string, aliases Aliases) (labels Labels)

func (*Event) AllField

func (e *Event) AllField() string

func (*Event) DimField

func (e *Event) DimField(dim Dimension, q map[string]string) (field string, ok bool)

func (*Event) EventName

func (e *Event) EventName(labels Labels) string

func (*Event) Field

func (e *Event) Field(input ...string) string

func (*Event) HasLabel

func (e *Event) HasLabel(a string) bool

func (*Event) Key

func (e *Event) Key(res *Resolution, tm time.Time, labels Labels) string

func (*Event) Labels

func (e *Event) Labels(input ...string) (labels []string)

func (*Event) Log

func (e *Event) Log(n int64, labels ...string)

func (*Event) MatchField added in v0.1.12

func (e *Event) MatchField(group string, input ...string) string

MatchField returns a redis MATCH argument with an asterisk matcher on the group label

func (*Event) MustPersist

func (e *Event) MustPersist(tm time.Time, r *redis.Client)

func (*Event) Persist

func (e *Event) Persist(tm time.Time, r *redis.Client) (err error)

func (*Event) Record

func (e *Event) Record(r *Resolution, t time.Time, labels []string) *Record

func (*Event) Records

func (e *Event) Records(res *Resolution, start, end time.Time, queries ...[]string) []*Record

func (*Event) Snapshot

func (e *Event) Snapshot() map[string]int64

func (*Event) ValueIndex added in v0.1.11

func (e *Event) ValueIndex(label string) int

type FlushError

type FlushError map[string]error

func (FlushError) Error

func (e FlushError) Error() string

type Labels

type Labels []string

func ParseField added in v0.1.12

func ParseField(field string) Labels

func (Labels) Get added in v0.1.11

func (labels Labels) Get(label string) (string, bool)

func (Labels) Map

func (labels Labels) Map() map[string]string

func (Labels) Set

func (labels Labels) Set(pairs ...string) Labels

type Logger

type Logger struct {
	*Registry
	Aliases Aliases
	// contains filtered or unexported fields
}

func NewLogger

func NewLogger() *Logger

func (*Logger) Close

func (lo *Logger) Close()

func (*Logger) FlushErrors

func (lo *Logger) FlushErrors() int64

func (*Logger) Log

func (lo *Logger) Log(name string, n int64, labels ...string) error

func (*Logger) MustLog

func (lo *Logger) MustLog(name string, n int64, labels ...string)

func (*Logger) MustPersist

func (lo *Logger) MustPersist(tm time.Time, r *redis.Client)

func (*Logger) Persist

func (lo *Logger) Persist(tm time.Time, r *redis.Client) error

type Query

type Query struct {
	Events     []string
	Start      time.Time
	End        time.Time
	Labels     map[string][]string
	Resolution *Resolution
	Grouped    bool
	MaxRecords int
}

func (*Query) Records

func (q *Query) Records(r *Registry) (rs RecordSequence, err error)

type Record

type Record struct {
	Name   string
	Time   time.Time
	Key    string
	Field  string
	Labels []string
	Result *redis.StringCmd
}

func (*Record) MarshalJSON

func (r *Record) MarshalJSON() ([]byte, error)

func (*Record) Value

func (r *Record) Value() int64

type RecordSequence

type RecordSequence []*Record

func (RecordSequence) Group

func (s RecordSequence) Group() []*Result

func (RecordSequence) Results

func (s RecordSequence) Results() []*Result

type Registry

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

func NewRegistry

func NewRegistry() *Registry

func (*Registry) Each

func (r *Registry) Each(fn func(name string, t *Event))

func (*Registry) Get

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

func (*Registry) Logger

func (r *Registry) Logger() *Logger

func (*Registry) MustRegister

func (r *Registry) MustRegister(name string, t *Event)

func (*Registry) Register

func (r *Registry) Register(name string, t *Event) error

type Resolution

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

func NewResolution

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

func (*Resolution) Key

func (r *Resolution) Key(event string, t time.Time) string

func (*Resolution) MarshalTime

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

func (*Resolution) ParseDateRange

func (r *Resolution) ParseDateRange(s, e string) (start, end time.Time, err error)

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) WithTTL

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

type Result

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

type Summary added in v0.1.11

type Summary map[string]int64

func (Summary) Add added in v0.1.11

func (s Summary) Add(other Summary)

type SummaryController added in v0.1.11

type SummaryController struct {
	Resolution *Resolution
	DB         *DB
}

func (*SummaryController) ServeHTTP added in v0.1.11

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

type SummaryQuery added in v0.1.11

type SummaryQuery struct {
	Time       time.Time
	Event      string
	Labels     []string
	Group      string
	Resolution *Resolution
}

Jump to

Keyboard shortcuts

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