@@ -30,24 +30,28 @@ type WantManager struct {
30
30
ctx context.Context
31
31
cancel func ()
32
32
33
- metricWantlist metrics.Gauge
33
+ wantlistGauge metrics.Gauge
34
+ sentHistogram metrics.Histogram
34
35
}
35
36
36
37
func NewWantManager (ctx context.Context , network bsnet.BitSwapNetwork ) * WantManager {
37
38
ctx , cancel := context .WithCancel (ctx )
38
39
wantlistGauge := metrics .NewCtx (ctx , "wanlist_total" ,
39
40
"Number of items in wantlist." ).Gauge ()
41
+ sentHistogram := metrics .NewCtx (ctx , "sent_all_blocks_bytes" , "Histogram of blocks sent by" +
42
+ " this bitswap" ).Histogram (metricsBuckets )
40
43
return & WantManager {
41
- incoming : make (chan []* bsmsg.Entry , 10 ),
42
- connect : make (chan peer.ID , 10 ),
43
- disconnect : make (chan peer.ID , 10 ),
44
- peerReqs : make (chan chan []peer.ID ),
45
- peers : make (map [peer.ID ]* msgQueue ),
46
- wl : wantlist .NewThreadSafe (),
47
- network : network ,
48
- ctx : ctx ,
49
- cancel : cancel ,
50
- metricWantlist : wantlistGauge ,
44
+ incoming : make (chan []* bsmsg.Entry , 10 ),
45
+ connect : make (chan peer.ID , 10 ),
46
+ disconnect : make (chan peer.ID , 10 ),
47
+ peerReqs : make (chan chan []peer.ID ),
48
+ peers : make (map [peer.ID ]* msgQueue ),
49
+ wl : wantlist .NewThreadSafe (),
50
+ network : network ,
51
+ ctx : ctx ,
52
+ cancel : cancel ,
53
+ wantlistGauge : wantlistGauge ,
54
+ sentHistogram : sentHistogram ,
51
55
}
52
56
}
53
57
@@ -116,6 +120,8 @@ func (pm *WantManager) SendBlock(ctx context.Context, env *engine.Envelope) {
116
120
// throughout the network stack
117
121
defer env .Sent ()
118
122
123
+ pm .sentHistogram .Observe (float64 (len (env .Block .RawData ())))
124
+
119
125
msg := bsmsg .New (false )
120
126
msg .AddBlock (env .Block )
121
127
log .Infof ("Sending block %s to %s" , env .Block , env .Peer )
@@ -289,12 +295,12 @@ func (pm *WantManager) Run() {
289
295
for _ , e := range entries {
290
296
if e .Cancel {
291
297
if pm .wl .Remove (e .Cid ) {
292
- pm .metricWantlist .Dec ()
298
+ pm .wantlistGauge .Dec ()
293
299
filtered = append (filtered , e )
294
300
}
295
301
} else {
296
302
if pm .wl .AddEntry (e .Entry ) {
297
- pm .metricWantlist .Inc ()
303
+ pm .wantlistGauge .Inc ()
298
304
filtered = append (filtered , e )
299
305
}
300
306
}
0 commit comments