reporter.go 940 Bytes
Newer Older
tavit ohanian's avatar
tavit ohanian committed
1
// Package metrics provides metrics collection and reporting interfaces for p2p.
2 3 4
package metrics

import (
tavit ohanian's avatar
tavit ohanian committed
5 6
	"gitlab.dms3.io/p2p/go-p2p-core/peer"
	"gitlab.dms3.io/p2p/go-p2p-core/protocol"
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
)

// 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.
type Stats struct {
	TotalIn  int64
	TotalOut int64
	RateIn   float64
	RateOut  float64
}

// Reporter provides methods for logging and retrieving metrics.
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
}