Class Metrics

property

{import('../connection-manager')} connectionManager

property

{number} [computeThrottleMaxQueueSize = defaultOptions.computeThrottleMaxQueueSize]

property

{number} [computeThrottleTimeout = defaultOptions.computeThrottleTimeout]

property

{number[]} [movingAverageIntervals = defaultOptions.movingAverageIntervals]

property

{number} [maxOldPeersRetention = defaultOptions.maxOldPeersRetention]

Hierarchy

  • Metrics

Index

References

MetricsOptions

Re-exports MetricsOptions

MetricsProperties

Re-exports MetricsProperties

MultiaddrConnection

Re-exports MultiaddrConnection

PeerId

Re-exports PeerId

Constructors

constructor

Properties

_connectionManager

_connectionManager: ConnectionManager

_globalStats

_globalStats: Stats

_oldPeers

_oldPeers: any

Private _onMessage

_onMessage: any

Takes the metadata for a message and tracks it in the appropriate categories. If the protocol is present, protocol stats will also be tracked.

param
param

Remote peer

param

Protocol string the stream is running

param

One of ['in','out']

param

Size of the message

returns

_options

_options: any

_peerStats

_peerStats: Map<any, any>

_protocolStats

_protocolStats: Map<any, any>

_running

_running: boolean

Accessors

global

  • Gets the global Stats object

    Returns Stats

peers

  • get peers(): string[]
  • Returns a list of PeerId strings currently being tracked

    Returns string[]

protocols

  • get protocols(): string[]
  • Returns a list of all protocol strings currently being tracked.

    Returns string[]

Methods

forPeer

  • Returns the Stats object for the given PeerId whether it is a live peer, or in the disconnected peer LRU cache.

    Parameters

    Returns Stats

forProtocol

  • forProtocol(protocol: string): Stats
  • Returns the Stats object for the given protocol.

    Parameters

    • protocol: string

    Returns Stats

onPeerDisconnected

  • onPeerDisconnected(peerId: PeerId): void
  • Should be called when all connections to a given peer have closed. The Stats collection for the peer will be stopped and moved to an LRU for temporary retention.

    Parameters

    Returns void

start

  • start(): void
  • Must be called for stats to saved. Any data pushed for tracking will be ignored.

    Returns void

stop

  • stop(): void
  • Stops all averages timers and prevents new data from being tracked. Once stop is called, start must be called to resume stats tracking.

    Returns void

trackStream

  • Tracks data running through a given Duplex Iterable stream. If the peerId is not provided, a placeholder string will be created and returned. This allows lazy tracking of a peer when the peer is not yet known. When the PeerId is known, Metrics.updatePlaceholder should be called with the placeholder string returned from here, and the known PeerId.

    Parameters

    Returns MultiaddrConnection

    The peerId string or placeholder string

updatePlaceholder

  • updatePlaceholder(placeholder: PeerId, peerId: PeerId): void
  • Replaces the PeerId string with the given peerId. If stats are already being tracked for the given peerId, the placeholder stats will be merged with the existing stats.

    Parameters

    Returns void

Static mergeStats

  • Merges other into target. target will be modified and returned.

    Parameters

    Returns Stats