librato

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Sep 5, 2019 License: BSD-3-Clause Imports: 16 Imported by: 0

Documentation

Overview

Package librato is a small wrapper around Librato's API for submitting metrics.

This satisfies the go-kit metrics Provider type.

Index

Examples

Constants

View Source
const (
	// DefaultBucketCount is a reasonable default for the number of buckets a
	// Histogram should use.
	DefaultBucketCount = 50
	// DefaultURL for reporting metrics.
	DefaultURL = "https://metrics-api.librato.com/v1/metrics"
	// DefaultPercentilePrefix if WithPercentilePrefix isn't used to set a different prefix
	DefaultPercentilePrefix = ".p"
	// DefaultNumRetries if WithRetries isn't used to set a different value
	DefaultNumRetries = 3
	// DefaultBatchSize of metric batches sent to librato. This value was taken out of the librato docs at:
	// http://api-docs-archive.librato.com/?shell#measurement-properties
	DefaultBatchSize = 300
)

Variables

This section is empty.

Functions

func New

func New(URL *url.URL, interval time.Duration, opts ...OptionFunc) metrics.Provider

New librato metrics provider that reports metrics to the URL every interval with the provided options.

Example
start := time.Now()
u, err := url.Parse(DefaultURL)
if err != nil {
	log.Fatal(err)
}
u.User = url.UserPassword("libratoUser", "libratoPassword/Token")

errHandler := func(err error) {
	log.Println(err)
}
p := New(u, 20*time.Second, WithErrorHandler(errHandler))
c := p.NewCounter("i.am.a.counter")
h := p.NewHistogram("i.am.a.histogram", DefaultBucketCount)
g := p.NewGauge("i.am.a.gauge")
uc := p.NewCardinalityCounter("i.am.a.cardinality.estimate.counter")

// Pretend applicaion logic....
c.Add(1)
h.Observe(time.Since(start).Seconds()) // how long did it take the program to get here.
g.Set(1000)
uc.Insert([]byte("count this as 1"))
// /Pretend

// block until we report one final time
p.Stop()
Output:

Types

type CardinalityCounter

type CardinalityCounter struct {
	*xmetrics.HLLCounter
	// contains filtered or unexported fields
}

CardinalityCounter is a wrapper on xmetrics.CardinalityCounter which stores a reference to the underlying Provider.

func (*CardinalityCounter) Insert

func (c *CardinalityCounter) Insert(b []byte)

Insert implements CardinalityCounter.

func (*CardinalityCounter) With

func (c *CardinalityCounter) With(labelValues ...string) xmetrics.CardinalityCounter

With returns a CardinalityCounter with the label values applied. Depending on whether you're using tags or not, the label values may be applied to the name.

type Counter

type Counter struct {
	*generic.Counter
	// contains filtered or unexported fields
}

Counter is a wrapper on generic.Counter which stores a reference to the underlying Provider.

func (*Counter) Add

func (c *Counter) Add(delta float64)

Add implements Counter.

func (*Counter) With

func (c *Counter) With(labelValues ...string) kmetrics.Counter

With returns a Counter with the label values applied. Depending on whether you're using tags or not, the label values may be applied to the name.

type Error

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

Error is used to report information from a non 200 error returned by Librato.

func (Error) Body

func (e Error) Body() string

Body returned by librato.

func (Error) Code

func (e Error) Code() int

Code returned by librato

func (Error) Error

func (e Error) Error() string

Error interface

func (Error) RateLimit

func (e Error) RateLimit() (string, string)

RateLimit info returned by librato in the X-Librato-RateLimit-Agg and X-Librato-RateLimit-Std headers

func (Error) Request

func (e Error) Request() string

Request that generated the error

func (Error) Temporary

func (e Error) Temporary() bool

Temporary error that will be retried?

type Gauge

type Gauge struct {
	*generic.Gauge
	// contains filtered or unexported fields
}

Gauge is a wrapper on generic.Gauge which stores a reference to the underlying Provider.

func (*Gauge) Add

func (g *Gauge) Add(delta float64)

Add implements Gauge.

func (*Gauge) Set

func (g *Gauge) Set(value float64)

Set implements Gauge.

func (*Gauge) With

func (g *Gauge) With(labelValues ...string) kmetrics.Gauge

With returns a Gauge with the label values applied. Depending on whether you're using tags or not, the label values may be applied to the name.

type Histogram

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

