From 71b752ef662e1ecc56459126899792d90603ea82 Mon Sep 17 00:00:00 2001 From: Callum Waters Date: Fri, 19 Jul 2024 17:02:42 +0200 Subject: [PATCH] enable metrics --- consensus/metrics.go | 28 +++++++++++++--------------- consensus/reactor.go | 2 ++ consensus/state.go | 8 +++++++- mempool/cat/pool.go | 5 ++++- 4 files changed, 26 insertions(+), 17 deletions(-) diff --git a/consensus/metrics.go b/consensus/metrics.go index 2f454e17b3..303f0f0cd5 100644 --- a/consensus/metrics.go +++ b/consensus/metrics.go @@ -334,18 +334,17 @@ func (m *Metrics) MarkStep(s cstypes.RoundStepType) { } type JSONMetrics struct { - dir string - interval int - StartTime time.Time - EndTime time.Time - Blocks uint64 - Rounds uint64 - SentConsensusBytes uint64 - SentCompactBlocks uint64 - SentCompactBytes uint64 - CompactBlockFailures uint64 - SentBlockParts uint64 - SentBlockPartsBytes uint64 + dir string + interval int + StartTime time.Time + EndTime time.Time + Blocks uint64 + Rounds uint64 + SentCompactBlocks uint64 + CompactBlockFailures uint64 + SentBlockParts uint64 + ReceivedBlockParts uint64 + ReceivedCompactBlocks uint64 } func NewJSONMetrics(dir string) *JSONMetrics { @@ -371,10 +370,9 @@ func (m *JSONMetrics) Save() { func (m *JSONMetrics) reset() { m.Blocks = 0 m.Rounds = 0 - m.SentConsensusBytes = 0 m.SentBlockParts = 0 - m.SentBlockPartsBytes = 0 m.SentCompactBlocks = 0 - m.SentCompactBytes = 0 m.CompactBlockFailures = 0 + m.ReceivedBlockParts = 0 + m.ReceivedCompactBlocks = 0 } diff --git a/consensus/reactor.go b/consensus/reactor.go index e1fa75a972..f55fe6647d 100644 --- a/consensus/reactor.go +++ b/consensus/reactor.go @@ -694,6 +694,7 @@ OUTER_LOOP: }, }, logger) { ps.SetHasBlock(prs.Height, prs.Round) + conR.conS.jsonMetrics.SentCompactBlocks++ } continue OUTER_LOOP } @@ -840,6 +841,7 @@ func (conR *Reactor) gossipDataForCatchup(logger log.Logger, rs *cstypes.RoundSt string(peer.ID()), schema.Upload, ) + conR.conS.jsonMetrics.SentBlockParts++ } else { logger.Debug("Sending block part for catchup failed") // sleep to avoid retrying too fast diff --git a/consensus/state.go b/consensus/state.go index a557c5294f..59109f39ec 100644 --- a/consensus/state.go +++ b/consensus/state.go @@ -1801,7 +1801,11 @@ func (cs *State) finalizeCommit(height int64) { // NewHeightStep! cs.updateToState(stateCopy) - cs.jsonMetrics.Save() + cs.jsonMetrics.Blocks++ + // Save every 20 blocks + if cs.Height%20 == 0 { + cs.jsonMetrics.Save() + } fail.Fail() // XXX @@ -2003,6 +2007,7 @@ func (cs *State) addCompactBlock(msg *CompactBlockMessage, peerID p2p.ID) error blockHash := cs.Proposal.BlockID.Hash timeout := cs.config.Propose(cs.Round) + cs.jsonMetrics.ReceivedCompactBlocks++ // Yield the lock while we fetch the transactions from the mempool so that votes // and other operations can be processed. @@ -2098,6 +2103,7 @@ func (cs *State) addProposalBlockPart(msg *BlockPartMessage, peerID p2p.ID) (add } cs.metrics.BlockGossipPartsReceived.With("matches_current", "true").Add(1) + cs.jsonMetrics.ReceivedBlockParts++ if cs.ProposalBlockParts.ByteSize() > cs.state.ConsensusParams.Block.MaxBytes { return added, fmt.Errorf("total size of proposal block parts exceeds maximum block bytes (%d > %d)", diff --git a/mempool/cat/pool.go b/mempool/cat/pool.go index 0d98632a29..35d7e9c74b 100644 --- a/mempool/cat/pool.go +++ b/mempool/cat/pool.go @@ -559,7 +559,10 @@ func (txmp *TxPool) Update( txmp.notifyTxsAvailable() } } - txmp.jsonMetrics.Save() + // save every 20 blocks + if blockHeight%20 == 0 { + txmp.jsonMetrics.Save() + } return nil }