metrics

package
v2.1.0-rc2 Latest Latest
Warning

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

Go to latest
Published: May 13, 2024 License: BSD-3-Clause Imports: 9 Imported by: 0

Documentation

Overview

Package metrics provides service for collecting various metrics about peers. It is intended to be used with the kademlia where the metrics are collected.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Collector

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

Collector collects various metrics about peers specified be the swarm.Address.

func NewCollector

func NewCollector(db *shed.DB) (*Collector, error)

NewCollector is a convenient constructor for creating new Collector.

func (*Collector) Filter

func (c *Collector) Filter(addr swarm.Address, fop ...FilterOp) bool

Filter returns true if the addr does not pass any filter operation.

func (*Collector) Finalize

func (c *Collector) Finalize(t time.Time, remove bool) error

Finalize tries to log out all ongoing peer sessions.

func (*Collector) Flush

func (c *Collector) Flush() error

Flush sync the dirty in memory counters for all peers by flushing their values to the underlying storage.

func (*Collector) Inspect

func (c *Collector) Inspect(addr swarm.Address) *Snapshot

Inspect allows inspecting current snapshot for the given peer address by executing the inspection function.

func (*Collector) IsUnreachable

func (c *Collector) IsUnreachable(addr swarm.Address) bool

IsUnreachable returns true if the peer is unreachable.

func (*Collector) Record

func (c *Collector) Record(addr swarm.Address, rop ...RecordOp)

Record records a set of metrics for peer specified by the given address.

func (*Collector) Snapshot

func (c *Collector) Snapshot(t time.Time, addresses ...swarm.Address) map[string]*Snapshot

Snapshot returns the current state of the metrics collector for peer(s). The given time t is used to calculate the duration of the current session, if any. If an address or a set of addresses is specified then only metrics related to them will be returned, otherwise metrics for all peers will be returned. If the peer is still logged in, the session-related counters will be evaluated against the last seen time, which equals to the login time. If the peer is logged out, then the session counters will reflect its last session.

type Counters

type Counters struct {
	sync.Mutex

	ReachabilityStatus p2p.ReachabilityStatus
	Healthy            bool
	// contains filtered or unexported fields
}

Counters represents a collection of peer metrics mainly collected for statistics and debugging.

func (*Counters) MarshalJSON

func (cs *Counters) MarshalJSON() ([]byte, error)

MarshalJSON marshals just the persistent counters.

func (*Counters) UnmarshalJSON

func (cs *Counters) UnmarshalJSON(b []byte) (err error)

UnmarshalJSON unmarshal just the persistent counters.

type FilterOp

type FilterOp func(*Counters) bool

FilterOp is a function type used to filter peers on certain fields.

func Health

func Health(filterHealthy bool) FilterOp

Unreachable is used to filter unhealthy peers.

func Reachability

func Reachability(filterReachable bool) FilterOp

Reachable is used to filter reachable or unreachable peers based on r.

type PeerConnectionDirection

type PeerConnectionDirection string

PeerConnectionDirection represents peer connection direction.

const (
	PeerConnectionDirectionInbound  PeerConnectionDirection = "inbound"
	PeerConnectionDirectionOutbound PeerConnectionDirection = "outbound"
)

type RecordOp

type RecordOp func(*Counters)

RecordOp is a definition of a peer metrics Record operation whose execution modifies a specific metrics.

func IncSessionConnectionRetry

func IncSessionConnectionRetry() RecordOp

IncSessionConnectionRetry increments the session connection retry counter by 1.

func PeerHealth

func PeerHealth(isHealty bool) RecordOp

PeerHealth updates the last health status of a peers.

func PeerLatency

func PeerLatency(t time.Duration) RecordOp

PeerLatency records the average peer latency.

func PeerLogIn

func PeerLogIn(t time.Time, dir PeerConnectionDirection) RecordOp

PeerLogIn will first update the current last seen to the give time t and as the second it'll set the direction of the session connection to the given value. The force flag will force the peer re-login if he's already logged in. The time is set as Unix timestamp ignoring the timezone. The operation will panic if the given time is before the Unix epoch.

func PeerLogOut

func PeerLogOut(t time.Time) RecordOp

PeerLogOut will first update the connection session and total duration with the difference of the given time t and the current last seen value. As the second it'll also update the last seen peer metrics to the given time t. The time is set as Unix timestamp ignoring the timezone. The operation will panic if the given time is before the Unix epoch.

func PeerReachability

func PeerReachability(s p2p.ReachabilityStatus) RecordOp

PeerReachability updates the last reachability status.

type Snapshot

type Snapshot struct {
	LastSeenTimestamp          int64
	SessionConnectionRetry     uint64
	ConnectionTotalDuration    time.Duration
	SessionConnectionDuration  time.Duration
	SessionConnectionDirection PeerConnectionDirection
	LatencyEWMA                time.Duration
	Reachability               p2p.ReachabilityStatus
	Healthy                    bool
}

Snapshot represents a snapshot of peers' metrics counters.

Jump to

Keyboard shortcuts

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