appoptics

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 8, 2019 License: BSD-2-Clause Imports: 10 Imported by: 0

README

This is a reporter for the go-metrics library which posts the metrics to AppOptics/Librato. It is forked from go-metrics-librato and was originally part of the go-metrics library itself.

This library supports tagged metrics only; source-based metrics have been deprecated by Librato. The original go-metrics-librato library can be used if you need to upload source-based metrics instead.

Usage

import "github.com/ysamlan/go-metrics-appoptics"

go appoptics.AppOptics(metrics.DefaultRegistry,
    10*time.Second,              // interval for uploads
    "token",                     // AppOptics API token
    map[string]string{
        "hostname": "localhost", // tags
    }, 
    []float64{0.95},             // percentiles to send
    time.Millisecond,            // time units for timers
    "myservicename.",            // prefix on reported metric names
    nil,                         // (optional) go-metrics runtime.* stats upload whitelist
)

Features

Metric Name Prefix: This reporter supports a prefix argument when initializing. All uploaded metrics will have that prefix prepended to their names. Use "" if you don't want this behavior.

Tags: Tags passed during the initialization are attached to all this reporter's measurements to AppOptics.

Selective runtime metric uploading: If you're using go-metrics' CaptureRuntimeMemStats feature, it's great and automates collecting a lot of useful data. Unfortunately, it also adds 30 metrics, which can eat up a lot of metric hours with AppOptics. The runtimeMetricsWhiteleist parameter lets you cherry-pick which metrics actually get uploaded, without needing to manually collect them yourself. See the source for possible values. Pass nil to allow all, and an empty slice to disable uploads for all runtime. metrics.

Limitations

Tags are attached at the batch level, not to the individual metrics/measurements within the batch. You can work around this by using a different Registry and appoptics.AppOptics goroutine for metrics that need different tags. See #1 for potential approaches for fixing this.

Migrating from rcrowley/go-metrics / mihasya/go-metrics-librato implementation

To get the same behavior you're used to from the original Librato reporter (only with tags instead of sources):

  • Change the import to "github.com/ysamlan/go-metrics-appoptics"
  • Change librato.Librato to appoptics.AppOptics
  • Remove the email argument from the appoptics.AppOptics function call (the updated AppOptics API only requires the token)
  • Change the source argument from a string into a map[string]string for tags - e.g. a source "myhostname" could become the tag map[string]string{"host":"myhostname"}).
  • Use "" for the metric name prefix.
  • Use nil for the runtime-metric-name whitelist (allow-all).

Documentation

Index

Constants

View Source
const (
	// display attributes
	Color             = "color"
	DisplayMax        = "display_max"
	DisplayMin        = "display_min"
	DisplayUnitsLong  = "display_units_long"
	DisplayUnitsShort = "display_units_short"
	DisplayStacked    = "display_stacked"
	DisplayTransform  = "display_transform"
	// special gauge display attributes
	SummarizeFunction = "summarize_function"
	Aggregate         = "aggregate"

	// metric keys
	Name        = "name"
	Period      = "period"
	Description = "description"
	DisplayName = "display_name"
	Attributes  = "attributes"

	// measurement keys
	Time  = "time"
	Tags  = "tags"
	Value = "value"

	// special gauge keys
	Count  = "count"
	Sum    = "sum"
	Max    = "max"
	Min    = "min"
	StdDev = "stddev"

	// batch keys
	Measurements = "measurements"

	MetricsPostUrl = "https://api.appoptics.com/v1/measurements"
)

property strings

View Source
const Operations = "operations"
View Source
const OperationsShort = "ops"

Variables

This section is empty.

Functions

func AppOptics

func AppOptics(registry metrics.Registry, interval time.Duration, token string, tags map[string]string,
	percentiles []float64, timeUnits time.Duration, prefix string, whitelistedRuntimeMetrics []string)

Call in a goroutine to start metric uploading. Using whitelistedRuntimeMetrics: a non-nil value sets this reporter to upload only a subset of the runtime.* metrics that are gathered by go-metrics runtime memory stats (CaptureRuntimeMemStats). The full list of possible values is at https://github.com/rcrowley/go-metrics/blob/master/runtime.go#L181-L211 Passing an empty slice disables uploads for all runtime.* metrics.

func SetHTTPClient

func SetHTTPClient(c *http.Client)

Types

type AppOpticsClient

type AppOpticsClient struct {
	Token string
}

func (*AppOpticsClient) PostMetrics

func (self *AppOpticsClient) PostMetrics(batch Batch) (err error)

type Batch

type Batch struct {
	Measurements []Measurement     `json:"measurements,omitempty"`
	Time         int64             `json:"time"`
	Tags         map[string]string `json:"tags"`
}

type Measurement

type Measurement map[string]interface{}

type Metric

type Metric map[string]interface{}

type Reporter

type Reporter struct {
	Token                     string
	Tags                      map[string]string
	Interval                  time.Duration
	Registry                  metrics.Registry
	Percentiles               []float64              // percentiles to report on histogram metrics
	Prefix                    string                 // prefix metric names for upload (eg "servicename.")
	WhitelistedRuntimeMetrics map[string]bool        // runtime.* metrics to upload (nil = allow all)
	TimerAttributes           map[string]interface{} // units in which timers will be displayed
	// contains filtered or unexported fields
}

func NewReporter

func NewReporter(registry metrics.Registry, interval time.Duration, token string, tags map[string]string,
	percentiles []float64, timeUnits time.Duration, prefix string, whitelistedRuntimeMetrics []string) *Reporter

func (*Reporter) BuildRequest

func (self *Reporter) BuildRequest(now time.Time, r metrics.Registry) (snapshot Batch, err error)

func (*Reporter) Run

func (self *Reporter) Run()

Jump to

Keyboard shortcuts

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