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

package pubsubmon

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

Package pubsubmon implements a PeerMonitor component for IPFS Cluster that uses PubSub to send and receive metrics.


Package Files

config.go pubsubmon.go


const (
    DefaultCheckInterval    = 15 * time.Second
    DefaultFailureThreshold = 3.0

Default values for this Config.


var PubsubTopic = "monitor.metrics"

PubsubTopic specifies the topic used to publish Cluster metrics.

type Config Uses

type Config struct {

    CheckInterval time.Duration
    // FailureThreshold indicates when a peer should be considered failed.
    // The greater the threshold value the more leniency is granted.
    // A value between 2.0 and 4.0 is suggested for the threshold.
    FailureThreshold float64

Config allows to initialize a Monitor and customize some parameters.

func (*Config) ApplyEnvVars Uses

func (cfg *Config) ApplyEnvVars() error

ApplyEnvVars fills in any Config fields found as environment variables.

func (*Config) ConfigKey Uses

func (cfg *Config) ConfigKey() string

ConfigKey provides a human-friendly identifier for this type of Config.

func (*Config) Default Uses

func (cfg *Config) Default() error

Default sets the fields of this Config to sensible values.

func (*Config) LoadJSON Uses

func (cfg *Config) LoadJSON(raw []byte) error

LoadJSON sets the fields of this Config to the values defined by the JSON representation of it, as generated by ToJSON.

func (*Config) ToDisplayJSON Uses

func (cfg *Config) ToDisplayJSON() ([]byte, error)

ToDisplayJSON returns JSON config as a string.

func (*Config) ToJSON Uses

func (cfg *Config) ToJSON() ([]byte, error)

ToJSON generates a human-friendly JSON representation of this Config.

func (*Config) Validate Uses

func (cfg *Config) Validate() error

Validate checks that the fields of this Config have working values, at least in appearance.

type Monitor Uses

type Monitor struct {
    // contains filtered or unexported fields

Monitor is a component in charge of monitoring peers, logging metrics and detecting failures

func New Uses

func New(
    ctx context.Context,
    cfg *Config,
    psub *pubsub.PubSub,
    peers PeersFunc,
) (*Monitor, error)

New creates a new PubSub monitor, using the given host, config and PeersFunc. The PeersFunc can be nil. In this case, no metric filtering is done based on peers (any peer is considered part of the peerset).

func (*Monitor) Alerts Uses

func (mon *Monitor) Alerts() <-chan *api.Alert

Alerts returns a channel on which alerts are sent when the monitor detects a failure.

func (*Monitor) LatestMetrics Uses

func (mon *Monitor) LatestMetrics(ctx context.Context, name string) []*api.Metric

LatestMetrics returns last known VALID metrics of a given type. A metric is only valid if it has not expired and belongs to a current cluster peer.

func (*Monitor) LogMetric Uses

func (mon *Monitor) LogMetric(ctx context.Context, m *api.Metric) error

LogMetric stores a metric so it can later be retrieved.

func (*Monitor) MetricNames Uses

func (mon *Monitor) MetricNames(ctx context.Context) []string

MetricNames lists all metric names.

func (*Monitor) PublishMetric Uses

func (mon *Monitor) PublishMetric(ctx context.Context, m *api.Metric) error

PublishMetric broadcasts a metric to all current cluster peers.

func (*Monitor) SetClient Uses

func (mon *Monitor) SetClient(c *rpc.Client)

SetClient saves the given rpc.Client for later use

func (*Monitor) Shutdown Uses

func (mon *Monitor) Shutdown(ctx context.Context) error

Shutdown stops the peer monitor. It particular, it will not deliver any alerts.

type PeersFunc Uses

type PeersFunc func(context.Context) ([]peer.ID, error)

PeersFunc allows the Monitor to filter and discard metrics that do not belong to a given peerset.

Package pubsubmon imports 16 packages (graph) and is imported by 1 packages. Updated 2020-07-20. Refresh now. Tools for package owners.