Histogram adapts go-kit/Heroku/Librato's ideas of histograms. It reports p99, p95 and p50 values as gauges in addition to a gauge for the histogram itself.

func (*Histogram) Count

func (h *Histogram) Count() int64

Count of Observations

func (*Histogram) Max

func (h *Histogram) Max() float64

Max Observation

func (*Histogram) Min

func (h *Histogram) Min() float64

Min Observation

func (*Histogram) Observe

func (h *Histogram) Observe(value float64)

Observe some data for the histogram

func (*Histogram) Quantile

func (h *Histogram) Quantile(q float64) float64

Quantile percentage of reported Observations

func (*Histogram) Sum

func (h *Histogram) Sum() float64

Sum of the Observations

func (*Histogram) SumSq

func (h *Histogram) SumSq() float64

SumSq of the Observations

func (*Histogram) With

func (h *Histogram) With(labelValues ...string) kmetrics.Histogram

With returns a new LibratoHistogram with the same name / buckets but it is otherwise a noop

type OptionFunc

type OptionFunc func(*Provider)

OptionFunc used to set options on a librato provider

func WithBackoff

func WithBackoff(b func(r int) error) OptionFunc

WithBackoff sets the optional backoff handler. The backoffhandler should sleep for the amount of time required between retries. The backoff func receives the current number of retries remaining. Returning an error from the backoff func stops additional retries for that request.

The default backoff strategy is 100ms * (total # of tries - retries remaining)

func WithBatchSize

func WithBatchSize(n int) OptionFunc

WithBatchSize sets the number of metrics sent in a single request to librato

func WithErrorHandler

func WithErrorHandler(eh func(err error)) OptionFunc

WithErrorHandler sets the optional error handler used to report errors. Use this to log, or otherwise handle reporting errors in your application.

func WithPercentilePrefix

func WithPercentilePrefix(prefix string) OptionFunc

WithPercentilePrefix sets the optional percentile prefix used for the different percentile gauges reported for each histogram. The default is `.p`, meaning the name of those gauges will be:

<histogram metric name>.p50
<histogram metric name>.p95
<histogram metric name>.p99

func WithPrefix

func WithPrefix(prefix string) OptionFunc

WithPrefix sets the optional metrics prefix for the librato provider. If the prefix is != "" then it is prefixed to each metric name when reported.

func WithRequestDebugging

func WithRequestDebugging() OptionFunc

WithRequestDebugging enables request debugging which exposes the original request in the Error.

func WithResetCounters

func WithResetCounters() OptionFunc

WithResetCounters makes the reporting behavior reset all the counters every reporting interval. Use this option if you're trying to be compatible with l2met (e.g. you previously had l2met metrics which exhibited the same behavior).

func WithRetries

func WithRetries(n int) OptionFunc

WithRetries sets the max number of retries during reporting.

func WithSSA

func WithSSA() OptionFunc

WithSSA turns on Server Side Aggreggation for all gauges submitted.

func WithSource

func WithSource(source string) OptionFunc

WithSource sets the optional provided source for the librato provider

func WithTags

func WithTags(labelValues ...string) OptionFunc

WithTags allows the use of tags when submitting measurements. The default is to not allow it, and fall back to just sources.

type Provider

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

Provider works with Librato's older source based metrics (http://api-docs-archive.librato.com/?shell#create-a-metric, not the new tag based metrics). The generated metric's With methods return new metrics, but are otherwise noops as the LabelValues are not applied in any meaningful way.

func (*Provider) Batch

func (p *Provider) Batch(u *url.URL, interval time.Duration) ([]*http.Request, error)

func (*Provider) NewCardinalityCounter

func (p *Provider) NewCardinalityCounter(name string) xmetrics.CardinalityCounter

NewCardinalityCounter that will be reported by the provider.

func (*Provider) NewCounter

func (p *Provider) NewCounter(name string) kmetrics.Counter

NewCounter that will be reported by the provider. Becuase of the way librato works, they are reported as gauges. If you require a counter reset every report use the WithResetCounters option function, otherwise the counter's value will increase until restart.

func (*Provider) NewGauge

func (p *Provider) NewGauge(name string) kmetrics.Gauge

NewGauge that will be reported by the provider.

func (*Provider) NewHistogram

func (p *Provider) NewHistogram(name string, buckets int) kmetrics.Histogram

NewHistogram that will be reported by the provider.

func (*Provider) Stop

func (p *Provider) Stop()

Stop reporting metrics

Jump to

Keyboard shortcuts

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