Introduce sent blocks histogram
License: MIT Signed-off-by: Jakub Sztandera <kubuxu@protonmail.ch>
Jakub Sztandera committed
Jan 20, 2017 at 18:40 UTC
acfaf9ac8953c13c9a3b925c20bfb046ca305d60
2 files changed
+21
-15
exchange/bitswap/bitswap.go
+2
-2
@@ -79,9 +79,9 @@ func New(parent context.Context, p peer.ID, network bsnet.BitSwapNetwork,
79
// exclusively. We should probably find another way to share logging data
80
ctx, cancelFunc := context.WithCancel(parent)
81
ctx = metrics.CtxSubScope(ctx, "bitswap")
82
- dupHist := metrics.NewCtx(ctx, "dup_blocks_bytes", "Summary of duplicate"+
82
+ dupHist := metrics.NewCtx(ctx, "recv_dup_blocks_bytes", "Summary of duplicate"+
83
" data blocks recived").Histogram(metricsBuckets)
84
- allHist := metrics.NewCtx(ctx, "all_blocks_bytes", "Summary of all"+
84
+ allHist := metrics.NewCtx(ctx, "recv_all_blocks_bytes", "Summary of all"+
85
" data blocks recived").Histogram(metricsBuckets)
86
87
notif := notifications.New()
exchange/bitswap/wantmanager.go
+19
-13
@@ -30,24 +30,28 @@ type WantManager struct {
30
ctx context.Context
31
cancel func()
32
33
- metricWantlist metrics.Gauge
33
+ wantlistGauge metrics.Gauge
34
+ sentHistogram metrics.Histogram
35
}
36
37
func NewWantManager(ctx context.Context, network bsnet.BitSwapNetwork) *WantManager {
38
ctx, cancel := context.WithCancel(ctx)
39
wantlistGauge := metrics.NewCtx(ctx, "wanlist_total",
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)
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,
55
}
56
}
57
@@ -116,6 +120,8 @@ func (pm *WantManager) SendBlock(ctx context.Context, env *engine.Envelope) {
120
// throughout the network stack
121
defer env.Sent()
122
123
+ pm.sentHistogram.Observe(float64(len(env.Block.RawData())))
124
+
125
msg := bsmsg.New(false)
126
msg.AddBlock(env.Block)
127
log.Infof("Sending block %s to %s", env.Block, env.Peer)
@@ -289,12 +295,12 @@ func (pm *WantManager) Run() {
295
for _, e := range entries {
296
if e.Cancel {
297
if pm.wl.Remove(e.Cid) {
292
- pm.metricWantlist.Dec()
298
+ pm.wantlistGauge.Dec()
299
filtered = append(filtered, e)
300
}
301
} else {
302
if pm.wl.AddEntry(e.Entry) {
297
- pm.metricWantlist.Inc()
303
+ pm.wantlistGauge.Inc()
304
filtered = append(filtered, e)
305
}
306
}