diff --git a/cmd/geth/config.go b/cmd/geth/config.go index 96bd715e88..8c06677167 100644 --- a/cmd/geth/config.go +++ b/cmd/geth/config.go @@ -209,7 +209,7 @@ func constructDevModeBanner(ctx *cli.Context, cfg gethConfig) string { 0x%x (10^49 ETH) `, cfg.Eth.Miner.PendingFeeRecipient) if cfg.Eth.Miner.PendingFeeRecipient == utils.DeveloperAddr { - devModeBanner += fmt.Sprintf(` + devModeBanner += fmt.Sprintf(` Private Key ------------------ 0x%x @@ -375,6 +375,9 @@ func applyMetricConfig(ctx *cli.Context, cfg *gethConfig) { if ctx.IsSet(utils.MetricsInfluxDBOrganizationFlag.Name) { cfg.Metrics.InfluxDBOrganization = ctx.String(utils.MetricsInfluxDBOrganizationFlag.Name) } + if ctx.IsSet(utils.MetricsStateSizeFlag.Name) { + cfg.Metrics.EnableStateSizeTracking = ctx.Bool(utils.MetricsStateSizeFlag.Name) + } // Sanity-check the commandline flags. It is fine if some unused fields is part // of the toml-config, but we expect the commandline to only contain relevant // arguments, otherwise it indicates an error. diff --git a/cmd/geth/main.go b/cmd/geth/main.go index 2da5c43216..54e1b4c4c1 100644 --- a/cmd/geth/main.go +++ b/cmd/geth/main.go @@ -200,6 +200,7 @@ var ( utils.MetricsInfluxDBTokenFlag, utils.MetricsInfluxDBBucketFlag, utils.MetricsInfluxDBOrganizationFlag, + utils.MetricsStateSizeFlag, } ) diff --git a/cmd/utils/flags.go b/cmd/utils/flags.go index bfc1ff0983..b58249a637 100644 --- a/cmd/utils/flags.go +++ b/cmd/utils/flags.go @@ -966,6 +966,13 @@ Please note that --` + MetricsHTTPFlag.Name + ` must be set to start the server. Value: metrics.DefaultConfig.InfluxDBOrganization, Category: flags.MetricsCategory, } + + MetricsStateSizeFlag = &cli.BoolFlag{ + Name: "metrics.statesize", + Usage: "Enable state size tracking for metrics collection", + Value: metrics.DefaultConfig.EnableStateSizeTracking, + Category: flags.MetricsCategory, + } ) var ( @@ -2218,6 +2225,10 @@ func MakeChain(ctx *cli.Context, stack *node.Node, readonly bool) (*core.BlockCh } else if ctx.IsSet(CacheFlag.Name) || ctx.IsSet(CacheSnapshotFlag.Name) { options.SnapshotLimit = ctx.Int(CacheFlag.Name) * ctx.Int(CacheSnapshotFlag.Name) / 100 } + if ctx.Bool(MetricsStateSizeFlag.Name) { + log.Info("Enabling state size tracking") + options.EnableStateSizeTracking = true + } // If we're in readonly, do not bother generating snapshot data. if readonly { options.SnapshotNoBuild = true diff --git a/metrics/config.go b/metrics/config.go index 72f94dd194..ea916b3673 100644 --- a/metrics/config.go +++ b/metrics/config.go @@ -33,6 +33,8 @@ type Config struct { InfluxDBToken string `toml:",omitempty"` InfluxDBBucket string `toml:",omitempty"` InfluxDBOrganization string `toml:",omitempty"` + + EnableStateSizeTracking bool `toml:",omitempty"` } // DefaultConfig is the default config for metrics used in go-ethereum. @@ -53,4 +55,6 @@ var DefaultConfig = Config{ InfluxDBToken: "test", InfluxDBBucket: "geth", InfluxDBOrganization: "geth", + + EnableStateSizeTracking: false, }