From 2b32c2e597a01412eb9a56503373590be7b10e48 Mon Sep 17 00:00:00 2001 From: vyzo Date: Fri, 5 Mar 2021 11:54:06 +0200 Subject: [PATCH] add some metrics --- blockstore/splitstore/splitstore.go | 23 +++++++++++++++++-- metrics/metrics.go | 34 +++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+), 2 deletions(-) diff --git a/blockstore/splitstore/splitstore.go b/blockstore/splitstore/splitstore.go index ac2711fa4..6a18e898e 100644 --- a/blockstore/splitstore/splitstore.go +++ b/blockstore/splitstore/splitstore.go @@ -21,6 +21,9 @@ import ( bstore "github.com/filecoin-project/lotus/blockstore" "github.com/filecoin-project/lotus/build" "github.com/filecoin-project/lotus/chain/types" + "github.com/filecoin-project/lotus/metrics" + + "go.opencensus.io/stats" ) var ( @@ -206,7 +209,11 @@ func (s *SplitStore) Get(cid cid.Cid) (blocks.Block, error) { return blk, nil case bstore.ErrNotFound: - return s.cold.Get(cid) + blk, err = s.cold.Get(cid) + if err != nil { + stats.Record(context.Background(), metrics.SplitstoreMiss.M(1)) + } + return blk, err default: return nil, err @@ -221,7 +228,11 @@ func (s *SplitStore) GetSize(cid cid.Cid) (int, error) { return size, nil case bstore.ErrNotFound: - return s.cold.GetSize(cid) + size, err = s.cold.GetSize(cid) + if err != nil { + stats.Record(context.Background(), metrics.SplitstoreMiss.M(1)) + } + return size, err default: return 0, err @@ -539,11 +550,14 @@ func (s *SplitStore) compact(curTs *types.TipSet) { log.Infow("current mark set size estimate", "size", s.markSetSize) } + start := time.Now() if s.fullCompaction { err = s.compactFull(curTs) } else { err = s.compactSimple(curTs) } + took := time.Since(start).Milliseconds() + stats.Record(context.Background(), metrics.SplitstoreCompactionTimeSeconds.M(float64(took)/1e3)) if err != nil { log.Errorf("COMPACTION ERROR: %s", err) @@ -650,6 +664,8 @@ func (s *SplitStore) compactSimple(curTs *types.TipSet) error { log.Infow("collection done", "took", time.Since(startCollect)) log.Infow("compaction stats", "hot", hotCnt, "cold", coldCnt) + stats.Record(context.Background(), metrics.SplitstoreCompactionHot.M(int64(hotCnt))) + stats.Record(context.Background(), metrics.SplitstoreCompactionCold.M(int64(coldCnt))) // Enter critical section atomic.StoreInt32(&s.critsection, 1) @@ -924,6 +940,9 @@ func (s *SplitStore) compactFull(curTs *types.TipSet) error { log.Infow("collection done", "took", time.Since(startCollect)) log.Infow("compaction stats", "hot", hotCnt, "cold", coldCnt, "dead", deadCnt) + stats.Record(context.Background(), metrics.SplitstoreCompactionHot.M(int64(hotCnt))) + stats.Record(context.Background(), metrics.SplitstoreCompactionCold.M(int64(coldCnt))) + stats.Record(context.Background(), metrics.SplitstoreCompactionDead.M(int64(deadCnt))) // Enter critical section atomic.StoreInt32(&s.critsection, 1) diff --git a/metrics/metrics.go b/metrics/metrics.go index 45869ea91..5428a81bc 100644 --- a/metrics/metrics.go +++ b/metrics/metrics.go @@ -82,6 +82,13 @@ var ( WorkerCallsReturnedCount = stats.Int64("sealing/worker_calls_returned_count", "Counter of returned worker tasks", stats.UnitDimensionless) WorkerCallsReturnedDuration = stats.Float64("sealing/worker_calls_returned_ms", "Counter of returned worker tasks", stats.UnitMilliseconds) WorkerUntrackedCallsReturned = stats.Int64("sealing/worker_untracked_calls_returned", "Counter of returned untracked worker tasks", stats.UnitDimensionless) + + // splitstore + SplitstoreMiss = stats.Int64("splitstore/miss", "Number of misses in hotstre access", stats.UnitDimensionless) + SplitstoreCompactionTimeSeconds = stats.Float64("splitstore/compaction_time", "Compaction time in seconds", stats.UnitSeconds) + SplitstoreCompactionHot = stats.Int64("splitstore/hot", "Number of hot blocks in last compaction", stats.UnitDimensionless) + SplitstoreCompactionCold = stats.Int64("splitstore/cold", "Number of cold blocks in last compaction", stats.UnitDimensionless) + SplitstoreCompactionDead = stats.Int64("splitstore/dead", "Number of dead blocks in last compaction", stats.UnitDimensionless) ) var ( @@ -222,6 +229,28 @@ var ( Aggregation: workMillisecondsDistribution, TagKeys: []tag.Key{TaskType, WorkerHostname}, } + + // splitstore + SplitstoreMissView = &view.View{ + Measure: SplitstoreMiss, + Aggregation: view.Count(), + } + SplitstoreCompactionTimeSecondsView = &view.View{ + Measure: SplitstoreCompactionTimeSeconds, + Aggregation: view.LastValue(), + } + SplitstoreCompactionHotView = &view.View{ + Measure: SplitstoreCompactionHot, + Aggregation: view.LastValue(), + } + SplitstoreCompactionColdView = &view.View{ + Measure: SplitstoreCompactionCold, + Aggregation: view.Sum(), + } + SplitstoreCompactionDeadView = &view.View{ + Measure: SplitstoreCompactionDead, + Aggregation: view.Sum(), + } ) // DefaultViews is an array of OpenCensus views for metric gathering purposes @@ -258,6 +287,11 @@ var ChainNodeViews = append([]*view.View{ PubsubDropRPCView, VMFlushCopyCountView, VMFlushCopyDurationView, + SplitstoreMissView, + SplitstoreCompactionTimeSecondsView, + SplitstoreCompactionHotView, + SplitstoreCompactionColdView, + SplitstoreCompactionDeadView, }, DefaultViews...) var MinerNodeViews = append([]*view.View{