tsdmetrics

package module
v0.0.0-...-7739dee Latest Latest
Warning

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

Go to latest
Published: Jun 4, 2019 License: BSD-2-Clause-Views Imports: 17 Imported by: 0

README

go-tsdmetrics

Documentation

Overview

+build !cgo appengine

Index

Examples

Constants

This section is empty.

Variables

Functions

func CaptureTaggedRuntimeMemStatsOnce

func CaptureTaggedRuntimeMemStatsOnce(r TaggedRegistry)

Capture new values for the Go runtime statistics exported in runtime.MemStats. This is designed to be called in a background goroutine. Giving a registry which has not been given to RegisterRuntimeMemStats will panic.

Be very careful with this because runtime.ReadMemStats calls the C functions runtime·semacquire(&runtime·worldsema) and runtime·stoptheworld() and that last one does what it says on the tin.

func CleanOpenTSDB

func CleanOpenTSDB(s string) string

func CleanOpenTSDBRune

func CleanOpenTSDBRune(r, replace rune) rune

func RegisterTaggedRuntimeMemStats

func RegisterTaggedRuntimeMemStats(r TaggedRegistry)

Register runtimeMetrics for the Go runtime statistics exported in runtime and specifically runtime.MemStats. The runtimeMetrics are named by their fully-qualified Go symbols, i.e. runtime.MemStats.Alloc.

Types

type ClearableMetric

type ClearableMetric interface {
	Clear()
}

type DefaultTaggedMetric

type DefaultTaggedMetric struct {
	Tags   Tags
	Metric interface{}
}

func (*DefaultTaggedMetric) AddTags

func (m *DefaultTaggedMetric) AddTags(tags Tags) TaggedMetric

func (*DefaultTaggedMetric) GetMetric

func (m *DefaultTaggedMetric) GetMetric() interface{}

func (*DefaultTaggedMetric) GetTags

func (m *DefaultTaggedMetric) GetTags() Tags

func (*DefaultTaggedMetric) GetTagsID

func (m *DefaultTaggedMetric) GetTagsID() TagsID

func (*DefaultTaggedMetric) TagString

func (m *DefaultTaggedMetric) TagString() string

type DefaultTaggedRegistry

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

The standard implementation of a Registry is a mutex-protected map of names to metrics.

func (*DefaultTaggedRegistry) Add

func (r *DefaultTaggedRegistry) Add(name string, tags Tags, i interface{}) error

func (*DefaultTaggedRegistry) Each

func (r *DefaultTaggedRegistry) Each(f func(string, TaggedMetric))

Call the given function for each registered metric.

func (*DefaultTaggedRegistry) Get

func (r *DefaultTaggedRegistry) Get(name string, tags Tags) interface{}

Get the metric by the given name or nil if none is registered.

func (*DefaultTaggedRegistry) GetOrRegister

func (r *DefaultTaggedRegistry) GetOrRegister(name string, tags Tags, i interface{}) interface{}

Gets an existing metric or creates and registers a new one. Threadsafe alternative to calling Get and Register on failure. The interface can be the metric to register if not found in registry, or a function returning the metric for lazy instantiation.

func (*DefaultTaggedRegistry) Register

func (r *DefaultTaggedRegistry) Register(name string, tags Tags, i interface{}) error

Register the given metric under the given name. Returns a DuplicateMetric if a metric by the given name is already registered.

func (*DefaultTaggedRegistry) RunHealthchecks

func (r *DefaultTaggedRegistry) RunHealthchecks()

Run all registered healthchecks.

func (*DefaultTaggedRegistry) Unregister

func (r *DefaultTaggedRegistry) Unregister(name string, tags Tags)

Unregister the metric with the given name.

func (*DefaultTaggedRegistry) UnregisterAll

func (r *DefaultTaggedRegistry) UnregisterAll()

Unregister all metrics. (Mostly for testing.)

