Skip to content

Commit 89811ab

Browse files
committed
metrics: don't export vochaininfo metrics during blocksync
1 parent 77480ae commit 89811ab

2 files changed

Lines changed: 26 additions & 11 deletions

File tree

vochain/vochaininfo/metrics.go

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,17 @@ package vochaininfo
33
import "github.com/VictoriaMetrics/metrics"
44

55
var (
6-
height = metrics.NewCounter("vochain_height") // Height of the vochain (last block)
7-
voteCount = metrics.NewCounter("vochain_vote_tree") // Total vote count
8-
processTreeSize = metrics.NewCounter("vochain_process_tree") // Size of the process tree
9-
accountTreeSize = metrics.NewCounter("vochain_account_tree") // Size of the account tree
10-
sikTreeSize = metrics.NewCounter("vochain_sik_tree") // Size of the SIK tree
11-
mempoolSize = metrics.NewCounter("vochain_mempool") // Number of Txs in the mempool
12-
voteCacheSize = metrics.NewCounter("vochain_vote_cache") // Size of the current vote cache
13-
blockPeriodMinute = metrics.NewCounter("vochain_block_period_minute") // Block period for the last minute
14-
blocksSyncLastMinute = metrics.NewCounter("vochain_blocks_sync_minute") // Blocks synced the last minute
6+
viMetrics = metrics.NewSet()
7+
height = viMetrics.NewCounter("vochain_height") // Height of the vochain (last block)
8+
voteCount = viMetrics.NewCounter("vochain_vote_tree") // Total vote count
9+
processTreeSize = viMetrics.NewCounter("vochain_process_tree") // Size of the process tree
10+
accountTreeSize = viMetrics.NewCounter("vochain_account_tree") // Size of the account tree
11+
sikTreeSize = viMetrics.NewCounter("vochain_sik_tree") // Size of the SIK tree
12+
mempoolSize = viMetrics.NewCounter("vochain_mempool") // Number of Txs in the mempool
13+
voteCacheSize = viMetrics.NewCounter("vochain_vote_cache") // Size of the current vote cache
14+
blockPeriodMinute = viMetrics.NewCounter("vochain_block_period_minute") // Block period for the last minute
15+
16+
blocksyncMetrics = metrics.NewSet()
17+
blocksyncHeight = blocksyncMetrics.NewCounter("vochain_sync_height")
18+
blocksyncBPM = blocksyncMetrics.NewCounter("vochain_sync_blocks_per_minute")
1519
)

vochain/vochaininfo/vochaininfo.go

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@ func NewVochainInfo(node *vochain.BaseApplication) *VochainInfo {
3333
}
3434

3535
func (vi *VochainInfo) updateCounters() {
36+
if !vi.vnode.IsSynced() {
37+
blocksyncHeight.Set(uint64(vi.vnode.Height()))
38+
blocksyncBPM.Set(uint64(vi.BlocksLastMinute()))
39+
return
40+
}
3641
height.Set(uint64(vi.vnode.Height()))
3742

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

6872
// Height returns the current number of blocks of the blockchain.
@@ -259,7 +263,11 @@ func (vi *VochainInfo) Start(sleepSecs uint64) {
259263
panic("sleepSecs cannot be zero")
260264
}
261265
log.Infof("starting vochain info service every %d seconds", sleepSecs)
262-
metrics.NewGauge("vochain_tokens_burned",
266+
267+
metrics.UnregisterSet(viMetrics)
268+
metrics.RegisterSet(blocksyncMetrics)
269+
270+
viMetrics.NewGauge("vochain_tokens_burned",
263271
func() float64 { return float64(vi.TokensBurned()) })
264272

265273
var duration time.Duration
@@ -270,6 +278,9 @@ func (vi *VochainInfo) Start(sleepSecs uint64) {
270278
duration = time.Second * time.Duration(sleepSecs)
271279
for {
272280
select {
281+
case <-vi.vnode.WaitUntilSynced():
282+
metrics.RegisterSet(viMetrics)
283+
metrics.UnregisterSet(blocksyncMetrics)
273284
case <-time.After(duration):
274285
vi.updateCounters()
275286
currentHeight = uint64(vi.vnode.Height())

0 commit comments

Comments
 (0)