aboutsummaryrefslogtreecommitdiffstats
path: root/metrics
diff options
context:
space:
mode:
authorPéter Szilágyi <peterke@gmail.com>2015-06-29 21:11:01 +0800
committerJeffrey Wilcke <geffobscura@gmail.com>2015-06-30 06:51:46 +0800
commit01fe97211354d13ecaba8a52c82b808b7a7e8393 (patch)
tree337e23800833c81e1d21f5850d4079c575e89ea7 /metrics
parentccbb56b4f2cdba352eaa859ce3e34f999287f5c0 (diff)
downloaddexon-01fe97211354d13ecaba8a52c82b808b7a7e8393.tar
dexon-01fe97211354d13ecaba8a52c82b808b7a7e8393.tar.gz
dexon-01fe97211354d13ecaba8a52c82b808b7a7e8393.tar.bz2
dexon-01fe97211354d13ecaba8a52c82b808b7a7e8393.tar.lz
dexon-01fe97211354d13ecaba8a52c82b808b7a7e8393.tar.xz
dexon-01fe97211354d13ecaba8a52c82b808b7a7e8393.tar.zst
dexon-01fe97211354d13ecaba8a52c82b808b7a7e8393.zip
cmd, core, eth, metrics, p2p: require enabling metrics
Diffstat (limited to 'metrics')
-rw-r--r--metrics/metrics.go42
1 files changed, 42 insertions, 0 deletions
diff --git a/metrics/metrics.go b/metrics/metrics.go
index cb0caaae4..33004ee3b 100644
--- a/metrics/metrics.go
+++ b/metrics/metrics.go
@@ -2,7 +2,9 @@
package metrics
import (
+ "os"
"runtime"
+ "strings"
"time"
"github.com/ethereum/go-ethereum/logger"
@@ -10,9 +12,49 @@ import (
"github.com/rcrowley/go-metrics"
)
+// MetricsEnabledFlag is the CLI flag name to use to enable metrics collections.
+var MetricsEnabledFlag = "metrics"
+
+// enabled is the flag specifying if metrics are enable or not.
+var enabled = false
+
+// Init enables or disables the metrics system. Since we need this to run before
+// any other code gets to create meters and timers, we'll actually do an ugly hack
+// and peek into the command line args for the metrics flag.
+func init() {
+ for _, arg := range os.Args {
+ if strings.TrimLeft(arg, "-") == MetricsEnabledFlag {
+ glog.V(logger.Info).Infof("Enabling metrics collection")
+ enabled = true
+ }
+ }
+}
+
+// NewMeter create a new metrics Meter, either a real one of a NOP stub depending
+// on the metrics flag.
+func NewMeter(name string) metrics.Meter {
+ if !enabled {
+ return new(metrics.NilMeter)
+ }
+ return metrics.GetOrRegisterMeter(name, metrics.DefaultRegistry)
+}
+
+// NewTimer create a new metrics Timer, either a real one of a NOP stub depending
+// on the metrics flag.
+func NewTimer(name string) metrics.Timer {
+ if !enabled {
+ return new(metrics.NilTimer)
+ }
+ return metrics.GetOrRegisterTimer(name, metrics.DefaultRegistry)
+}
+
// CollectProcessMetrics periodically collects various metrics about the running
// process.
func CollectProcessMetrics(refresh time.Duration) {
+ // Short circuit if the metrics system is disabled
+ if !enabled {
+ return
+ }
// Create the various data collectors
memstats := make([]*runtime.MemStats, 2)
diskstats := make([]*DiskStats, 2)