func (bwc *BandwidthCounter) LogRecvMessageStream(size int64, proto protocol.ID, p peer.ID) { meter := gm.GetOrRegisterMeter("/peer/in/"+string(p), bwc.reg) meter.Mark(size) pmeter := gm.GetOrRegisterMeter("/proto/in/"+string(proto), bwc.reg) pmeter.Mark(size) }
func NewBandwidthCounter() *BandwidthCounter { reg := gm.NewRegistry() return &BandwidthCounter{ totalIn: gm.GetOrRegisterMeter("totalIn", reg), totalOut: gm.GetOrRegisterMeter("totalOut", reg), reg: reg, } }
func (bwc *BandwidthCounter) GetBandwidthForProtocol(proto protocol.ID) (out Stats) { inMeter := gm.GetOrRegisterMeter(string("/proto/in/"+proto), bwc.reg).Snapshot() outMeter := gm.GetOrRegisterMeter(string("/proto/out/"+proto), bwc.reg).Snapshot() return Stats{ TotalIn: inMeter.Count(), TotalOut: outMeter.Count(), RateIn: inMeter.RateFine(), RateOut: outMeter.RateFine(), } }
func (bwc *BandwidthCounter) GetBandwidthForPeer(p peer.ID) (out Stats) { inMeter := gm.GetOrRegisterMeter("/peer/in/"+string(p), bwc.reg).Snapshot() outMeter := gm.GetOrRegisterMeter("/peer/out/"+string(p), bwc.reg).Snapshot() return Stats{ TotalIn: inMeter.Count(), TotalOut: outMeter.Count(), RateIn: inMeter.RateFine(), RateOut: outMeter.RateFine(), } }