diff --git a/metrics/metrics.go b/metrics/metrics.go index c7fe5c7333b9..b603b4bd74bf 100644 --- a/metrics/metrics.go +++ b/metrics/metrics.go @@ -15,6 +15,7 @@ import ( "time" "github.com/ethereum/go-ethereum/log" + "github.com/naoina/toml" ) // Enabled is checked by the constructor functions for all of the @@ -37,17 +38,35 @@ func init() { for _, enabler := range enablerEnvVars { if val, found := syscall.Getenv(enabler); found && !Enabled { if enable, _ := strconv.ParseBool(val); enable { // ignore error, flag parser will choke on it later - log.Info("Enabling metrics collection") Enabled = true } } } - for _, arg := range os.Args { + for i, arg := range os.Args { flag := strings.TrimLeft(arg, "-") + // If geth is being configured by toml, try to peak into it. + if !Enabled && strings.HasPrefix(flag, "config") { + file := strings.TrimSpace(os.Args[i+1]) + f, err := os.Open(file) + if err != nil { + continue + } + defer f.Close() + + var cfg map[string]map[string]any + if err := toml.NewDecoder(f).Decode(&cfg); err != nil { + continue + } + if m, ok := cfg["Metrics"]; ok { + if v, ok := m["Enabled"].(bool); ok && v { + Enabled = true + } + } + } + for _, enabler := range enablerFlags { if !Enabled && flag == enabler { - log.Info("Enabling metrics collection") Enabled = true } } @@ -129,6 +148,7 @@ func readRuntimeStats(v *runtimeStats) { func CollectProcessMetrics(refresh time.Duration) { // Short circuit if the metrics system is disabled if !Enabled { + log.Warn("Nah I don't wanna do metrics") return }