metrics

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: May 6, 2022 License: Apache-2.0, MIT, Apache-2.0, + 1 more Imports: 8 Imported by: 0

Documentation

Overview

Package metrics provides common functionality for working with metrics, particularly useful for monitoring components. It includes types to store, check and filter metrics.

Index

Constants

This section is empty.

Variables

View Source
var AlertChannelCap = 256

AlertChannelCap specifies how much buffer the alerts channel has.

View Source
var DefaultWindowCap = 25

DefaultWindowCap sets the amount of metrics to store per peer.

View Source
var ErrAlertChannelFull = errors.New("alert channel is full")

ErrAlertChannelFull is returned if the alert channel is full.

View Source
var ErrNoMetrics = errors.New("no metrics have been added to this window")

ErrNoMetrics is returned when there are no metrics in a Window.

View Source
var MaxAlertThreshold = 1

MaxAlertThreshold specifies how many alerts will occur per a peer is removed from the list of monitored peers.

Functions

func PeersetFilter

func PeersetFilter(metrics []api.Metric, peerset []peer.ID) []api.Metric

PeersetFilter removes all metrics not belonging to the given peerset

Types

type Checker

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

Checker provides utilities to find expired metrics for a given peerset and send alerts if it proceeds to do so.

func NewChecker

func NewChecker(ctx context.Context, metrics *Store) *Checker

NewChecker creates a Checker using the given MetricsStore. The threshold value indicates when a monitored component should be considered to have failed. The greater the threshold value the more leniency is granted.

A value between 2.0 and 4.0 is suggested for the threshold.

func (*Checker) Alerts

func (mc *Checker) Alerts() <-chan api.Alert

Alerts returns a channel which gets notified by CheckPeers.

func (*Checker) CheckAll added in v0.11.0

func (mc *Checker) CheckAll() error

CheckAll will trigger alerts for all latest metrics when they have expired and no alert has been sent before.

func (*Checker) CheckPeers

func (mc *Checker) CheckPeers(peers []peer.ID) error

CheckPeers will trigger alerts based on the latest metrics from the given peerset when they have expired and no alert has been sent before.

func (*Checker) FailedMetric added in v0.11.0

func (mc *Checker) FailedMetric(metric string, pid peer.ID) bool

FailedMetric returns if a peer is marked as failed for a particular metric.

func (*Checker) ResetAlerts added in v0.14.5

func (mc *Checker) ResetAlerts(pid peer.ID, metricName string)

ResetAlerts clears up how many time a peer alerted for a given metric. Thus, if it was over the threshold, it will start alerting again.

func (*Checker) Watch

func (mc *Checker) Watch(ctx context.Context, peersF func(context.Context) ([]peer.ID, error), interval time.Duration)

Watch will trigger regular CheckPeers on the given interval. It will call peersF to obtain a peerset. It can be stopped by cancelling the context. Usually you want to launch this in a goroutine.

type PeerMetrics

type PeerMetrics map[peer.ID]*Window

PeerMetrics maps a peer IDs to a metrics window.

type Store

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

Store can be used to store and access metrics.

func NewStore

func NewStore() *Store

NewStore can be used to create a Store.

func (*Store) Add

func (mtrs *Store) Add(m api.Metric)

Add inserts a new metric in Metrics.

func (*Store) AllMetrics added in v0.11.0

func (mtrs *Store) AllMetrics() []api.Metric

AllMetrics returns the latest metrics for all peers and metrics types. It may return expired metrics.

func (*Store) LatestValid added in v0.11.0

func (mtrs *Store) LatestValid(name string) []api.Metric

LatestValid returns all the last known valid metrics of a given type. A metric is valid if it has not expired.

func (*Store) MetricNames added in v0.11.0

func (mtrs *Store) MetricNames() []string

MetricNames returns all the known metric names

func (*Store) PeerLatest added in v0.11.0

func (mtrs *Store) PeerLatest(name string, pid peer.ID) api.Metric

PeerLatest returns the latest of a particular metric for a particular peer. It may return an expired metric.

func (*Store) PeerMetricAll added in v0.11.0

func (mtrs *Store) PeerMetricAll(name string, pid peer.ID) []api.Metric

PeerMetricAll returns all of a particular metrics for a particular peer.

func (*Store) PeerMetrics

func (mtrs *Store) PeerMetrics(pid peer.ID) []api.Metric

PeerMetrics returns the latest metrics for a given peer ID for all known metrics types. It may return expired metrics.

func (*Store) RemovePeer added in v0.11.0

func (mtrs *Store) RemovePeer(pid peer.ID)

RemovePeer removes all metrics related to a peer from the Store.

func (*Store) RemovePeerMetrics added in v0.11.0

func (mtrs *Store) RemovePeerMetrics(pid peer.ID, name string)

RemovePeerMetrics removes all metrics of a given name for a given peer ID.

type Window

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

Window implements a circular queue to store metrics.

func NewWindow

func NewWindow(windowCap int) *Window

NewWindow creates an instance with the given window capacity.

func (*Window) Add

func (mw *Window) Add(m api.Metric)

Add adds a new metric to the window. If the window capacity has been reached, the oldest metric (by the time it was added), will be discarded. Add leaves the cursor on the next spot, which is either empty or the oldest record.

func (*Window) All

func (mw *Window) All() []api.Metric

All returns all the metrics in the window, in the inverse order they were Added. That is, result[0] will be the last added metric.

func (*Window) Latest

func (mw *Window) Latest() (api.Metric, error)

Latest returns the last metric added. It returns an error if no metrics were added.

Jump to

Keyboard shortcuts

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