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 ¶
- Variables
- func PeersetFilter(metrics []api.Metric, peerset []peer.ID) []api.Metric
- type Checker
- func (mc *Checker) Alerts() <-chan api.Alert
- func (mc *Checker) CheckAll() error
- func (mc *Checker) CheckPeers(peers []peer.ID) error
- func (mc *Checker) FailedMetric(metric string, pid peer.ID) bool
- func (mc *Checker) ResetAlerts(pid peer.ID, metricName string)
- func (mc *Checker) Watch(ctx context.Context, peersF func(context.Context) ([]peer.ID, error), ...)
- type PeerMetrics
- type Store
- func (mtrs *Store) Add(m api.Metric)
- func (mtrs *Store) AllMetrics() []api.Metric
- func (mtrs *Store) LatestValid(name string) []api.Metric
- func (mtrs *Store) MetricNames() []string
- func (mtrs *Store) PeerLatest(name string, pid peer.ID) api.Metric
- func (mtrs *Store) PeerMetricAll(name string, pid peer.ID) []api.Metric
- func (mtrs *Store) PeerMetrics(pid peer.ID) []api.Metric
- func (mtrs *Store) RemovePeer(pid peer.ID)
- func (mtrs *Store) RemovePeerMetrics(pid peer.ID, name string)
- type Window
Constants ¶
This section is empty.
Variables ¶
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.
Functions ¶
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 ¶
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) CheckAll ¶ added in v0.11.0
CheckAll will trigger alerts for all latest metrics when they have expired and no alert has been sent before.
func (*Checker) CheckPeers ¶
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
FailedMetric returns if a peer is marked as failed for a particular metric.
func (*Checker) ResetAlerts ¶ added in v0.14.5
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 ¶
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 (*Store) AllMetrics ¶ added in v0.11.0
AllMetrics returns the latest metrics for all peers and metrics types. It may return expired metrics.
func (*Store) LatestValid ¶ added in v0.11.0
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
MetricNames returns all the known metric names
func (*Store) PeerLatest ¶ added in v0.11.0
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
PeerMetricAll returns all of a particular metrics for a particular peer.
func (*Store) PeerMetrics ¶
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
RemovePeer removes all metrics related to a peer from the Store.
type Window ¶
type Window struct {
// contains filtered or unexported fields
}
Window implements a circular queue to store metrics.
func (*Window) Add ¶
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.