func (*DefaultTaggedRegistry) UnregisterMetric

func (r *DefaultTaggedRegistry) UnregisterMetric(i interface{})

Unregister the metric using the Metric object itself.

func (*DefaultTaggedRegistry) WrappedEach

func (r *DefaultTaggedRegistry) WrappedEach(wrapperFunc func(string, TaggedMetric) (string, TaggedMetric), f func(string, TaggedMetric))

type DuplicateTaggedMetric

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

DuplicateMetric is the error returned by Registry.Register when a metric already exists. If you mean to Register that metric you must first Unregister the existing metric.

func (DuplicateTaggedMetric) Error

func (err DuplicateTaggedMetric) Error() string

type IntHistogram

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

IntHistogram is the standard implementation of a Histogram and uses a Sample to bound its memory use.

func (*IntHistogram) Clear

func (h *IntHistogram) Clear()

Clear clears the histogram and its sample.

func (*IntHistogram) Count

func (h *IntHistogram) Count() int64

Count returns the number of samples recorded since the histogram was last cleared.

func (*IntHistogram) Max

func (h *IntHistogram) Max() int64

Max returns the maximum value in the sample.

func (*IntHistogram) Mean

func (h *IntHistogram) Mean() int64

Mean returns the mean of the values in the sample.

func (*IntHistogram) Min

func (h *IntHistogram) Min() int64

Min returns the minimum value in the sample.

func (*IntHistogram) Percentile

func (h *IntHistogram) Percentile(p float64) int64

Percentile returns an arbitrary percentile of the values in the sample.

func (*IntHistogram) Percentiles

func (h *IntHistogram) Percentiles(ps []float64) []int64

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

func (*IntHistogram) Sample

func (h *IntHistogram) Sample() metrics.Sample

Sample returns the Sample underlying the histogram.

func (*IntHistogram) Snapshot

func (h *IntHistogram) Snapshot() IntegerHistogram

Snapshot returns a read-only copy of the histogram.

func (*IntHistogram) StdDev

func (h *IntHistogram) StdDev() int64

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

func (*IntHistogram) Sum

func (h *IntHistogram) Sum() int64

Sum returns the sum in the sample.

func (*IntHistogram) Update

func (h *IntHistogram) Update(v int64)

Update samples a new value.

func (*IntHistogram) Variance

func (h *IntHistogram) Variance() int64

Variance returns the variance of the values in the sample.

type IntHistogramSnapshot

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

IntHistogramSnapshot is a read-only copy of another Histogram.

func (*IntHistogramSnapshot) Clear

func (*IntHistogramSnapshot) Clear()

Clear panics.

func (*IntHistogramSnapshot) Count

func (h *IntHistogramSnapshot) Count() int64

Count returns the number of samples recorded at the time the snapshot was taken.

func (*IntHistogramSnapshot) Max

func (h *IntHistogramSnapshot) Max() int64

Max returns the maximum value in the sample at the time the snapshot was taken.

func (*IntHistogramSnapshot) Mean

func (h *IntHistogramSnapshot) Mean() int64

Mean returns the mean of the values in the sample at the time the snapshot was taken.

func (*IntHistogramSnapshot) Min

func (h *IntHistogramSnapshot) Min() int64

Min returns the minimum value in the sample at the time the snapshot was taken.

func (*IntHistogramSnapshot) Percentile

func (h *IntHistogramSnapshot) Percentile(p float64) int64

Percentile returns an arbitrary percentile of values in the sample at the time the snapshot was taken.

func (*IntHistogramSnapshot) Percentiles

func (h *IntHistogramSnapshot) Percentiles(ps []float64) []int64

Percentiles returns a slice of arbitrary percentiles of values in the sample at the time the snapshot was taken.

func (*IntHistogramSnapshot) Sample

func (h *IntHistogramSnapshot) Sample() metrics.Sample

Sample returns the Sample underlying the histogram.

func (*IntHistogramSnapshot) Snapshot

