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 ¶
- type Collector
- func (c *Collector) Finalize(t time.Time) error
- func (c *Collector) Flush(addresses ...swarm.Address) error
- func (c *Collector) Inspect(addr swarm.Address, fn func(ss *Snapshot))
- func (c *Collector) Record(addr swarm.Address, rop ...RecordOp)
- func (c *Collector) Snapshot(t time.Time, addresses ...swarm.Address) map[string]*Snapshot
- type Counters
- type PeerConnectionDirection
- type RecordOp
- type Snapshot
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 ¶
NewCollector is a convenient constructor for creating new Collector.
func (*Collector) Finalize ¶
Finalize logs out all ongoing peer sessions and flushes all in-memory metrics counters.
func (*Collector) Flush ¶
Flush sync the dirty in memory counters by flushing their values to the underlying storage. If an address or a set of addresses is specified then only counters related to them will be flushed, otherwise counters for all peers will be flushed.
func (*Collector) Inspect ¶
Inspect allows to inspect current snapshot for the given peer address by executing the inspection function.
func (*Collector) 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 ¶
Counters represents a collection of peer metrics mainly collected for statistics and debugging.
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 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 panics if the given time is before the Unix epoch.
func PeerLogOut ¶
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 panics if the given time is before the Unix epoch.
type Snapshot ¶
type Snapshot struct { LastSeenTimestamp int64 SessionConnectionRetry uint64 ConnectionTotalDuration time.Duration SessionConnectionDuration time.Duration SessionConnectionDirection PeerConnectionDirection }
Snapshot represents a snapshot of peers' metrics counters.
func (*Snapshot) HasAtMaxOneConnectionAttempt ¶
HasAtMaxOneConnectionAttempt returns true if the snapshot represents a new peer which has at maximum one session connection attempt but it still isn't logged in.