Skip to content

Commit 3fe6879

Browse files
committed
metrics: peek into toml to decide enabling
1 parent f6971a7 commit 3fe6879

File tree

1 file changed

+23
-3
lines changed

1 file changed

+23
-3
lines changed

metrics/metrics.go

+23-3
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
"time"
1616

1717
"github.com/ethereum/go-ethereum/log"
18+
"github.com/naoina/toml"
1819
)
1920

2021
// Enabled is checked by the constructor functions for all of the
@@ -37,17 +38,35 @@ func init() {
3738
for _, enabler := range enablerEnvVars {
3839
if val, found := syscall.Getenv(enabler); found && !Enabled {
3940
if enable, _ := strconv.ParseBool(val); enable { // ignore error, flag parser will choke on it later
40-
log.Info("Enabling metrics collection")
4141
Enabled = true
4242
}
4343
}
4444
}
45-
for _, arg := range os.Args {
45+
for i, arg := range os.Args {
4646
flag := strings.TrimLeft(arg, "-")
4747

48+
// If geth is being configured by toml, try to peak into it.
49+
if !Enabled && strings.HasPrefix(flag, "config") {
50+
file := strings.TrimSpace(os.Args[i+1])
51+
f, err := os.Open(file)
52+
if err != nil {
53+
continue
54+
}
55+
defer f.Close()
56+
57+
var cfg map[string]map[string]any
58+
if err := toml.NewDecoder(f).Decode(&cfg); err != nil {
59+
continue
60+
}
61+
if m, ok := cfg["Metrics"]; ok {
62+
if v, ok := m["Enabled"].(bool); ok && v {
63+
Enabled = true
64+
}
65+
}
66+
}
67+
4868
for _, enabler := range enablerFlags {
4969
if !Enabled && flag == enabler {
50-
log.Info("Enabling metrics collection")
5170
Enabled = true
5271
}
5372
}
@@ -129,6 +148,7 @@ func readRuntimeStats(v *runtimeStats) {
129148
func CollectProcessMetrics(refresh time.Duration) {
130149
// Short circuit if the metrics system is disabled
131150
if !Enabled {
151+
log.Warn("Nah I don't wanna do metrics")
132152
return
133153
}
134154

0 commit comments

Comments
 (0)