Skip to content

Commit

Permalink
enable metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
cmwaters committed Jul 19, 2024
1 parent 8f63838 commit 71b752e
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 17 deletions.
28 changes: 13 additions & 15 deletions consensus/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
}
2 changes: 2 additions & 0 deletions consensus/reactor.go
Original file line number Diff line number Diff line change
Expand Up @@ -694,6 +694,7 @@ OUTER_LOOP:
},
}, logger) {
ps.SetHasBlock(prs.Height, prs.Round)
conR.conS.jsonMetrics.SentCompactBlocks++
}
continue OUTER_LOOP
}
Expand Down Expand Up @@ -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
Expand Down
8 changes: 7 additions & 1 deletion consensus/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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)",
Expand Down
5 changes: 4 additions & 1 deletion mempool/cat/pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down

0 comments on commit 71b752e

Please sign in to comment.