ipfs-cluster: github.com/ipfs/ipfs-cluster/monitor/metrics Index | Files

package metrics

import "github.com/ipfs/ipfs-cluster/monitor/metrics"

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


Package Files

checker.go prob.go store.go util.go window.go


var AlertChannelCap = 256

AlertChannelCap specifies how much buffer the alerts channel has.

var DefaultWindowCap = 25

DefaultWindowCap sets the amount of metrics to store per peer.

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

ErrAlertChannelFull is returned if the alert channel is full.

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

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

var MaxAlertThreshold = 1

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

func PeersetFilter Uses

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

PeersetFilter removes all metrics not belonging to the given peerset

type Checker Uses

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 Uses

func NewChecker(ctx context.Context, metrics *Store, threshold float64) *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 Uses

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

Alerts returns a channel which gets notified by CheckPeers.

func (*Checker) CheckAll Uses

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 Uses

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 Uses

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) Watch Uses

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 Uses

type PeerMetrics map[peer.ID]*Window

PeerMetrics maps a peer IDs to a metrics window.

type Store Uses

type Store struct {
    // contains filtered or unexported fields

Store can be used to store and access metrics.

func NewStore Uses

func NewStore() *Store

NewStore can be used to create a Store.

func (*Store) Add Uses

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

Add inserts a new metric in Metrics.

func (*Store) AllMetrics Uses

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

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

func (*Store) Distribution Uses

func (mtrs *Store) Distribution(name string, pid peer.ID) []float64

Distribution returns the distribution of a particular metrics for a particular peer.

func (*Store) LatestValid Uses

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 Uses

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

MetricNames returns all the known metric names

func (*Store) PeerLatest Uses

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 Uses

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 Uses

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 Uses

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

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

func (*Store) RemovePeerMetrics Uses

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

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

type Window Uses

type Window struct {
    // contains filtered or unexported fields

Window implements a circular queue to store metrics.

func NewWindow Uses

func NewWindow(windowCap int) *Window

NewWindow creates an instance with the given window capacity.

func (*Window) Add Uses

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 Uses

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) Distribution Uses

func (mw *Window) Distribution() []float64

Distribution returns the deltas between all the current values contained in the current window. This will only return values if the api.Metric.Type() is "ping", which are used for accural failure detection.

func (*Window) Latest Uses

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

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

Package metrics imports 13 packages (graph) and is imported by 1 packages. Updated 2020-10-24. Refresh now. Tools for package owners.