librato

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

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

Go to latest
Published: Dec 29, 2016 License: MIT Imports: 6 Imported by: 0

README

librato

This package provides an api for publishing gauges and counters to librato asynchonously.

Usage

From Go:


  // Configure the authentication credentials
  // See struct docs for additional options
  config := Config{
    Email:  os.Getenv("LIBRATO_EMAIL"),
    APIKey: os.Getenv("LIBRATO_APIKEY"),
  }

  // Create a new librato instance
  // Each instance publishes independently of others, and
  // may be used to connect to multiple accounts
  l := librato.New(config)

  // Add a new gauge measurement.
  l.AddGauge(Gauge{Name: "reticulated.splines", Value: 1, Source: "add-gauge"})

  // add a new counter measurement
  l.AddCounter(Counter{Name: "reticulated.splines.counter", Value: 7, Source: "add-counter"})

  // Create and add an aggregate gauge
  a := Aggregate{Name: "reticulated.splines", Source: "add-aggregate"}
  a.Add(12).Add(6).Add(5).Add(4).Add(5).Add(10).Add(3)
  l.AddGauge(a.ToGauge())

  // When done, call Shutdown().
  // This operation is synchronous and will wait for the last
  // publish of metrics to complete
  l.Shutdown()

Installation

To install as a library, you can use go get:

go get github.com/stitchfix/librato

Additional Documentation

For further documentation, please refer to godocs at

GoDoc

Documentation

Overview

Package librato is a pure go client for publishing metrics to Librato.

The package publishes metrics asynchronously, at a regular interval. If the package is unable to log metrics (network issues, service outage, or the app being overloaded), it will drop metrics instead of degrading the application's performance. The package allows some control over this behavior by allowing the developer the option of configuring the queue size. Once this queue size is exceeded, messages will be dropped until the publisher catches up.

The package also provides an Aggregator struct which can be used to aggregate the gauge measurements on the client. For applications that need to log a substantial number of metrics, this will be preferable to publishing the individual metrics.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Aggregate

type Aggregate struct {
	// Each metric has a name that is unique to its class of metrics e.g. a gauge name must be unique among gauges. The name
	// identifies a metric in subsequent API calls to store/query individual measurements and can be up to 255 characters in
	// length. Valid characters for metric names are A-Za-z0-9.:-_. The metric namespace is case insensitive.
	Name string `json:"name"`

	// Source is an optional property that can be used to subdivide a common gauge/counter among multiple members of a population.
	// For example the number of requests/second serviced by an application could be broken up among a group of server instances in
	// a scale-out tier by setting the hostname as the value of source.
	Source string `json:"source,omitempty"`

	// The epoch time at which an individual measurement occurred with a maximum resolution of seconds.
	MeasureTime int64 `json:"measure_time,omitempty"`
	// contains filtered or unexported fields
}

Aggregate provides a means for aggregating metrics on the client side, and pushing the the calculated value to librato.

func (*Aggregate) Add

func (a *Aggregate) Add(v float64) *Aggregate

Add a new value to the aggregate The method returns itself to allow chaining

func (Aggregate) Count

func (a Aggregate) Count() int

Count is the number of measurements that have been recorded

func (Aggregate) Max

func (a Aggregate) Max() float64

Max is the maximum measurement value, or zero if no measurements exist.

func (Aggregate) Min

func (a Aggregate) Min() float64

Min is the minimum measurement value, or zero if no measurements exist.

func (Aggregate) Sum

func (a Aggregate) Sum() float64

Sum is the sum of the measurements

func (Aggregate) SumSquares

func (a Aggregate) SumSquares() float64

SumSquares is used to determine the standard deviation for the published measurements.

func (Aggregate) ToGauge

func (a Aggregate) ToGauge() Gauge

type Config

type Config struct {
	// Email used for logging into your librato account
	Email string
	// The Key used to access the librato api.
	APIKey string
	// An optional Queue size. By default, this will be 600
	QueueSize int
}

type Counter

type Counter struct {
	Name        string      `json:"name"`
	Value       interface{} `json:"value"`
	Source      string      `json:"source,omitempty"`
	MeasureTime int64       `json:"measure_time,omitempty"`
}

type Gauge

type Gauge struct {
	// Each metric has a name that is unique to its class of metrics e.g. a gauge name must be unique among gauges. The name
	// identifies a metric in subsequent API calls to store/query individual measurements and can be up to 255 characters in
	// length. Valid characters for metric names are A-Za-z0-9.:-_. The metric namespace is case insensitive.
	Name string `json:"name"`

	// The numeric value of an individual measurement. Multiple formats are supported (e.g. integer, floating point, etc) but the value must be numeric.
	Value interface{} `json:"value"`

	// Source is an optional property that can be used to subdivide a common gauge/counter among multiple members of a population.
	// For example the number of requests/second serviced by an application could be broken up among a group of server instances in
	// a scale-out tier by setting the hostname as the value of source.
	Source string `json:"source,omitempty"`

	// The epoch time at which an individual measurement occurred with a maximum resolution of seconds.
	MeasureTime int64 `json:"measure_time,omitempty"`

	// The following fields are used to publish aggregations
	// They are public to allow serialization, but should not be used directly.
	Count      int         `json:"count,omitempty"`
	Sum        interface{} `json:"sum,omitempty"`
	Min        interface{} `json:"min,omitempty"`
	Max        interface{} `json:"max,omitempty"`
	SumSquares interface{} `json:"sum_squares,omitempty"`
}

type Librato

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

func New

func New(config Config, errCh chan<- error) *Librato

New creates a new librato client. The client will harvest metrics and publish them every second. You can specify the QueueSize to control how many metrics the client will batch. If you exceed the queue size, the measures will be silently dropped.

func (*Librato) AddCounter

func (l *Librato) AddCounter(c Counter)

Adds a Counter measurement to librato. If the queue is full, the measure will be dropped, but an error will be published to the error channel if it was configured.

func (*Librato) AddGauge

func (l *Librato) AddGauge(g Gauge)

Adds a Gauge measurement to librato. If the queue is full, the measure will be dropped, but an error will be published to the error channel if it was configured.

func (*Librato) Shutdown

func (l *Librato) Shutdown()

Shutdown stops the librato client. The operation is blocking, and will make one final attempt to harvest measures and send them to librato.

Jump to

Keyboard shortcuts

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