metrics

package
v0.10.4 Latest Latest
Warning

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

Go to latest
Published: Jun 1, 2021 License: GPL-3.0 Imports: 24 Imported by: 7

Documentation

Index

Constants

View Source
const PrometheusFormatRequirement = "^" + prometheusBaseFormt + "$"

Variables

View Source
var (
	CfgOptionInstanceKey = "core/metrics/instance"

	CfgOptionPushKey = "core/metrics/push"
)

Configuration Keys

View Source
var (

	// ErrAlreadyStarted is returned when an operation is only valid before the
	// first metric is registered, and is called after.
	ErrAlreadyStarted = errors.New("can only be changed before first metric is registered")

	// ErrAlreadyRegistered is returned when a metric with the same ID is
	// registered again.
	ErrAlreadyRegistered = errors.New("metric already registered")

	// ErrAlreadySet is returned when a value is already set and cannot be changed.
	ErrAlreadySet = errors.New("already set")
)
View Source
var (

	// ErrAlreadyInitialized is returned when trying to initialize an option
	// more than once.
	ErrAlreadyInitialized = errors.New("already initialized")
)

Functions

func AddGlobalLabel

func AddGlobalLabel(name, value string) error

AddGlobalLabel adds a global label to all metrics. Global labels must be added before any metric is registered. Does not affect golang runtime metrics.

func EnableMetricPersistence

func EnableMetricPersistence(key string) error

EnableMetricPersistence enables metric persistence for metrics that opted for it. They given key is the database key where the metric data will be persisted. This call also directly loads the stored data from the database. The returned error is only about loading the metrics, not about enabling persistence. May only be called once.

func SetNamespace

func SetNamespace(namespace string) error

SetNamespace sets the namespace for all metrics. It is prefixed to all metric IDs. It must be set before any metric is registered. Does not affect golang runtime metrics.

func WriteMetrics

func WriteMetrics(w io.Writer, permission api.Permission, expertiseLevel config.ExpertiseLevel)

WriteMetrics writes all metrics that match the given permission and expertiseLevel to the given writer.

Types

type Counter

type Counter struct {
	*vm.Counter
	// contains filtered or unexported fields
}

Counter is a counter metric.

func NewCounter

func NewCounter(id string, labels map[string]string, opts *Options) (*Counter, error)

NewCounter registers a new counter metric.

func (Counter) ID

func (m Counter) ID() string

ID returns the given ID of the metric.

func (Counter) LabeledID

func (m Counter) LabeledID() string

LabeledID returns the Prometheus-compatible labeled ID of the metric.

func (Counter) Opts

func (m Counter) Opts() *Options

Opts returns the metric options. They may not be modified.

func (Counter) WritePrometheus

func (m Counter) WritePrometheus(w io.Writer)

WritePrometheus writes the metric in the prometheus format to the given writer.

type Gauge

type Gauge struct {
	*vm.Gauge
	// contains filtered or unexported fields
}

Gauge is a gauge metric.

func NewGauge

func NewGauge(id string, labels map[string]string, fn func() float64, opts *Options) (*Gauge, error)

NewGauge registers a new gauge metric.

func (Gauge) ID

func (m Gauge) ID() string

ID returns the given ID of the metric.

func (Gauge) LabeledID

func (m Gauge) LabeledID() string

LabeledID returns the Prometheus-compatible labeled ID of the metric.

func (Gauge) Opts

func (m Gauge) Opts() *Options

Opts returns the metric options. They may not be modified.

func (Gauge) WritePrometheus

func (m Gauge) WritePrometheus(w io.Writer)

WritePrometheus writes the metric in the prometheus format to the given writer.

type Histogram

type Histogram struct {
	*vm.Histogram
	// contains filtered or unexported fields
}

Histogram is a histogram metric.

func NewHistogram

func NewHistogram(id string, labels map[string]string, opts *Options) (*Histogram, error)

NewHistogram registers a new histogram metric.

func (Histogram) ID

func (m Histogram) ID() string

ID returns the given ID of the metric.

func (Histogram) LabeledID

func (m Histogram) LabeledID() string

LabeledID returns the Prometheus-compatible labeled ID of the metric.

func (Histogram) Opts

func (m Histogram) Opts() *Options

Opts returns the metric options. They may not be modified.

func (Histogram) WritePrometheus

func (m Histogram) WritePrometheus(w io.Writer)

WritePrometheus writes the metric in the prometheus format to the given writer.

type Metric

type Metric interface {
	ID() string
	LabeledID() string
	Opts() *Options
	WritePrometheus(w io.Writer)
}

Metric represents one or more metrics.

type Options

type Options struct {
	// Name defines an optional human readable name for the metric.
	Name string

	// AlertLimit defines an upper limit that triggers an alert.
	AlertLimit float64

	// AlertTimeframe defines an optional timeframe in seconds for which the
	// AlertLimit should be interpreted in.
	AlertTimeframe float64

	// Permission defines the permission that is required to read the metric.
	Permission api.Permission

	// ExpertiseLevel defines the expertise level that the metric is meant for.
	ExpertiseLevel config.ExpertiseLevel

	// Persist enabled persisting the metric on shutdown and loading the previous
	// value at start. This is only supported for counters.
	Persist bool
}

Options can be used to set advanced metric settings.

Jump to

Keyboard shortcuts

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