Documentation ¶
Overview ¶
Package librato is a small wrapper around Librato's API for submitting metrics.
This satisfies the go-kit metrics Provider type.
Index ¶
- Constants
- func New(u *url.URL, interval time.Duration, opts ...OptionFunc) metrics.Provider
- type CardinalityCounter
- type Counter
- type Error
- type Gauge
- type Histogram
- func (h *Histogram) Count() int64
- func (h *Histogram) Max() float64
- func (h *Histogram) Min() float64
- func (h *Histogram) Observe(value float64)
- func (h *Histogram) Quantile(q float64) float64
- func (h *Histogram) Sum() float64
- func (h *Histogram) SumSq() float64
- func (h *Histogram) With(labelValues ...string) kmetrics.Histogram
- type OptionFunc
- func WithBackoff(b func(r int) error) OptionFunc
- func WithBatchSize(n int) OptionFunc
- func WithErrorHandler(eh func(err error)) OptionFunc
- func WithPercentilePrefix(prefix string) OptionFunc
- func WithPrefix(prefix string) OptionFunc
- func WithRequestDebugging() OptionFunc
- func WithResetCounters() OptionFunc
- func WithRetries(n int) OptionFunc
- func WithSSA() OptionFunc
- func WithSource(source string) OptionFunc
- func WithTags(labelValues ...string) OptionFunc
- type Provider
- func (p *Provider) Batch(u *url.URL, interval time.Duration) ([]*http.Request, error)
- func (p *Provider) NewCardinalityCounter(name string) xmetrics.CardinalityCounter
- func (p *Provider) NewCounter(name string) kmetrics.Counter
- func (p *Provider) NewGauge(name string) kmetrics.Gauge
- func (p *Provider) NewHistogram(name string, buckets int) kmetrics.Histogram
- func (p *Provider) Stop()
Examples ¶
Constants ¶
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 ¶
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 ¶
Counter is a wrapper on generic.Counter which stores a reference to the underlying Provider.
type Error ¶
type Error struct {
// contains filtered or unexported fields
}
Error is used to report information from a non 200 error returned by Librato.
type Gauge ¶
Gauge is a wrapper on generic.Gauge which stores a reference to the underlying Provider.
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.
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) NewCardinalityCounter ¶
func (p *Provider) NewCardinalityCounter(name string) xmetrics.CardinalityCounter
NewCardinalityCounter that will be reported by the provider.
func (*Provider) NewCounter ¶
NewCounter that will be reported by the provider. Because 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) NewHistogram ¶
NewHistogram that will be reported by the provider.