diff --git a/vochain/vochaininfo/metrics.go b/vochain/vochaininfo/metrics.go index dbc5ec360..dd5b6e388 100644 --- a/vochain/vochaininfo/metrics.go +++ b/vochain/vochaininfo/metrics.go @@ -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") ) diff --git a/vochain/vochaininfo/vochaininfo.go b/vochain/vochaininfo/vochaininfo.go index ced70d6eb..d6a098e23 100644 --- a/vochain/vochaininfo/vochaininfo.go +++ b/vochain/vochaininfo/vochaininfo.go @@ -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) @@ -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. @@ -259,7 +263,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 @@ -270,6 +278,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())