metrics

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: May 30, 2018 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package metrics provides common functionality for working with metrics, particulary 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.

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(metrics *Store) *Checker

NewChecker creates a Checker using the given MetricsStore.

func (*Checker) Alerts

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

Alerts returns a channel which gets notified by CheckPeers.

func (*Checker) CheckPeers

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

CheckPeers will trigger alerts for expired metrics belonging to the given peerset.

func (*Checker) Watch

func (mc *Checker) Watch(ctx context.Context, peersF func() ([]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) Latest

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

Latest returns all the last known valid metrics. A metric is valid if it has not expired.

func (*Store) PeerMetrics

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

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

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.

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