metrics: add some extra feature flags as node stats; (#2662)
This commit is contained in:
parent
5c4096fffa
commit
1bcdad851f
@ -259,6 +259,7 @@ func makeFullNode(ctx *cli.Context) (*node.Node, ethapi.Backend) {
|
||||
utils.EnableBuildInfo(git.Commit, git.Date),
|
||||
utils.EnableMinerInfo(ctx, &cfg.Eth.Miner),
|
||||
utils.EnableNodeInfo(&cfg.Eth.TxPool, stack.Server().NodeInfo()),
|
||||
utils.EnableNodeTrack(ctx, &cfg.Eth, stack),
|
||||
)
|
||||
return stack, backend
|
||||
}
|
||||
|
@ -35,6 +35,8 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/ethereum/go-ethereum/internal/version"
|
||||
|
||||
"github.com/ethereum/go-ethereum/accounts"
|
||||
"github.com/ethereum/go-ethereum/accounts/keystore"
|
||||
"github.com/ethereum/go-ethereum/beacon/fakebeacon"
|
||||
@ -2317,6 +2319,67 @@ func EnableNodeInfo(poolConfig *legacypool.Config, nodeInfo *p2p.NodeInfo) Setup
|
||||
}
|
||||
}
|
||||
|
||||
func EnableNodeTrack(ctx *cli.Context, cfg *ethconfig.Config, stack *node.Node) SetupMetricsOption {
|
||||
nodeInfo := stack.Server().NodeInfo()
|
||||
return func() {
|
||||
// register node info into metrics
|
||||
metrics.NewRegisteredLabel("node-stats", nil).Mark(map[string]interface{}{
|
||||
"NodeType": parseNodeType(),
|
||||
"ENR": nodeInfo.ENR,
|
||||
"Mining": ctx.Bool(MiningEnabledFlag.Name),
|
||||
"Etherbase": parseEtherbase(cfg),
|
||||
"MiningFeatures": parseMiningFeatures(ctx, cfg),
|
||||
"DBFeatures": parseDBFeatures(cfg, stack),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func parseEtherbase(cfg *ethconfig.Config) string {
|
||||
if cfg.Miner.Etherbase == (common.Address{}) {
|
||||
return ""
|
||||
}
|
||||
return cfg.Miner.Etherbase.String()
|
||||
}
|
||||
|
||||
func parseNodeType() string {
|
||||
git, _ := version.VCS()
|
||||
version := []string{params.VersionWithMeta}
|
||||
if len(git.Commit) >= 7 {
|
||||
version = append(version, git.Commit[:7])
|
||||
}
|
||||
if git.Date != "" {
|
||||
version = append(version, git.Date)
|
||||
}
|
||||
arch := []string{runtime.GOOS, runtime.GOARCH}
|
||||
infos := []string{"BSC", strings.Join(version, "-"), strings.Join(arch, "-"), runtime.Version()}
|
||||
return strings.Join(infos, "/")
|
||||
}
|
||||
|
||||
func parseDBFeatures(cfg *ethconfig.Config, stack *node.Node) string {
|
||||
var features []string
|
||||
if cfg.StateScheme == rawdb.PathScheme {
|
||||
features = append(features, "PBSS")
|
||||
}
|
||||
if stack.CheckIfMultiDataBase() {
|
||||
features = append(features, "MultiDB")
|
||||
}
|
||||
return strings.Join(features, "|")
|
||||
}
|
||||
|
||||
func parseMiningFeatures(ctx *cli.Context, cfg *ethconfig.Config) string {
|
||||
if !ctx.Bool(MiningEnabledFlag.Name) {
|
||||
return ""
|
||||
}
|
||||
var features []string
|
||||
if cfg.Miner.Mev.Enabled {
|
||||
features = append(features, "MEV")
|
||||
}
|
||||
if cfg.Miner.VoteEnable {
|
||||
features = append(features, "FFVoting")
|
||||
}
|
||||
return strings.Join(features, "|")
|
||||
}
|
||||
|
||||
func SetupMetrics(ctx *cli.Context, options ...SetupMetricsOption) {
|
||||
if metrics.Enabled {
|
||||
log.Info("Enabling metrics collection")
|
||||
|
@ -100,6 +100,8 @@ var (
|
||||
blockReorgAddMeter = metrics.NewRegisteredMeter("chain/reorg/add", nil)
|
||||
blockReorgDropMeter = metrics.NewRegisteredMeter("chain/reorg/drop", nil)
|
||||
|
||||
blockRecvTimeDiffGauge = metrics.NewRegisteredGauge("chain/block/recvtimediff", nil)
|
||||
|
||||
errStateRootVerificationFailed = errors.New("state root verification failed")
|
||||
errInsertionInterrupted = errors.New("insertion is interrupted")
|
||||
errChainStopped = errors.New("blockchain is stopped")
|
||||
@ -2055,6 +2057,9 @@ func (bc *BlockChain) insertChain(chain types.Blocks, setHead bool) (int, error)
|
||||
return 0, nil
|
||||
}
|
||||
|
||||
if len(chain) > 0 {
|
||||
blockRecvTimeDiffGauge.Update(time.Now().Unix() - int64(chain[0].Time()))
|
||||
}
|
||||
// Start a parallel signature recovery (signer will fluke on fork transition, minimal perf loss)
|
||||
signer := types.MakeSigner(bc.chainConfig, chain[0].Number(), chain[0].Time())
|
||||
go SenderCacher.RecoverFromBlocks(signer, chain)
|
||||
|
Loading…
Reference in New Issue
Block a user