9
9
"os"
10
10
"runtime/metrics"
11
11
"runtime/pprof"
12
+ "strconv"
12
13
"strings"
14
+ "syscall"
13
15
"time"
14
16
15
17
"github.com/ethereum/go-ethereum/log"
@@ -30,13 +32,35 @@ var EnabledExpensive = false
30
32
// enablerFlags is the CLI flag names to use to enable metrics collections.
31
33
var enablerFlags = []string {"metrics" }
32
34
35
+ // enablerEnvVars is the env var names to use to enable metrics collections.
36
+ var enablerEnvVars = []string {"GETH_METRICS" }
37
+
33
38
// expensiveEnablerFlags is the CLI flag names to use to enable metrics collections.
34
39
var expensiveEnablerFlags = []string {"metrics.expensive" }
35
40
41
+ // expensiveEnablerEnvVars is the env var names to use to enable metrics collections.
42
+ var expensiveEnablerEnvVars = []string {"GETH_METRICS_EXPENSIVE" }
43
+
36
44
// Init enables or disables the metrics system. Since we need this to run before
37
45
// any other code gets to create meters and timers, we'll actually do an ugly hack
38
46
// and peek into the command line args for the metrics flag.
39
47
func init () {
48
+ for _ , enabler := range enablerEnvVars {
49
+ if val , found := syscall .Getenv (enabler ); found && ! Enabled {
50
+ if enable , _ := strconv .ParseBool (val ); enable { // ignore error, flag parser will choke on it later
51
+ log .Info ("Enabling metrics collection" )
52
+ Enabled = true
53
+ }
54
+ }
55
+ }
56
+ for _ , enabler := range expensiveEnablerEnvVars {
57
+ if val , found := syscall .Getenv (enabler ); found && ! EnabledExpensive {
58
+ if enable , _ := strconv .ParseBool (val ); enable { // ignore error, flag parser will choke on it later
59
+ log .Info ("Enabling expensive metrics collection" )
60
+ EnabledExpensive = true
61
+ }
62
+ }
63
+ }
40
64
for _ , arg := range os .Args {
41
65
flag := strings .TrimLeft (arg , "-" )
42
66
0 commit comments