metrics

package module
v0.0.0-...-d63b684 Latest Latest
Warning

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

Go to latest
Published: Feb 16, 2019 License: Apache-2.0 Imports: 13 Imported by: 1

README

metrics

A metrics library for GoLang services and applications

This library is integrated with noxdew/config

Installation

go get bitbucket.org/noxdew/metrics

Usage

import "bitbucket.org/noxdew/metrics"

func main() {
    metricsConfig := metrics.Config{} // Or parse yaml/json file into it
    metricsConfig.Configure(logger)

    // Check all available functions in functions.go
    metrics.IncrementBy1("some.path")
}

Currently supported reporters

  • none - no reported, essentially disabled metrics
  • log - log all reports to stderr, perfect for development
  • influxdb - send metrics to InfluxDB

If you need a new reporter, feel free to submit a PR or request it in an issue. We will try to add more.

Contributing

Feel free to create issues or contribute code. We are reviewing them regularly.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Decrement

func Decrement(path string, value int64)

Decrement the specified counter by the value Counters hold an int64 value that can be incremented and decremented

func DecrementBy1

func DecrementBy1(path string)

DecrementBy1 the specified counter Counters hold an int64 value that can be incremented and decremented

func DecrementBy1WithTags

func DecrementBy1WithTags(path string, tags map[string]string)

DecrementBy1WithTags the specified counter with the given tags Counters hold an int64 value that can be incremented and decremented

func DecrementWithTags

func DecrementWithTags(path string, value int64, tags map[string]string)

DecrementWithTags the specified counter by the value with the given tags Counters hold an int64 value that can be incremented and decremented

func Increment

func Increment(path string, value int64)

Increment the specified counter by the value Counters hold an int64 value that can be incremented and decremented

func IncrementBy1

func IncrementBy1(path string)

IncrementBy1 the specified counter Counters hold an int64 value that can be incremented and decremented

func IncrementBy1WithTags

func IncrementBy1WithTags(path string, tags map[string]string)

IncrementBy1WithTags the specified counter with the given tags Counters hold an int64 value that can be incremented and decremented

func IncrementWithTags

func IncrementWithTags(path string, value int64, tags map[string]string)

IncrementWithTags the specified counter by the value with the given tags Counters hold an int64 value that can be incremented and decremented

func InfluxDB

func InfluxDB(r metrics.Registry, config ReporterConfig, logger *zap.Logger)

InfluxDB starts a InfluxDB reporter which will post the metrics from the given registry at each d interval with the specified tags

func MarkMeter

func MarkMeter(path string, value int64)

MarkMeter records the value against the specified meter Meters count events to produce exponentially-weighted moving average rates at one-, five-, and fifteen-minutes and a mean rate

func MarkMeterWithTags

func MarkMeterWithTags(path string, value int64, tags map[string]string)

MarkMeterWithTags records the value against the specified meter with the given tags Meters count events to produce exponentially-weighted moving average rates at one-, five-, and fifteen-minutes and a mean rate

func NewSlidingWindowSample

func NewSlidingWindowSample(window time.Duration) metrics.Sample

NewSlidingWindowSample constructs a new sliding window sample with the given window

func StartSlidingWindowTrimmer

func StartSlidingWindowTrimmer()

StartSlidingWindowTrimmer starts the regular trimming of sliding window samples

func Time

func Time(path string, f func())

Time record the duration of execution of the given function Timers capture the duration and rate of events

func TimeWithTags

func TimeWithTags(path string, tags map[string]string, f func())

TimeWithTags record the duration of execution of the given function with the given tags Timers capture the duration and rate of events

func UpdateGauge

func UpdateGauge(path string, value int64)

UpdateGauge records the value on the specified gauge Gauges hold an int64 value that can be set arbitrarily

func UpdateGaugeFloat64

func UpdateGaugeFloat64(path string, value float64)

UpdateGaugeFloat64 records the value on the specified gauge Gauges hold an float64 value that can be set arbitrarily

func UpdateGaugeFloat64WithTags

func UpdateGaugeFloat64WithTags(path string, value float64, tags map[string]string)

UpdateGaugeFloat64WithTags records the value on the specified gauge with the given tags Gauges hold an float64 value that can be set arbitrarily

func UpdateGaugeWithTags

func UpdateGaugeWithTags(path string, value int64, tags map[string]string)

