selfstat

package
v1.30.2 Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2024 License: MIT Imports: 7 Imported by: 94

Documentation

Overview

Package selfstat is a package for tracking and collecting internal statistics about telegraf. Metrics can be registered using this package, and then incremented or set within your code. If the inputs.internal plugin is enabled, then all registered stats will be collected as they would by any other input plugin.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Metrics

func Metrics() []telegraf.Metric

Metrics returns all registered stats as telegraf metrics.

Types

type Registry added in v1.15.0

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

type Stat

type Stat interface {
	// Name is the name of the measurement
	Name() string

	// FieldName is the name of the measurement field
	FieldName() string

	// Tags is a tag map. Each time this is called a new map is allocated.
	Tags() map[string]string

	// Incr increments a regular stat by 'v'.
	// in the case of a timing stat, increment adds the timing to the cache.
	Incr(v int64)

	// Set sets a regular stat to 'v'.
	// in the case of a timing stat, set adds the timing to the cache.
	Set(v int64)

	// Get gets the value of the stat. In the case of timings, this returns
	// an average value of all timings received since the last call to Get().
	// If no timings were received, it returns the previous value.
	Get() int64
}

Stat is an interface for dealing with telegraf statistics collected on itself.

func Register

func Register(measurement, field string, tags map[string]string) Stat

Register registers the given measurement, field, and tags in the selfstat registry. If given an identical measurement, it will return the stat that's already been registered.

The returned Stat can be incremented by the consumer of Register(), and it's value will be returned as a telegraf metric when Metrics() is called.

func RegisterTiming

func RegisterTiming(measurement, field string, tags map[string]string) Stat

RegisterTiming registers the given measurement, field, and tags in the selfstat registry. If given an identical measurement, it will return the stat that's already been registered.

Timing stats differ from regular stats in that they accumulate multiple "timings" added to them, and will return the average when Get() is called. After Get() is called, the average is cleared and the next timing returned from Get() will only reflect timings added since the previous call to Get(). If Get() is called without receiving any new timings, then the previous value is used.

In other words, timings are an averaged metric that get cleared on each call to Get().

The returned Stat can be incremented by the consumer of Register(), and it's value will be returned as a telegraf metric when Metrics() is called.

Jump to

Keyboard shortcuts

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