metrics: pull library and introduce ResettingTimer and InfluxDB reporter (#15910)
* go-metrics: fork library and introduce ResettingTimer and InfluxDB reporter. * vendor: change nonsense/go-metrics to ethersphere/go-metrics * go-metrics: add tests. move ResettingTimer logic from reporter to type. * all, metrics: pull in metrics package in go-ethereum * metrics/test: make sure metrics are enabled for tests * metrics: apply gosimple rules * metrics/exp, internal/debug: init expvar endpoint when starting pprof server * internal/debug: tiny comment formatting fix
This commit is contained in:
committed by
Péter Szilágyi
parent
7f74bdf8dd
commit
ae9f97221a
@ -1,20 +1,8 @@
|
||||
// Copyright 2015 The go-ethereum Authors
|
||||
// This file is part of the go-ethereum library.
|
||||
// Go port of Coda Hale's Metrics library
|
||||
//
|
||||
// The go-ethereum library is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Lesser General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
// <https://github.com/rcrowley/go-metrics>
|
||||
//
|
||||
// The go-ethereum library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public License
|
||||
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
// Package metrics provides general system and process level metrics collection.
|
||||
// Coda Hale's original work: <https://github.com/codahale/metrics>
|
||||
package metrics
|
||||
|
||||
import (
|
||||
@ -24,17 +12,19 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/ethereum/go-ethereum/log"
|
||||
"github.com/rcrowley/go-metrics"
|
||||
"github.com/rcrowley/go-metrics/exp"
|
||||
)
|
||||
|
||||
// Enabled is checked by the constructor functions for all of the
|
||||
// standard metrics. If it is true, the metric returned is a stub.
|
||||
//
|
||||
// This global kill-switch helps quantify the observer effect and makes
|
||||
// for less cluttered pprof profiles.
|
||||
var Enabled bool = false
|
||||
|
||||
// MetricsEnabledFlag is the CLI flag name to use to enable metrics collections.
|
||||
const MetricsEnabledFlag = "metrics"
|
||||
const DashboardEnabledFlag = "dashboard"
|
||||
|
||||
// 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.
|
||||
@ -45,34 +35,7 @@ func init() {
|
||||
Enabled = true
|
||||
}
|
||||
}
|
||||
exp.Exp(metrics.DefaultRegistry)
|
||||
}
|
||||
|
||||
// NewCounter create a new metrics Counter, either a real one of a NOP stub depending
|
||||
// on the metrics flag.
|
||||
func NewCounter(name string) metrics.Counter {
|
||||
if !Enabled {
|
||||
return new(metrics.NilCounter)
|
||||
}
|
||||
return metrics.GetOrRegisterCounter(name, metrics.DefaultRegistry)
|
||||
}
|
||||
|
||||
// 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)
|
||||
//exp.Exp(DefaultRegistry)
|
||||
}
|
||||
|
||||
// CollectProcessMetrics periodically collects various metrics about the running
|
||||
@ -90,17 +53,17 @@ func CollectProcessMetrics(refresh time.Duration) {
|
||||
diskstats[i] = new(DiskStats)
|
||||
}
|
||||
// Define the various metrics to collect
|
||||
memAllocs := metrics.GetOrRegisterMeter("system/memory/allocs", metrics.DefaultRegistry)
|
||||
memFrees := metrics.GetOrRegisterMeter("system/memory/frees", metrics.DefaultRegistry)
|
||||
memInuse := metrics.GetOrRegisterMeter("system/memory/inuse", metrics.DefaultRegistry)
|
||||
memPauses := metrics.GetOrRegisterMeter("system/memory/pauses", metrics.DefaultRegistry)
|
||||
memAllocs := GetOrRegisterMeter("system/memory/allocs", DefaultRegistry)
|
||||
memFrees := GetOrRegisterMeter("system/memory/frees", DefaultRegistry)
|
||||
memInuse := GetOrRegisterMeter("system/memory/inuse", DefaultRegistry)
|
||||
memPauses := GetOrRegisterMeter("system/memory/pauses", DefaultRegistry)
|
||||
|
||||
var diskReads, diskReadBytes, diskWrites, diskWriteBytes metrics.Meter
|
||||
var diskReads, diskReadBytes, diskWrites, diskWriteBytes Meter
|
||||
if err := ReadDiskStats(diskstats[0]); err == nil {
|
||||
diskReads = metrics.GetOrRegisterMeter("system/disk/readcount", metrics.DefaultRegistry)
|
||||
diskReadBytes = metrics.GetOrRegisterMeter("system/disk/readdata", metrics.DefaultRegistry)
|
||||
diskWrites = metrics.GetOrRegisterMeter("system/disk/writecount", metrics.DefaultRegistry)
|
||||
diskWriteBytes = metrics.GetOrRegisterMeter("system/disk/writedata", metrics.DefaultRegistry)
|
||||
diskReads = GetOrRegisterMeter("system/disk/readcount", DefaultRegistry)
|
||||
diskReadBytes = GetOrRegisterMeter("system/disk/readdata", DefaultRegistry)
|
||||
diskWrites = GetOrRegisterMeter("system/disk/writecount", DefaultRegistry)
|
||||
diskWriteBytes = GetOrRegisterMeter("system/disk/writedata", DefaultRegistry)
|
||||
} else {
|
||||
log.Debug("Failed to read disk metrics", "err", err)
|
||||
}
|
||||
|
Reference in New Issue
Block a user