func (h *IntHistogramSnapshot) Snapshot() IntegerHistogram

Snapshot returns the snapshot.

func (*IntHistogramSnapshot) StdDev

func (h *IntHistogramSnapshot) StdDev() int64

StdDev returns the standard deviation of the values in the sample at the time the snapshot was taken.

func (*IntHistogramSnapshot) Sum

func (h *IntHistogramSnapshot) Sum() int64

Sum returns the sum in the sample at the time the snapshot was taken.

func (*IntHistogramSnapshot) Update

func (*IntHistogramSnapshot) Update(int64)

Update panics.

func (*IntHistogramSnapshot) Variance

func (h *IntHistogramSnapshot) Variance() int64

Variance returns the variance of inputs at the time the snapshot was taken.

type IntegerHistogram

type IntegerHistogram interface {
	Clear()
	Count() int64
	Max() int64
	Mean() int64
	Min() int64
	Percentile(float64) int64
	Percentiles([]float64) []int64
	Sample() metrics.Sample
	Snapshot() IntegerHistogram
	StdDev() int64
	Sum() int64
	Update(int64)
	Variance() int64
}

func NewIntegerHistogram

func NewIntegerHistogram(s metrics.Sample) IntegerHistogram

type MetricWrapper

type MetricWrapper struct {
	Registry TaggedRegistry
	OpenTSDB TaggedOpenTSDB
	// contains filtered or unexported fields
}

func NewMetricWrapper

func NewMetricWrapper(baseName string, baseTags string, addr string, flushInterval int, logger logrus.FieldLogger) (*MetricWrapper, error)

NewMetricWrapper returns a wrapper facilitating the creation of common metric objects

func (*MetricWrapper) Counter

func (w *MetricWrapper) Counter(name string, tags Tags) metrics.Counter

Counter creates a metric counter object

func (*MetricWrapper) Gauge

func (w *MetricWrapper) Gauge(name string, tags Tags) metrics.Gauge

Gauge creates a metric gauge object

func (*MetricWrapper) GaugeFloat64

func (w *MetricWrapper) GaugeFloat64(name string, tags Tags) metrics.GaugeFloat64

GaugeFloat64 creates a float64 metric gauge object

func (*MetricWrapper) Histogram

func (w *MetricWrapper) Histogram(name string, sample metrics.Sample, tags Tags) metrics.Histogram

Histogram creates a metric histogram object

func (*MetricWrapper) Meter

func (w *MetricWrapper) Meter(name string, tags Tags) metrics.Meter

Meter creates a metric meter object

func (*MetricWrapper) RegisterMemStats

func (w *MetricWrapper) RegisterMemStats(tags Tags)

RegisterMemStats will send go runtime stats to opentsdb

func (*MetricWrapper) UnregisterMetric

func (w *MetricWrapper) UnregisterMetric(i interface{})

UnregisterMetric unregister metrics using the Metric object itself.

type OpenTSDBFormat

type OpenTSDBFormat int
const (
	Tcollector OpenTSDBFormat = iota
	Json
)

type OpenTSDBPoint

type OpenTSDBPoint struct {
	Metric    string            `json:"metric"`
	Value     interface{}       `json:"value"`
	Timestamp int64             `json:"timestamp"`
	Tags      map[string]string `json:"tags"`
}

type PrefixedTaggedRegistry

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

Provide a single set of tags and a prefix for all metrics in registry

func (*PrefixedTaggedRegistry) Add

func (r *PrefixedTaggedRegistry) Add(name string, tags Tags, i interface{}) error

func (*PrefixedTaggedRegistry) Each

func (r *PrefixedTaggedRegistry) Each(fn func(string, TaggedMetric))

Call the given function for each registered metric.

func (*PrefixedTaggedRegistry) Get

func (r *PrefixedTaggedRegistry) Get(name string, tags Tags) interface{}

Get the metric by the given name or nil if none is registered.

