mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-18 18:02:24 +00:00
all: different metrics-api, enable from flags
This commit is contained in:
parent
87048fc9c8
commit
3ade355f6f
18 changed files with 90 additions and 112 deletions
|
|
@ -282,14 +282,15 @@ func importChain(ctx *cli.Context) error {
|
||||||
if ctx.Args().Len() < 1 {
|
if ctx.Args().Len() < 1 {
|
||||||
utils.Fatalf("This command requires an argument.")
|
utils.Fatalf("This command requires an argument.")
|
||||||
}
|
}
|
||||||
|
stack, cfg := makeConfigNode(ctx)
|
||||||
|
defer stack.Close()
|
||||||
|
|
||||||
// Start metrics export if enabled
|
// Start metrics export if enabled
|
||||||
utils.SetupMetrics(ctx)
|
utils.SetupMetrics(&cfg.Metrics)
|
||||||
|
|
||||||
// Start system runtime metrics collection
|
// Start system runtime metrics collection
|
||||||
go metrics.CollectProcessMetrics(3 * time.Second)
|
go metrics.CollectProcessMetrics(3 * time.Second)
|
||||||
|
|
||||||
stack, _ := makeConfigNode(ctx)
|
|
||||||
defer stack.Close()
|
|
||||||
|
|
||||||
chain, db := utils.MakeChain(ctx, stack, false)
|
chain, db := utils.MakeChain(ctx, stack, false)
|
||||||
defer db.Close()
|
defer db.Close()
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -25,6 +25,7 @@ import (
|
||||||
"runtime"
|
"runtime"
|
||||||
"slices"
|
"slices"
|
||||||
"strings"
|
"strings"
|
||||||
|
"time"
|
||||||
"unicode"
|
"unicode"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/accounts"
|
"github.com/ethereum/go-ethereum/accounts"
|
||||||
|
|
@ -192,6 +193,10 @@ func makeFullNode(ctx *cli.Context) *node.Node {
|
||||||
cfg.Eth.OverrideVerkle = &v
|
cfg.Eth.OverrideVerkle = &v
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Start metrics export if enabled
|
||||||
|
utils.SetupMetrics(&cfg.Metrics)
|
||||||
|
go metrics.CollectProcessMetrics(3 * time.Second)
|
||||||
|
|
||||||
backend, eth := utils.RegisterEthService(stack, &cfg.Eth)
|
backend, eth := utils.RegisterEthService(stack, &cfg.Eth)
|
||||||
|
|
||||||
// Create gauge with geth system and build information
|
// Create gauge with geth system and build information
|
||||||
|
|
|
||||||
|
|
@ -34,7 +34,6 @@ import (
|
||||||
"github.com/ethereum/go-ethereum/internal/debug"
|
"github.com/ethereum/go-ethereum/internal/debug"
|
||||||
"github.com/ethereum/go-ethereum/internal/flags"
|
"github.com/ethereum/go-ethereum/internal/flags"
|
||||||
"github.com/ethereum/go-ethereum/log"
|
"github.com/ethereum/go-ethereum/log"
|
||||||
"github.com/ethereum/go-ethereum/metrics"
|
|
||||||
"github.com/ethereum/go-ethereum/node"
|
"github.com/ethereum/go-ethereum/node"
|
||||||
"go.uber.org/automaxprocs/maxprocs"
|
"go.uber.org/automaxprocs/maxprocs"
|
||||||
|
|
||||||
|
|
@ -325,12 +324,6 @@ func prepare(ctx *cli.Context) {
|
||||||
ctx.Set(utils.CacheFlag.Name, strconv.Itoa(4096))
|
ctx.Set(utils.CacheFlag.Name, strconv.Itoa(4096))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Start metrics export if enabled
|
|
||||||
utils.SetupMetrics(ctx)
|
|
||||||
|
|
||||||
// Start system runtime metrics collection
|
|
||||||
go metrics.CollectProcessMetrics(3 * time.Second)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// geth is the main entry point into the system if no special subcommand is run.
|
// geth is the main entry point into the system if no special subcommand is run.
|
||||||
|
|
|
||||||
|
|
@ -1969,24 +1969,22 @@ func RegisterFullSyncTester(stack *node.Node, eth *eth.Ethereum, target common.H
|
||||||
log.Info("Registered full-sync tester", "hash", target)
|
log.Info("Registered full-sync tester", "hash", target)
|
||||||
}
|
}
|
||||||
|
|
||||||
func SetupMetrics(ctx *cli.Context) {
|
func SetupMetrics(cfg *metrics.Config) {
|
||||||
if metrics.Enabled {
|
if !cfg.Enabled {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
metrics.Init(true)
|
||||||
log.Info("Enabling metrics collection")
|
log.Info("Enabling metrics collection")
|
||||||
|
|
||||||
var (
|
var (
|
||||||
enableExport = ctx.Bool(MetricsEnableInfluxDBFlag.Name)
|
enableExport = cfg.EnableInfluxDB
|
||||||
enableExportV2 = ctx.Bool(MetricsEnableInfluxDBV2Flag.Name)
|
enableExportV2 = cfg.EnableInfluxDBV2
|
||||||
)
|
)
|
||||||
|
if enableExport && enableExportV2 {
|
||||||
|
Fatalf("Flags %v can't be used at the same time", strings.Join([]string{MetricsEnableInfluxDBFlag.Name, MetricsEnableInfluxDBV2Flag.Name}, ", "))
|
||||||
|
}
|
||||||
if enableExport || enableExportV2 {
|
if enableExport || enableExportV2 {
|
||||||
CheckExclusive(ctx, MetricsEnableInfluxDBFlag, MetricsEnableInfluxDBV2Flag)
|
v1FlagIsSet := cfg.InfluxDBUsername != "" || cfg.InfluxDBPassword != ""
|
||||||
|
v2FlagIsSet := cfg.InfluxDBToken != "" || cfg.InfluxDBOrganization != "" || cfg.InfluxDBBucket != ""
|
||||||
v1FlagIsSet := ctx.IsSet(MetricsInfluxDBUsernameFlag.Name) ||
|
|
||||||
ctx.IsSet(MetricsInfluxDBPasswordFlag.Name)
|
|
||||||
|
|
||||||
v2FlagIsSet := ctx.IsSet(MetricsInfluxDBTokenFlag.Name) ||
|
|
||||||
ctx.IsSet(MetricsInfluxDBOrganizationFlag.Name) ||
|
|
||||||
ctx.IsSet(MetricsInfluxDBBucketFlag.Name)
|
|
||||||
|
|
||||||
if enableExport && v2FlagIsSet {
|
if enableExport && v2FlagIsSet {
|
||||||
Fatalf("Flags --influxdb.metrics.organization, --influxdb.metrics.token, --influxdb.metrics.bucket are only available for influxdb-v2")
|
Fatalf("Flags --influxdb.metrics.organization, --influxdb.metrics.token, --influxdb.metrics.bucket are only available for influxdb-v2")
|
||||||
|
|
@ -1996,38 +1994,37 @@ func SetupMetrics(ctx *cli.Context) {
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
endpoint = ctx.String(MetricsInfluxDBEndpointFlag.Name)
|
endpoint = cfg.InfluxDBEndpoint
|
||||||
database = ctx.String(MetricsInfluxDBDatabaseFlag.Name)
|
database = cfg.InfluxDBDatabase
|
||||||
username = ctx.String(MetricsInfluxDBUsernameFlag.Name)
|
username = cfg.InfluxDBUsername
|
||||||
password = ctx.String(MetricsInfluxDBPasswordFlag.Name)
|
password = cfg.InfluxDBPassword
|
||||||
|
|
||||||
token = ctx.String(MetricsInfluxDBTokenFlag.Name)
|
token = cfg.InfluxDBToken
|
||||||
bucket = ctx.String(MetricsInfluxDBBucketFlag.Name)
|
bucket = cfg.InfluxDBBucket
|
||||||
organization = ctx.String(MetricsInfluxDBOrganizationFlag.Name)
|
organization = cfg.InfluxDBOrganization
|
||||||
)
|
)
|
||||||
|
|
||||||
if enableExport {
|
if enableExport {
|
||||||
tagsMap := SplitTagsFlag(ctx.String(MetricsInfluxDBTagsFlag.Name))
|
tagsMap := SplitTagsFlag(cfg.InfluxDBTags)
|
||||||
|
|
||||||
log.Info("Enabling metrics export to InfluxDB")
|
log.Info("Enabling metrics export to InfluxDB")
|
||||||
|
|
||||||
go influxdb.InfluxDBWithTags(metrics.DefaultRegistry, 10*time.Second, endpoint, database, username, password, "geth.", tagsMap)
|
go influxdb.InfluxDBWithTags(metrics.DefaultRegistry, 10*time.Second, endpoint, database, username, password, "geth.", tagsMap)
|
||||||
} else if enableExportV2 {
|
} else if enableExportV2 {
|
||||||
tagsMap := SplitTagsFlag(ctx.String(MetricsInfluxDBTagsFlag.Name))
|
tagsMap := SplitTagsFlag(cfg.InfluxDBTags)
|
||||||
|
|
||||||
log.Info("Enabling metrics export to InfluxDB (v2)")
|
log.Info("Enabling metrics export to InfluxDB (v2)")
|
||||||
|
|
||||||
go influxdb.InfluxDBV2WithTags(metrics.DefaultRegistry, 10*time.Second, endpoint, token, bucket, organization, "geth.", tagsMap)
|
go influxdb.InfluxDBV2WithTags(metrics.DefaultRegistry, 10*time.Second, endpoint, token, bucket, organization, "geth.", tagsMap)
|
||||||
}
|
}
|
||||||
|
|
||||||
if ctx.IsSet(MetricsHTTPFlag.Name) {
|
if cfg.HTTP != "" {
|
||||||
address := net.JoinHostPort(ctx.String(MetricsHTTPFlag.Name), fmt.Sprintf("%d", ctx.Int(MetricsPortFlag.Name)))
|
address := net.JoinHostPort(cfg.HTTP, fmt.Sprintf("%d", cfg.Port))
|
||||||
log.Info("Enabling stand-alone metrics HTTP endpoint", "address", address)
|
log.Info("Enabling stand-alone metrics HTTP endpoint", "address", address)
|
||||||
exp.Setup(address)
|
exp.Setup(address)
|
||||||
} else if ctx.IsSet(MetricsPortFlag.Name) {
|
} else if cfg.HTTP == "" && cfg.Port != 0 {
|
||||||
log.Warn(fmt.Sprintf("--%s specified without --%s, metrics server will not start.", MetricsPortFlag.Name, MetricsHTTPFlag.Name))
|
log.Warn(fmt.Sprintf("--%s specified without --%s, metrics server will not start.", MetricsPortFlag.Name, MetricsHTTPFlag.Name))
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func SplitTagsFlag(tagsFlag string) map[string]string {
|
func SplitTagsFlag(tagsFlag string) map[string]string {
|
||||||
|
|
|
||||||
|
|
@ -111,7 +111,7 @@ func (p *triePrefetcher) terminate(async bool) {
|
||||||
|
|
||||||
// report aggregates the pre-fetching and usage metrics and reports them.
|
// report aggregates the pre-fetching and usage metrics and reports them.
|
||||||
func (p *triePrefetcher) report() {
|
func (p *triePrefetcher) report() {
|
||||||
if !metrics.Enabled {
|
if !metrics.Enabled() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
for _, fetcher := range p.fetchers {
|
for _, fetcher := range p.fetchers {
|
||||||
|
|
|
||||||
|
|
@ -126,7 +126,7 @@ func (p *TxPool) reserver(id int, subpool SubPool) AddressReserver {
|
||||||
return ErrAlreadyReserved
|
return ErrAlreadyReserved
|
||||||
}
|
}
|
||||||
p.reservations[addr] = subpool
|
p.reservations[addr] = subpool
|
||||||
if metrics.Enabled {
|
if metrics.Enabled() {
|
||||||
m := fmt.Sprintf("%s/%d", reservationsGaugeName, id)
|
m := fmt.Sprintf("%s/%d", reservationsGaugeName, id)
|
||||||
metrics.GetOrRegisterGauge(m, nil).Inc(1)
|
metrics.GetOrRegisterGauge(m, nil).Inc(1)
|
||||||
}
|
}
|
||||||
|
|
@ -143,7 +143,7 @@ func (p *TxPool) reserver(id int, subpool SubPool) AddressReserver {
|
||||||
return errors.New("address not owned")
|
return errors.New("address not owned")
|
||||||
}
|
}
|
||||||
delete(p.reservations, addr)
|
delete(p.reservations, addr)
|
||||||
if metrics.Enabled {
|
if metrics.Enabled() {
|
||||||
m := fmt.Sprintf("%s/%d", reservationsGaugeName, id)
|
m := fmt.Sprintf("%s/%d", reservationsGaugeName, id)
|
||||||
metrics.GetOrRegisterGauge(m, nil).Dec(1)
|
metrics.GetOrRegisterGauge(m, nil).Dec(1)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -365,7 +365,7 @@ func (h *handler) runSnapExtension(peer *snap.Peer, handler snap.Handler) error
|
||||||
defer h.decHandlers()
|
defer h.decHandlers()
|
||||||
|
|
||||||
if err := h.peers.registerSnapExtension(peer); err != nil {
|
if err := h.peers.registerSnapExtension(peer); err != nil {
|
||||||
if metrics.Enabled {
|
if metrics.Enabled() {
|
||||||
if peer.Inbound() {
|
if peer.Inbound() {
|
||||||
snap.IngressRegistrationErrorMeter.Mark(1)
|
snap.IngressRegistrationErrorMeter.Mark(1)
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
|
|
@ -190,7 +190,7 @@ func handleMessage(backend Backend, peer *Peer) error {
|
||||||
var handlers = eth68
|
var handlers = eth68
|
||||||
|
|
||||||
// Track the amount of time it takes to serve the request and run the handler
|
// Track the amount of time it takes to serve the request and run the handler
|
||||||
if metrics.Enabled {
|
if metrics.Enabled() {
|
||||||
h := fmt.Sprintf("%s/%s/%d/%#02x", p2p.HandleHistName, ProtocolName, peer.Version(), msg.Code)
|
h := fmt.Sprintf("%s/%s/%d/%#02x", p2p.HandleHistName, ProtocolName, peer.Version(), msg.Code)
|
||||||
defer func(start time.Time) {
|
defer func(start time.Time) {
|
||||||
sampler := func() metrics.Sample {
|
sampler := func() metrics.Sample {
|
||||||
|
|
|
||||||
|
|
@ -112,7 +112,7 @@ func (p *Peer) readStatus(network uint64, status *StatusPacket, genesis common.H
|
||||||
|
|
||||||
// markError registers the error with the corresponding metric.
|
// markError registers the error with the corresponding metric.
|
||||||
func markError(p *Peer, err error) {
|
func markError(p *Peer, err error) {
|
||||||
if !metrics.Enabled {
|
if !metrics.Enabled() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
m := meters.get(p.Inbound())
|
m := meters.get(p.Inbound())
|
||||||
|
|
|
||||||
|
|
@ -132,7 +132,7 @@ func HandleMessage(backend Backend, peer *Peer) error {
|
||||||
defer msg.Discard()
|
defer msg.Discard()
|
||||||
start := time.Now()
|
start := time.Now()
|
||||||
// Track the amount of time it takes to serve the request and run the handler
|
// Track the amount of time it takes to serve the request and run the handler
|
||||||
if metrics.Enabled {
|
if metrics.Enabled() {
|
||||||
h := fmt.Sprintf("%s/%s/%d/%#02x", p2p.HandleHistName, ProtocolName, peer.Version(), msg.Code)
|
h := fmt.Sprintf("%s/%s/%d/%#02x", p2p.HandleHistName, ProtocolName, peer.Version(), msg.Code)
|
||||||
defer func(start time.Time) {
|
defer func(start time.Time) {
|
||||||
sampler := func() metrics.Sample {
|
sampler := func() metrics.Sample {
|
||||||
|
|
|
||||||
|
|
@ -6,52 +6,34 @@
|
||||||
package metrics
|
package metrics
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"os"
|
"fmt"
|
||||||
"runtime/metrics"
|
"runtime/metrics"
|
||||||
"runtime/pprof"
|
"runtime/pprof"
|
||||||
"strconv"
|
|
||||||
"strings"
|
|
||||||
"syscall"
|
|
||||||
"time"
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/log"
|
var (
|
||||||
|
metricsEnabled = false
|
||||||
|
initRan = false
|
||||||
)
|
)
|
||||||
|
|
||||||
// Enabled is checked by functions that are deemed 'expensive', e.g. if a
|
// Enabled is checked by functions that are deemed 'expensive', e.g. if a
|
||||||
// meter-type does locking and/or non-trivial math operations during update.
|
// meter-type does locking and/or non-trivial math operations during update.
|
||||||
//
|
func Enabled() bool {
|
||||||
|
return metricsEnabled
|
||||||
|
}
|
||||||
|
|
||||||
|
// Init enables the metrics system.
|
||||||
// The Enabled-flag is expected to be set, once, during startup, but toggling off and on
|
// The Enabled-flag is expected to be set, once, during startup, but toggling off and on
|
||||||
// is not supported: YMMV.
|
// is not supported: YMMV.
|
||||||
var Enabled = false
|
// Init is not safe to call concurrently. It has no effect if it was already called.
|
||||||
|
func Init(enabled bool) {
|
||||||
// enablerFlags is the CLI flag names to use to enable metrics collections.
|
metricsEnabled = enabled
|
||||||
var enablerFlags = []string{"metrics"}
|
if initRan {
|
||||||
|
return
|
||||||
// enablerEnvVars is the env var names to use to enable metrics collections.
|
|
||||||
var enablerEnvVars = []string{"GETH_METRICS"}
|
|
||||||
|
|
||||||
// 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 _, enabler := range enablerEnvVars {
|
|
||||||
if val, found := syscall.Getenv(enabler); found && !Enabled {
|
|
||||||
if enable, _ := strconv.ParseBool(val); enable { // ignore error, flag parser will choke on it later
|
|
||||||
log.Info("Enabling metrics collection")
|
|
||||||
Enabled = true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for _, arg := range os.Args {
|
|
||||||
flag := strings.TrimLeft(arg, "-")
|
|
||||||
|
|
||||||
for _, enabler := range enablerFlags {
|
|
||||||
if !Enabled && flag == enabler {
|
|
||||||
log.Info("Enabling metrics collection")
|
|
||||||
Enabled = true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
initRan = true
|
||||||
|
// TODO: Maybe start the ticker for exp delays, and things like that.
|
||||||
}
|
}
|
||||||
|
|
||||||
var threadCreateProfile = pprof.Lookup("threadcreate")
|
var threadCreateProfile = pprof.Lookup("threadcreate")
|
||||||
|
|
@ -128,7 +110,7 @@ func readRuntimeStats(v *runtimeStats) {
|
||||||
// CollectProcessMetrics periodically collects various metrics about the running process.
|
// CollectProcessMetrics periodically collects various metrics about the running process.
|
||||||
func CollectProcessMetrics(refresh time.Duration) {
|
func CollectProcessMetrics(refresh time.Duration) {
|
||||||
// Short circuit if the metrics system is disabled
|
// Short circuit if the metrics system is disabled
|
||||||
if !Enabled {
|
if !metricsEnabled {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -45,7 +45,7 @@ func NewRegisteredResettingTimer(name string, r Registry) ResettingTimer {
|
||||||
|
|
||||||
// NewResettingTimer constructs a new StandardResettingTimer
|
// NewResettingTimer constructs a new StandardResettingTimer
|
||||||
func NewResettingTimer() ResettingTimer {
|
func NewResettingTimer() ResettingTimer {
|
||||||
if !Enabled {
|
if !metricsEnabled {
|
||||||
return NilResettingTimer{}
|
return NilResettingTimer{}
|
||||||
}
|
}
|
||||||
return &StandardResettingTimer{
|
return &StandardResettingTimer{
|
||||||
|
|
|
||||||
|
|
@ -53,7 +53,7 @@ type meteredUdpConn struct {
|
||||||
|
|
||||||
func newMeteredConn(conn UDPConn) UDPConn {
|
func newMeteredConn(conn UDPConn) UDPConn {
|
||||||
// Short circuit if metrics are disabled
|
// Short circuit if metrics are disabled
|
||||||
if !metrics.Enabled {
|
if !metrics.Enabled() {
|
||||||
return conn
|
return conn
|
||||||
}
|
}
|
||||||
return &meteredUdpConn{udpConn: conn}
|
return &meteredUdpConn{udpConn: conn}
|
||||||
|
|
|
||||||
|
|
@ -570,7 +570,7 @@ func (tab *Table) nodeAdded(b *bucket, n *tableNode) {
|
||||||
if tab.nodeAddedHook != nil {
|
if tab.nodeAddedHook != nil {
|
||||||
tab.nodeAddedHook(b, n)
|
tab.nodeAddedHook(b, n)
|
||||||
}
|
}
|
||||||
if metrics.Enabled {
|
if metrics.Enabled() {
|
||||||
bucketsCounter[b.index].Inc(1)
|
bucketsCounter[b.index].Inc(1)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -580,7 +580,7 @@ func (tab *Table) nodeRemoved(b *bucket, n *tableNode) {
|
||||||
if tab.nodeRemovedHook != nil {
|
if tab.nodeRemovedHook != nil {
|
||||||
tab.nodeRemovedHook(b, n)
|
tab.nodeRemovedHook(b, n)
|
||||||
}
|
}
|
||||||
if metrics.Enabled {
|
if metrics.Enabled() {
|
||||||
bucketsCounter[b.index].Dec(1)
|
bucketsCounter[b.index].Dec(1)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -64,7 +64,7 @@ var (
|
||||||
// markDialError matches errors that occur while setting up a dial connection
|
// markDialError matches errors that occur while setting up a dial connection
|
||||||
// to the corresponding meter.
|
// to the corresponding meter.
|
||||||
func markDialError(err error) {
|
func markDialError(err error) {
|
||||||
if !metrics.Enabled {
|
if !metrics.Enabled() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if err2 := errors.Unwrap(err); err2 != nil {
|
if err2 := errors.Unwrap(err); err2 != nil {
|
||||||
|
|
@ -98,7 +98,7 @@ type meteredConn struct {
|
||||||
// connection meter and also increases the metered peer count. If the metrics
|
// connection meter and also increases the metered peer count. If the metrics
|
||||||
// system is disabled, function returns the original connection.
|
// system is disabled, function returns the original connection.
|
||||||
func newMeteredConn(conn net.Conn) net.Conn {
|
func newMeteredConn(conn net.Conn) net.Conn {
|
||||||
if !metrics.Enabled {
|
if !metrics.Enabled() {
|
||||||
return conn
|
return conn
|
||||||
}
|
}
|
||||||
return &meteredConn{Conn: conn}
|
return &meteredConn{Conn: conn}
|
||||||
|
|
|
||||||
|
|
@ -357,7 +357,7 @@ func (p *Peer) handle(msg Msg) error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("msg code out of range: %v", msg.Code)
|
return fmt.Errorf("msg code out of range: %v", msg.Code)
|
||||||
}
|
}
|
||||||
if metrics.Enabled {
|
if metrics.Enabled() {
|
||||||
m := fmt.Sprintf("%s/%s/%d/%#02x", ingressMeterName, proto.Name, proto.Version, msg.Code-proto.offset)
|
m := fmt.Sprintf("%s/%s/%d/%#02x", ingressMeterName, proto.Name, proto.Version, msg.Code-proto.offset)
|
||||||
metrics.GetOrRegisterMeter(m, nil).Mark(int64(msg.meterSize))
|
metrics.GetOrRegisterMeter(m, nil).Mark(int64(msg.meterSize))
|
||||||
metrics.GetOrRegisterMeter(m+"/packets", nil).Mark(1)
|
metrics.GetOrRegisterMeter(m+"/packets", nil).Mark(1)
|
||||||
|
|
|
||||||
|
|
@ -84,7 +84,7 @@ func New(protocol string, timeout time.Duration) *Tracker {
|
||||||
// Track adds a network request to the tracker to wait for a response to arrive
|
// Track adds a network request to the tracker to wait for a response to arrive
|
||||||
// or until the request it cancelled or times out.
|
// or until the request it cancelled or times out.
|
||||||
func (t *Tracker) Track(peer string, version uint, reqCode uint64, resCode uint64, id uint64) {
|
func (t *Tracker) Track(peer string, version uint, reqCode uint64, resCode uint64, id uint64) {
|
||||||
if !metrics.Enabled {
|
if !metrics.Enabled() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
t.lock.Lock()
|
t.lock.Lock()
|
||||||
|
|
@ -163,7 +163,7 @@ func (t *Tracker) schedule() {
|
||||||
|
|
||||||
// Fulfil fills a pending request, if any is available, reporting on various metrics.
|
// Fulfil fills a pending request, if any is available, reporting on various metrics.
|
||||||
func (t *Tracker) Fulfil(peer string, version uint, code uint64, id uint64) {
|
func (t *Tracker) Fulfil(peer string, version uint, code uint64, id uint64) {
|
||||||
if !metrics.Enabled {
|
if !metrics.Enabled() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
t.lock.Lock()
|
t.lock.Lock()
|
||||||
|
|
|
||||||
|
|
@ -98,7 +98,7 @@ func (t *rlpxTransport) WriteMsg(msg Msg) error {
|
||||||
|
|
||||||
// Set metrics.
|
// Set metrics.
|
||||||
msg.meterSize = size
|
msg.meterSize = size
|
||||||
if metrics.Enabled && msg.meterCap.Name != "" { // don't meter non-subprotocol messages
|
if metrics.Enabled() && msg.meterCap.Name != "" { // don't meter non-subprotocol messages
|
||||||
m := fmt.Sprintf("%s/%s/%d/%#02x", egressMeterName, msg.meterCap.Name, msg.meterCap.Version, msg.meterCode)
|
m := fmt.Sprintf("%s/%s/%d/%#02x", egressMeterName, msg.meterCap.Name, msg.meterCap.Version, msg.meterCode)
|
||||||
metrics.GetOrRegisterMeter(m, nil).Mark(int64(msg.meterSize))
|
metrics.GetOrRegisterMeter(m, nil).Mark(int64(msg.meterSize))
|
||||||
metrics.GetOrRegisterMeter(m+"/packets", nil).Mark(1)
|
metrics.GetOrRegisterMeter(m+"/packets", nil).Mark(1)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue