cmd, core, eth, metrics, p2p: require enabling metrics
This commit is contained in:
committed by
Jeffrey Wilcke
parent
ccbb56b4f2
commit
01fe972113
@ -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)
|
||||
|
Reference in New Issue
Block a user