blockstore: add Bloom fill ratio metric
License: MIT Signed-off-by: Jakub Sztandera <kubuxu@protonmail.ch>
Jakub Sztandera committed
Sep 6, 2016 at 09:46 UTC
5f0be2eaa94ca703ab0d64935f357ab11a0dec35
1 file changed
+18
-1
blocks/blockstore/bloom_cache.go
+18
-1
@@ -2,6 +2,7 @@ package blockstore
2
3
import (
4
"sync/atomic"
5
+ "time"
6
7
"github.com/ipfs/go-ipfs/blocks"
8
key "gx/ipfs/Qmce4Y4zg3sYr7xKM5UueS67vhNni6EeWgCRnb7MbLJMew/go-key"
@@ -23,9 +24,25 @@ func bloomCached(bs Blockstore, ctx context.Context, bloomSize, hashCount int) (
24
"Number of cache hits in bloom cache").Counter()
25
bc.total = metrics.NewCtx(ctx, "bloom_total",
26
"Total number of requests to bloom cache").Counter()
27
+
28
+ fill := metrics.NewCtx(ctx, "bloom_fill_ratio",
29
+ "Ratio of bloom filter fullnes, (updated once a minute)").Gauge()
30
+
31
bc.Invalidate()
32
go bc.Rebuild(ctx)
28
-
33
+ go func() {
34
+ <-bc.rebuildChan
35
+ t := time.NewTicker(1 * time.Minute)
36
+ for {
37
+ select {
38
+ case <-ctx.Done():
39
+ t.Stop()
40
+ return
41
+ case <-t.C:
42
+ fill.Set(bc.bloom.FillRatio())
43
+ }
44
+ }
45
+ }()
46
return bc, nil
47
}
48