feat: wakuV2 bandwidth stats (#2325)
This commit is contained in:
parent
034f3bfec3
commit
719a303b05
1
go.mod
1
go.mod
|
@ -27,6 +27,7 @@ require (
|
|||
github.com/kilic/bls12-381 v0.0.0-20200607163746-32e1441c8a9f
|
||||
github.com/leodido/go-urn v1.2.0 // indirect
|
||||
github.com/lib/pq v1.9.0
|
||||
github.com/libp2p/go-libp2p v0.13.0
|
||||
github.com/libp2p/go-libp2p-core v0.8.5
|
||||
github.com/lucasb-eyer/go-colorful v1.0.3
|
||||
github.com/mat/besticon v0.0.0-20210314201728-1579f269edb7
|
||||
|
|
|
@ -43,6 +43,9 @@ import (
|
|||
"github.com/ethereum/go-ethereum/p2p"
|
||||
"github.com/ethereum/go-ethereum/rpc"
|
||||
|
||||
"github.com/libp2p/go-libp2p"
|
||||
"github.com/libp2p/go-libp2p-core/metrics"
|
||||
|
||||
wakuprotocol "github.com/status-im/go-waku/waku/v2/protocol"
|
||||
"github.com/status-im/go-waku/waku/v2/protocol/relay"
|
||||
|
||||
|
@ -78,7 +81,7 @@ type Waku struct {
|
|||
expirations map[uint32]mapset.Set // Message expiration pool
|
||||
poolMu sync.RWMutex // Mutex to sync the message and expiration pools
|
||||
|
||||
stats *common.StatsTracker
|
||||
bandwidthCounter *metrics.BandwidthCounter
|
||||
|
||||
msgQueue chan *common.ReceivedMessage // Message queue for waku messages that havent been decoded
|
||||
quit chan struct{} // Channel used for graceful exit
|
||||
|
@ -122,7 +125,7 @@ func New(nodeKey string, cfg *Config, logger *zap.Logger) (*Waku, error) {
|
|||
}
|
||||
|
||||
waku.filters = common.NewFilters()
|
||||
waku.stats = &common.StatsTracker{}
|
||||
waku.bandwidthCounter = metrics.NewBandwidthCounter()
|
||||
|
||||
var privateKey *ecdsa.PrivateKey
|
||||
var err error
|
||||
|
@ -143,6 +146,9 @@ func New(nodeKey string, cfg *Config, logger *zap.Logger) (*Waku, error) {
|
|||
}
|
||||
|
||||
waku.node, err = node.New(context.Background(),
|
||||
node.WithLibP2POptions(
|
||||
libp2p.BandwidthReporter(waku.bandwidthCounter),
|
||||
),
|
||||
node.WithPrivateKey(privateKey),
|
||||
node.WithHostAddress([]net.Addr{hostAddr}),
|
||||
node.WithWakuRelay(wakurelay.WithMaxMessageSize(int(waku.settings.MaxMsgSize))),
|
||||
|
@ -180,7 +186,11 @@ func New(nodeKey string, cfg *Config, logger *zap.Logger) (*Waku, error) {
|
|||
}
|
||||
|
||||
func (w *Waku) GetStats() types.StatsSummary {
|
||||
return w.stats.GetStats()
|
||||
stats := w.bandwidthCounter.GetBandwidthTotals()
|
||||
return types.StatsSummary{
|
||||
UploadRate: uint64(stats.RateOut),
|
||||
DownloadRate: uint64(stats.RateIn),
|
||||
}
|
||||
}
|
||||
|
||||
func (w *Waku) runMsgLoop() {
|
||||
|
|
Loading…
Reference in New Issue