metrics

package
v0.0.0-...-da72ffe Latest Latest
Warning

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

Go to latest
Published: May 16, 2025 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	PerformanceProtocolID protocol.ID = "/peerdns/performance/1.0.0"
)

Variables

This section is empty.

Functions

func PongHandler

func PongHandler(logger logger.Logger) func(s network.Stream)

Types

type Collector

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

Collector collects and updates utility metrics for peers.

Fields: - metrics: A map of peer IDs to their associated Metrics. - mu: A read-write mutex for synchronizing access to metrics. - weights: Weights assigned to different metrics for utility score calculation. - emaAlpha: Smoothing factor used in Exponential Moving Average calculations. - maxRespScore: Maximum cap for responsiveness to prevent extreme values.

func NewCollector

func NewCollector(ctx context.Context, logger logger.Logger, weights share.Metrics, emaAlpha float64, maxRespScore float64) *Collector

NewCollector initializes a new Collector with the provided weights and EMA alpha.

Parameters: - weights: Weights for each metric used in utility score calculation. - emaAlpha: Smoothing factor for Exponential Moving Average calculations. - maxRespScore: Maximum cap for responsiveness to prevent extreme values.

Returns: - A pointer to the initialized Collector.

func (*Collector) AdjustEmaAlpha

func (mc *Collector) AdjustEmaAlpha(newAlpha float64)

AdjustEmaAlpha dynamically adjusts the smoothing factor used in EMA calculations.

Parameters: - newAlpha: The new EMA alpha value to be set.

func (*Collector) CalculateUtilityScore

func (mc *Collector) CalculateUtilityScore(p peer.ID) float64

CalculateUtilityScore computes the overall utility score for a peer.

Parameters: - p: The peer ID of the peer for which the utility score is computed.

Returns: - The computed utility score as a float64.

func (*Collector) GetAllMetrics

func (mc *Collector) GetAllMetrics() map[peer.ID]*share.Metrics

GetAllMetrics returns a copy of all collected metrics.

Returns: - A map of peer IDs to their corresponding Metrics structs.

func (*Collector) GetMetrics

func (mc *Collector) GetMetrics(p peer.ID) *share.Metrics

GetMetrics retrieves the metrics for a given peer.

Parameters: - p: The peer ID of the peer whose metrics are retrieved.

Returns: - A pointer to the Metrics struct containing the peer's metrics.

func (*Collector) MapPeerToAddress

func (mc *Collector) MapPeerToAddress(p peer.ID, address types.Address)

func (*Collector) RemoveOldMetrics

func (mc *Collector) RemoveOldMetrics(threshold time.Duration)

RemoveOldMetrics removes metrics that haven't been updated within the specified threshold.

Parameters: - threshold: A duration specifying the age threshold for removing old metrics.

func (*Collector) UpdateBandwidthUsage

func (mc *Collector) UpdateBandwidthUsage(p peer.ID, value float64)

UpdateBandwidthUsage updates the bandwidth usage metric for a peer.

Parameters: - p: The peer ID of the peer being updated. - value: The new bandwidth usage value.

func (*Collector) UpdateComputational

func (mc *Collector) UpdateComputational(p peer.ID, value float64)

UpdateComputational updates the computational metric for a peer.

Parameters: - p: The peer ID of the peer being updated. - value: The new computational metric value.

func (*Collector) UpdateReliability

func (mc *Collector) UpdateReliability(p peer.ID, success bool)

UpdateReliability updates the reliability metric for a peer.

Parameters: - p: The peer ID of the peer being updated. - success: Indicates whether the communication attempt was successful.

func (*Collector) UpdateResponsiveness

func (mc *Collector) UpdateResponsiveness(p peer.ID, latency float64, success bool)

UpdateResponsiveness updates the responsiveness metric for a peer.

Parameters: - p: The peer ID of the peer being updated. - latency: The latency observed in communication with the peer. - success: Indicates whether the communication attempt was successful.

func (*Collector) UpdateStorage

func (mc *Collector) UpdateStorage(p peer.ID, value float64)

UpdateStorage updates the storage metric for a peer.

Parameters: - p: The peer ID of the peer being updated. - value: The new storage metric value.

func (*Collector) UpdateUptime

func (mc *Collector) UpdateUptime(p peer.ID, value float64)

UpdateUptime updates the uptime metric for a peer.

Parameters: - p: The peer ID of the peer being updated. - value: The new uptime metric value.

type PerformanceMonitor

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

PerformanceMonitor pings peers and collects performance metrics.

func NewPerformanceMonitor

func NewPerformanceMonitor(
	ctx context.Context,
	host host.Host,
	logger logger.Logger,
	obs *observability.Observability,
	collector *Collector,
	pingInterval time.Duration,
	concurrency int,
	metricsTimeout time.Duration,
	cleanupInterval time.Duration,
	cleanupThreshold time.Duration,
	stakingUpdateInterval time.Duration,
) *PerformanceMonitor

NewPerformanceMonitor initializes a new PerformanceMonitor.

func (*PerformanceMonitor) AdjustEmaAlpha

func (pm *PerformanceMonitor) AdjustEmaAlpha(newAlpha float64)

AdjustEmaAlpha dynamically adjusts the EMA smoothing factor.

func (*PerformanceMonitor) Start

func (pm *PerformanceMonitor) Start()

Start begins the peer monitoring and cleanup processes.

func (*PerformanceMonitor) Stop

func (pm *PerformanceMonitor) Stop()

Stop halts the performance monitoring process gracefully.

Jump to

Keyboard shortcuts

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