UpdateGaugeWithTags records the value on the specified gauge with the given tags Gauges hold an int64 value that can be set arbitrarily

func UpdateHistogram

func UpdateHistogram(path string, value int64)

UpdateHistogram records the value against the specified histogram Histograms calculate distribution statistics from a series of int64 values

func UpdateHistogramWithTags

func UpdateHistogramWithTags(path string, value int64, tags map[string]string)

UpdateHistogramWithTags records the value against the specified histogram with the given tags Histograms calculate distribution statistics from a series of int64 values

func UpdateTimer

func UpdateTimer(path string, duration time.Duration)

UpdateTimer records the duration against the specified timer Timers capture the duration and rate of events

func UpdateTimerSince

func UpdateTimerSince(path string, start time.Time)

UpdateTimerSince records the elapsed time since <start> against the specified timer Timers capture the duration and rate of events

func UpdateTimerSinceWithTags

func UpdateTimerSinceWithTags(path string, start time.Time, tags map[string]string)

UpdateTimerSinceWithTags records the elapsed time since <start> against the specified timer with the given tags Timers capture the duration and rate of events

func UpdateTimerWithTags

func UpdateTimerWithTags(path string, duration time.Duration, tags map[string]string)

UpdateTimerWithTags records the duration against the specified timer with the given tags Timers capture the duration and rate of events

Types

type Config

type Config struct {
	Type           string         `yaml:"type" json:"type"`
	ReporterConfig ReporterConfig `yaml:"config" json:"config"`
}

Config represent the configuration of the metrics package

func (Config) Configure

func (config Config) Configure(logger *zap.Logger)

Configure go-metrics using the config of the service it panics on all errors as it is better than running the service in the dark

type ReporterConfig

type ReporterConfig struct {
	URL      string            `yaml:"url" json:"url"`
	Username string            `yaml:"username" json:"username"`
	Password string            `yaml:"password" json:"password"`
	Database string            `yaml:"database" json:"database"`
	Prefix   string            `yaml:"prefix" json:"prefix"`
	Interval int               `yaml:"interval" json:"interval"` // in seconds
	Tags     map[string]string `yaml:"tags" json:"tags"`
}

ReporterConfig represents the configuration of the reporter

type SlidingWindowSample

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

SlidingWindowSample is an implementation of the sliding window algorithm

func (*SlidingWindowSample) Clear

func (s *SlidingWindowSample) Clear()

Clear clears all samples.

func (*SlidingWindowSample) Count

func (s *SlidingWindowSample) Count() int64

Count returns the number of samples recorded.

func (*SlidingWindowSample) Max

func (s *SlidingWindowSample) Max() int64

Max returns the maximum value in the sample, which may not be the maximum value ever to be part of the sample.

func (*SlidingWindowSample) Mean

func (s *SlidingWindowSample) Mean() float64

Mean returns the mean of the values in the sample.

func (*SlidingWindowSample) Min

func (s *SlidingWindowSample) Min() int64

Min returns the minimum value in the sample, which may not be the minimum value ever to be part of the sample.

func (*SlidingWindowSample) Percentile

func (s *SlidingWindowSample) Percentile(p float64) float64

Percentile returns an arbitrary percentile of values in the sample.

func (*SlidingWindowSample) Percentiles

func (s *SlidingWindowSample) Percentiles(ps []float64) []float64

Percentiles returns a slice of arbitrary percentiles of values in the sample.

func (*SlidingWindowSample) Size

func (s *SlidingWindowSample) Size() int

Size returns the size of the sample.

func (*SlidingWindowSample) Snapshot

func (s *SlidingWindowSample) Snapshot() metrics.Sample

Snapshot returns a read-only copy of the sample.

func (*SlidingWindowSample) StdDev

func (s *SlidingWindowSample) StdDev() float64

StdDev returns the standard deviation of the values in the sample.

func (*SlidingWindowSample) Sum

func (s *SlidingWindowSample) Sum() int64

Sum returns the sum of the values in the sample.

func (*SlidingWindowSample) Update

func (s *SlidingWindowSample) Update(v int64)

Update samples a new value.

func (*SlidingWindowSample) Values

func (s *SlidingWindowSample) Values() []int64

Values returns a copy of the values in the sample.

func (*SlidingWindowSample) Variance

func (s *SlidingWindowSample) Variance() float64

Variance returns the variance of the values in the sample.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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