func (*PrefixedTaggedRegistry) GetOrRegister

func (r *PrefixedTaggedRegistry) GetOrRegister(name string, tags Tags, i interface{}) interface{}

Gets an existing metric or registers the given one. The interface can be the metric to register if not found in registry, or a function returning the metric for lazy instantiation.

func (*PrefixedTaggedRegistry) Register

func (r *PrefixedTaggedRegistry) Register(name string, tags Tags, i interface{}) error

Register the given metric under the given name. The name will be prefixed.

func (*PrefixedTaggedRegistry) RunHealthchecks

func (r *PrefixedTaggedRegistry) RunHealthchecks()

Run all registered healthchecks.

func (*PrefixedTaggedRegistry) Unregister

func (r *PrefixedTaggedRegistry) Unregister(name string, tags Tags)

Unregister the metric with the given name. The name will be prefixed.

func (*PrefixedTaggedRegistry) UnregisterAll

func (r *PrefixedTaggedRegistry) UnregisterAll()

Unregister all metrics. (Mostly for testing.)

func (*PrefixedTaggedRegistry) UnregisterMetric

func (r *PrefixedTaggedRegistry) UnregisterMetric(i interface{})

Unregister the metric using the Metric object itself.

func (*PrefixedTaggedRegistry) WrappedEach

func (r *PrefixedTaggedRegistry) WrappedEach(wrapperFn func(string, TaggedMetric) (string, TaggedMetric), fn func(string, TaggedMetric))

type SegmentedTaggedRegistry

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

func (*SegmentedTaggedRegistry) Add

func (r *SegmentedTaggedRegistry) Add(name string, tags Tags, i interface{}) error

func (*SegmentedTaggedRegistry) Each

func (r *SegmentedTaggedRegistry) Each(fn func(string, TaggedMetric))

Call the given function for each registered metric.

func (*SegmentedTaggedRegistry) Get

func (r *SegmentedTaggedRegistry) Get(name string, tags Tags) interface{}

Get the metric by the given name or nil if none is registered.

func (*SegmentedTaggedRegistry) GetName

func (r *SegmentedTaggedRegistry) GetName(name string) string

func (*SegmentedTaggedRegistry) GetOrRegister

func (r *SegmentedTaggedRegistry) GetOrRegister(name string, tags Tags, i interface{}) interface{}

Gets an existing metric or registers the given one. The interface can be the metric to register if not found in registry, or a function returning the metric for lazy instantiation.

func (*SegmentedTaggedRegistry) GetPrefix

func (r *SegmentedTaggedRegistry) GetPrefix() string

func (*SegmentedTaggedRegistry) GetRootRegistry

func (r *SegmentedTaggedRegistry) GetRootRegistry() TaggedRegistry

func (*SegmentedTaggedRegistry) GetTags

func (r *SegmentedTaggedRegistry) GetTags(t Tags) Tags

func (*SegmentedTaggedRegistry) Register

func (r *SegmentedTaggedRegistry) Register(name string, tags Tags, i interface{}) error

Register the given metric under the given name. The name will be prefixed.

func (*SegmentedTaggedRegistry) RunHealthchecks

func (r *SegmentedTaggedRegistry) RunHealthchecks()

Run all registered healthchecks.

func (*SegmentedTaggedRegistry) Unregister

func (r *SegmentedTaggedRegistry) Unregister(name string, tags Tags)

Unregister the metric with the given name. The name will be prefixed.

func (*SegmentedTaggedRegistry) UnregisterAll

func (r *SegmentedTaggedRegistry) UnregisterAll()

Unregister all metrics. (Mostly for testing.)

func (*SegmentedTaggedRegistry) UnregisterMetric

func (r *SegmentedTaggedRegistry) UnregisterMetric(i interface{})

Unregister the metric using the Metric object itself.

func (*SegmentedTaggedRegistry) WrappedEach

