From 42c5c81bf0a4bbaf05fc05e8f5199368c096dc5f Mon Sep 17 00:00:00 2001 From: Felix Lange Date: Tue, 10 Dec 2024 12:18:34 +0100 Subject: [PATCH] cmd/geth: move process metrics startup into utils.SetupMetrics --- cmd/geth/chaincmd.go | 4 ---- cmd/geth/config.go | 2 -- cmd/utils/flags.go | 16 +++++++++------- 3 files changed, 9 insertions(+), 13 deletions(-) diff --git a/cmd/geth/chaincmd.go b/cmd/geth/chaincmd.go index 913e72faf2..48564eb5eb 100644 --- a/cmd/geth/chaincmd.go +++ b/cmd/geth/chaincmd.go @@ -38,7 +38,6 @@ import ( "github.com/ethereum/go-ethereum/ethdb" "github.com/ethereum/go-ethereum/internal/era" "github.com/ethereum/go-ethereum/log" - "github.com/ethereum/go-ethereum/metrics" "github.com/ethereum/go-ethereum/params" "github.com/urfave/cli/v2" ) @@ -288,9 +287,6 @@ func importChain(ctx *cli.Context) error { // Start metrics export if enabled utils.SetupMetrics(&cfg.Metrics) - // Start system runtime metrics collection - go metrics.CollectProcessMetrics(3 * time.Second) - chain, db := utils.MakeChain(ctx, stack, false) defer db.Close() diff --git a/cmd/geth/config.go b/cmd/geth/config.go index 60810975b8..ecee2bfd80 100644 --- a/cmd/geth/config.go +++ b/cmd/geth/config.go @@ -25,7 +25,6 @@ import ( "runtime" "slices" "strings" - "time" "unicode" "github.com/ethereum/go-ethereum/accounts" @@ -195,7 +194,6 @@ func makeFullNode(ctx *cli.Context) *node.Node { // Start metrics export if enabled utils.SetupMetrics(&cfg.Metrics) - go metrics.CollectProcessMetrics(3 * time.Second) backend, eth := utils.RegisterEthService(stack, &cfg.Eth) diff --git a/cmd/utils/flags.go b/cmd/utils/flags.go index 9898d735fb..5b9885c619 100644 --- a/cmd/utils/flags.go +++ b/cmd/utils/flags.go @@ -1969,12 +1969,15 @@ func RegisterFullSyncTester(stack *node.Node, eth *eth.Ethereum, target common.H log.Info("Registered full-sync tester", "hash", target) } +// SetupMetrics configures the metrics system. func SetupMetrics(cfg *metrics.Config) { if !cfg.Enabled { return } - metrics.Enable() log.Info("Enabling metrics collection") + metrics.Enable() + + // InfluxDB exporter. var ( enableExport = cfg.EnableInfluxDB enableExportV2 = cfg.EnableInfluxDBV2 @@ -1991,22 +1994,18 @@ func SetupMetrics(cfg *metrics.Config) { token = cfg.InfluxDBToken bucket = cfg.InfluxDBBucket organization = cfg.InfluxDBOrganization + tagsMap = SplitTagsFlag(cfg.InfluxDBTags) ) - if enableExport { - tagsMap := SplitTagsFlag(cfg.InfluxDBTags) - log.Info("Enabling metrics export to InfluxDB") - go influxdb.InfluxDBWithTags(metrics.DefaultRegistry, 10*time.Second, endpoint, database, username, password, "geth.", tagsMap) } else if enableExportV2 { tagsMap := SplitTagsFlag(cfg.InfluxDBTags) - log.Info("Enabling metrics export to InfluxDB (v2)") - go influxdb.InfluxDBV2WithTags(metrics.DefaultRegistry, 10*time.Second, endpoint, token, bucket, organization, "geth.", tagsMap) } + // Expvar exporter. if cfg.HTTP != "" { address := net.JoinHostPort(cfg.HTTP, fmt.Sprintf("%d", cfg.Port)) log.Info("Enabling stand-alone metrics HTTP endpoint", "address", address) @@ -2014,6 +2013,9 @@ func SetupMetrics(cfg *metrics.Config) { } else if cfg.HTTP == "" && cfg.Port != 0 { log.Warn(fmt.Sprintf("--%s specified without --%s, metrics server will not start.", MetricsPortFlag.Name, MetricsHTTPFlag.Name)) } + + // Enable system metrics collection. + go metrics.CollectProcessMetrics(3 * time.Second) } // SplitTagsFlag parses a comma-separated list of k=v metrics tags.