metrics

package
v0.0.0-...-08de2ff Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2023 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package metrics provides metrics collection and reporting interfaces for libp2p.

Package metrics provides metrics collection and reporting interfaces for libp2p.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BandwidthCounter

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

BandwidthCounter tracks incoming and outgoing data transferred by the local peer. Metrics are available for total bandwidth across all peers / protocols, as well as segmented by remote peer ID and protocol ID.

func NewBandwidthCounter

func NewBandwidthCounter() *BandwidthCounter

NewBandwidthCounter creates a new BandwidthCounter.

func (*BandwidthCounter) GetBandwidthByPeer

func (bwc *BandwidthCounter) GetBandwidthByPeer() map[peer.ID]Stats

GetBandwidthByPeer returns a map of all remembered peers and the bandwidth metrics with respect to each. This method may be very expensive.

func (*BandwidthCounter) GetBandwidthByProtocol

func (bwc *BandwidthCounter) GetBandwidthByProtocol() map[protocol.ID]Stats

GetBandwidthByProtocol returns a map of all remembered protocols and the bandwidth metrics with respect to each. This method may be moderately expensive.

func (*BandwidthCounter) GetBandwidthForPeer

func (bwc *BandwidthCounter) GetBandwidthForPeer(p peer.ID) (out Stats)

GetBandwidthForPeer returns a Stats struct with bandwidth metrics associated with the given peer.ID. The metrics returned include all traffic sent / received for the peer, regardless of protocol.

func (*BandwidthCounter) GetBandwidthForProtocol

func (bwc *BandwidthCounter) GetBandwidthForProtocol(proto protocol.ID) (out Stats)

GetBandwidthForProtocol returns a Stats struct with bandwidth metrics associated with the given protocol.ID. The metrics returned include all traffic sent / received for the protocol, regardless of which peers were involved.

func (*BandwidthCounter) GetBandwidthTotals

func (bwc *BandwidthCounter) GetBandwidthTotals() (out Stats)

GetBandwidthTotals returns a Stats struct with bandwidth metrics for all data sent / received by the local peer, regardless of protocol or remote peer IDs.

func (*BandwidthCounter) LogRecvMessage

func (bwc *BandwidthCounter) LogRecvMessage(size int64)

LogRecvMessage records the size of an incoming message without associating the bandwidth to a specific peer or protocol.

func (*BandwidthCounter) LogRecvMessageStream

func (bwc *BandwidthCounter) LogRecvMessageStream(size int64, proto protocol.ID, p peer.ID)

LogRecvMessageStream records the size of an incoming message over a single logical stream. Bandwidth is associated with the given protocol.ID and peer.ID.

func (*BandwidthCounter) LogSentMessage

func (bwc *BandwidthCounter) LogSentMessage(size int64)

LogSentMessage records the size of an outgoing message without associating the bandwidth to a specific peer or protocol.

func (*BandwidthCounter) LogSentMessageStream

func (bwc *BandwidthCounter) LogSentMessageStream(size int64, proto protocol.ID, p peer.ID)

LogSentMessageStream records the size of an outgoing message over a single logical stream. Bandwidth is associated with the given protocol.ID and peer.ID.

func (*BandwidthCounter) Reset

func (bwc *BandwidthCounter) Reset()

Reset clears all stats.

func (*BandwidthCounter) TrimIdle

func (bwc *BandwidthCounter) TrimIdle(since time.Time)

TrimIdle trims all timers idle since the given time.

type Reporter

type Reporter interface {
	LogSentMessage(int64)
	LogRecvMessage(int64)
	LogSentMessageStream(int64, protocol.ID, peer.ID)
	LogRecvMessageStream(int64, protocol.ID, peer.ID)
	GetBandwidthForPeer(peer.ID) Stats
	GetBandwidthForProtocol(protocol.ID) Stats
	GetBandwidthTotals() Stats
	GetBandwidthByPeer() map[peer.ID]Stats
	GetBandwidthByProtocol() map[protocol.ID]Stats
}

Reporter provides methods for logging and retrieving metrics.

type Stats

type Stats struct {
	TotalIn  int64
	TotalOut int64
	RateIn   float64
	RateOut  float64
}

Stats represents a point-in-time snapshot of bandwidth metrics.

The TotalIn and TotalOut fields record cumulative bytes sent / received. The RateIn and RateOut fields record bytes sent / received per second.

Jump to

Keyboard shortcuts

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