func (r *SegmentedTaggedRegistry) WrappedEach(wrapperFn func(string, TaggedMetric) (string, TaggedMetric), fn func(string, TaggedMetric))

type TaggedMetric

type TaggedMetric interface {
	GetTags() Tags
	GetMetric() interface{}
	GetTagsID() TagsID
	TagString() string

	AddTags(Tags) TaggedMetric
}

type TaggedOpenTSDB

type TaggedOpenTSDB struct {
	Addr          string         // Network address to connect to
	Registry      TaggedRegistry // Registry to be exported
	FlushInterval time.Duration  // Flush interval
	DurationUnit  time.Duration  // Time conversion unit for durations
	Format        OpenTSDBFormat
	Compress      bool
	BulkSize      int

	Logger log.FieldLogger
	// contains filtered or unexported fields
}

TaggedOpenTSDBConfig provides a container with configuration parameters for the TaggedOpenTSDB exporter

Example
go TaggedOpenTSDB(context.Background(), DefaultTaggedRegistry, 1*time.Second, "some.prefix", ":2003", Tcollector)
Output:

func (*TaggedOpenTSDB) Export

func (t *TaggedOpenTSDB) Export() error

func (*TaggedOpenTSDB) Run

func (t *TaggedOpenTSDB) Run(ctx context.Context)

TaggedOpenTSDBWithConfig is a blocking exporter function just like TaggedOpenTSDB, but it takes a TaggedOpenTSDBConfig instead.

func (*TaggedOpenTSDB) RunWithPreprocessing

func (t *TaggedOpenTSDB) RunWithPreprocessing(ctx context.Context, fn []func(TaggedRegistry))

func (*TaggedOpenTSDB) RunWithProcessing

func (t *TaggedOpenTSDB) RunWithProcessing(ctx context.Context, preFn, postFn []func(TaggedRegistry))

type TaggedRegistry

type TaggedRegistry interface {
	// Call the given function for each registered metric.
	Each(func(string, TaggedMetric))
	WrappedEach(func(string, TaggedMetric) (string, TaggedMetric), func(string, TaggedMetric))

	// Get the metric by the given name or nil if none is registered.
	Get(string, Tags) interface{}

	// Gets an existing metric or registers the given one.
	// The interface can be the metric to register if not found in registry,
	// or a function returning the metric for lazy instantiation.
	GetOrRegister(string, Tags, interface{}) interface{}

	// Register the given metric under the given name.
	Register(string, Tags, interface{}) error

	// Add() will add metrics that will be reported a single time
	// without getting registered
	Add(string, Tags, interface{}) error

	// Run all registered healthchecks.
	RunHealthchecks()

	// Unregister the metric with the given name.
	Unregister(string, Tags)

	// Unregister the metric using the Metric object itself.
	UnregisterMetric(interface{})

	// Unregister all metrics.  (Mostly for testing.)
	UnregisterAll()
}

This is an interface so as to encourage other structs to implement the Registry API as appropriate.

func NewPrefixedTaggedRegistry

func NewPrefixedTaggedRegistry(prefix string, tags Tags) TaggedRegistry

func NewRootSegmentedTaggedRegistry

func NewRootSegmentedTaggedRegistry(tags Tags) TaggedRegistry

func NewSegmentedTaggedRegistry

func NewSegmentedTaggedRegistry(prefix string, tags Tags, parentRegistry TaggedRegistry) TaggedRegistry

func NewTaggedRegistry

func NewTaggedRegistry() TaggedRegistry

Create a new registry.

type Tags

type Tags map[string]string

func TagsFromString

func TagsFromString(tags string) (Tags, error)

func (Tags) AddTags

func (tm Tags) AddTags(tags Tags) Tags

func (Tags) String

func (tm Tags) String() string

func (Tags) TagsID

func (tm Tags) TagsID() TagsID

type TagsID

type TagsID string

Jump to

Keyboard shortcuts

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