Skip to content

Commit

Permalink
metrics: don't export vochaininfo metrics during blocksync
Browse files Browse the repository at this point in the history
  • Loading branch information
altergui committed Mar 14, 2024
1 parent 204a472 commit 0f17620
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 11 deletions.
22 changes: 13 additions & 9 deletions vochain/vochaininfo/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,17 @@ package vochaininfo
import "github.com/VictoriaMetrics/metrics"

var (
height = metrics.NewCounter("vochain_height") // Height of the vochain (last block)
voteCount = metrics.NewCounter("vochain_vote_tree") // Total vote count
processTreeSize = metrics.NewCounter("vochain_process_tree") // Size of the process tree
accountTreeSize = metrics.NewCounter("vochain_account_tree") // Size of the account tree
sikTreeSize = metrics.NewCounter("vochain_sik_tree") // Size of the SIK tree
mempoolSize = metrics.NewCounter("vochain_mempool") // Number of Txs in the mempool
voteCacheSize = metrics.NewCounter("vochain_vote_cache") // Size of the current vote cache
blockPeriodMinute = metrics.NewCounter("vochain_block_period_minute") // Block period for the last minute
blocksSyncLastMinute = metrics.NewCounter("vochain_blocks_sync_minute") // Blocks synced the last minute
viMetrics = metrics.NewSet()
height = viMetrics.NewCounter("vochain_height") // Height of the vochain (last block)
voteCount = viMetrics.NewCounter("vochain_vote_tree") // Total vote count
processTreeSize = viMetrics.NewCounter("vochain_process_tree") // Size of the process tree
accountTreeSize = viMetrics.NewCounter("vochain_account_tree") // Size of the account tree
sikTreeSize = viMetrics.NewCounter("vochain_sik_tree") // Size of the SIK tree
mempoolSize = viMetrics.NewCounter("vochain_mempool") // Number of Txs in the mempool
voteCacheSize = viMetrics.NewCounter("vochain_vote_cache") // Size of the current vote cache
blockPeriodMinute = viMetrics.NewCounter("vochain_block_period_minute") // Block period for the last minute

blocksyncMetrics = metrics.NewSet()
blocksyncHeight = blocksyncMetrics.NewCounter("vochain_sync_height")
blocksyncBPM = blocksyncMetrics.NewCounter("vochain_sync_blocks_per_minute")
)
15 changes: 13 additions & 2 deletions vochain/vochaininfo/vochaininfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ func NewVochainInfo(node *vochain.BaseApplication) *VochainInfo {
}

func (vi *VochainInfo) updateCounters() {
if !vi.vnode.IsSynced() {
blocksyncHeight.Set(uint64(vi.vnode.Height()))
blocksyncBPM.Set(uint64(vi.BlocksLastMinute()))
return
}
height.Set(uint64(vi.vnode.Height()))

pc, err := vi.vnode.State.CountProcesses(true)
Expand Down Expand Up @@ -62,7 +67,6 @@ func (vi *VochainInfo) updateCounters() {
voteCacheSize.Set(uint64(vi.vnode.State.CacheSize()))
mempoolSize.Set(uint64(vi.vnode.MempoolSize()))
blockPeriodMinute.Set(uint64(vi.BlockTimes()[0].Milliseconds()))
blocksSyncLastMinute.Set(uint64(vi.BlocksLastMinute()))
}

// Height returns the current number of blocks of the blockchain.
Expand Down Expand Up @@ -258,7 +262,11 @@ func (vi *VochainInfo) Start(sleepSecs uint64) {
panic("sleepSecs cannot be zero")
}
log.Infof("starting vochain info service every %d seconds", sleepSecs)
metrics.NewGauge("vochain_tokens_burned",

metrics.UnregisterSet(viMetrics)
metrics.RegisterSet(blocksyncMetrics)

viMetrics.NewGauge("vochain_tokens_burned",
func() float64 { return float64(vi.TokensBurned()) })

var duration time.Duration
Expand All @@ -269,6 +277,9 @@ func (vi *VochainInfo) Start(sleepSecs uint64) {
duration = time.Second * time.Duration(sleepSecs)
for {
select {
case <-vi.vnode.WaitUntilSynced():
metrics.RegisterSet(viMetrics)
metrics.UnregisterSet(blocksyncMetrics)
case <-time.After(duration):
vi.updateCounters()
currentHeight = uint64(vi.vnode.Height())
Expand Down

0 comments on commit 0f17620

Please sign in to comment.