vocdoni-node
vocdoni-node copied to clipboard
Refactor vochainInfo
Refactor in a more advanced, smart and idiomatic way the vochaininfo package [1]. Also extend it to support more kind of statistics, on log but also for prometheus.
Open to creativity of the developer taking the issue :)
[1] https://github.com/vocdoni/vocdoni-node/tree/master/vochain/vochaininfo
i'm delighted!
i even hacked a bit on this while working on tendermint-0.35, for example i made a flag for the (currently hardcoded) stats log interval. i didn't push this commit since it needed more work (which was out of scope for tendermint-0.35), and also because i felt it wasn't worth it to add yet another flag for this. but just to say, i'm absolutely eager to work on this :smile:
hacking on stats interval
dvotenode: new flag --vochainLogStatsInterval useful for debugging
-------------------------- cmd/dvotenode/dvotenode.go --------------------------
index 55c35d52..d4332395 100644
@@ -133,6 +133,8 @@ func newConfig() (*config.DvoteCfg, config.Error) {
"tendermint node log level (error, info, debug, none)")
globalCfg.VochainConfig.LogLevelMemPool = *flag.String("vochainLogLevelMemPool", "error",
"tendermint mempool log level")
+ globalCfg.VochainConfig.LogStatsInterval = *flag.Duration("vochainLogStatsInterval", time.Duration(20*time.Second),
+ "time between periodic logging of several status info")
globalCfg.VochainConfig.Peers = *flag.StringArray("vochainPeers", []string{},
"comma-separated list of p2p peers")
globalCfg.VochainConfig.Seeds = *flag.StringArray("vochainSeeds", []string{},
@@ -240,6 +242,7 @@ func newConfig() (*config.DvoteCfg, config.Error) {
viper.BindPFlag("vochainConfig.RPCListen", flag.Lookup("vochainRPCListen"))
viper.BindPFlag("vochainConfig.LogLevel", flag.Lookup("vochainLogLevel"))
viper.BindPFlag("vochainConfig.LogLevelMemPool", flag.Lookup("vochainLogLevelMemPool"))
+ viper.BindPFlag("vochainConfig.LogStatsInterval", flag.Lookup("vochainLogStatsInterval"))
viper.BindPFlag("vochainConfig.Peers", flag.Lookup("vochainPeers"))
viper.BindPFlag("vochainConfig.Seeds", flag.Lookup("vochainSeeds"))
viper.BindPFlag("vochainConfig.CreateGenesis", flag.Lookup("vochainCreateGenesis"))
------------------------------- config/config.go -------------------------------
index 070ed01e..660bfb28 100644
@@ -1,6 +1,8 @@
package config
import (
+ "time"
+
"go.vocdoni.io/dvote/db"
"go.vocdoni.io/dvote/types"
)
@@ -141,6 +143,8 @@ type VochainCfg struct {
LogLevelMemPool string
// LogOutput logging output
LogOutput string
+ // LogStatsInterval time between periodic logging of several status info
+ LogStatsInterval time.Duration
// RPCListen address for the RPC server tp listen on
RPCListen string
// P2PListen address to listen for incoming P2P connections
------------------------------ service/vochain.go ------------------------------
index 8537fc4d..baef4cd1 100644
@@ -159,22 +159,23 @@ func Vochain(vconfig *config.VochainCfg, waitForSync bool,
i := 0
for !vi.Sync() {
time.Sleep(time.Second * 1)
- if i%20 == 0 {
- log.Infof("[vochain info] fastsync running at height %d (%d blocks/s), peers %d",
- vi.Height(), (vi.Height()-lastHeight)/20, len(vi.Peers()))
+ interval := int64(vconfig.LogStatsInterval.Seconds())
+ if i%int(interval) == 0 {
+ log.Infof("[vochain info every %d] fastsync running at height %d (%d blocks/s), peers %d", interval,
+ vi.Height(), (vi.Height()-lastHeight)/interval, len(vi.Peers()))
lastHeight = vi.Height()
}
i++
}
log.Infof("vochain fastsync completed!")
}
- go VochainPrintInfo(20, vi)
+ go VochainPrintInfo(vconfig.LogStatsInterval, vi)
return vnode, sc, vi, nil
}
// VochainPrintInfo initializes the Vochain statistics recollection
-func VochainPrintInfo(sleepSecs int64, vi *vochaininfo.VochainInfo) {
+func VochainPrintInfo(sleepInterval time.Duration, vi *vochaininfo.VochainInfo) {
var a *[5]int32
var h int64
var p, v uint64
@@ -206,6 +207,6 @@ func VochainPrintInfo(sleepSecs int64, vi *vochaininfo.VochainInfo) {
"processes:%d votes:%d vxm:%d voteCache:%d blockTime:{%s}",
h, m, len(vi.Peers()), p, v, vxm, vc, b.String(),
)
- time.Sleep(time.Duration(sleepSecs) * time.Second)
+ time.Sleep(sleepInterval)
}
}