|
| 1 | +// Copyright 2023 The go-ethereum Authors |
| 2 | +// This file is part of the go-ethereum library. |
| 3 | +// |
| 4 | +// The go-ethereum library is free software: you can redistribute it and/or modify |
| 5 | +// it under the terms of the GNU Lesser General Public License as published by |
| 6 | +// the Free Software Foundation, either version 3 of the License, or |
| 7 | +// (at your option) any later version. |
| 8 | +// |
| 9 | +// The go-ethereum library is distributed in the hope that it will be useful, |
| 10 | +// but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | +// GNU Lesser General Public License for more details. |
| 13 | +// |
| 14 | +// You should have received a copy of the GNU Lesser General Public License |
| 15 | +// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>. |
| 16 | + |
| 17 | +package eth |
| 18 | + |
| 19 | +import "github.com/ethereum/go-ethereum/metrics" |
| 20 | + |
| 21 | +// meters stores ingress and egress handshake meters. |
| 22 | +var meters bidirectionalMeters |
| 23 | + |
| 24 | +// bidirectionalMeters stores ingress and egress handshake meters. |
| 25 | +type bidirectionalMeters struct { |
| 26 | + ingress *hsMeters |
| 27 | + egress *hsMeters |
| 28 | +} |
| 29 | + |
| 30 | +// Get returns the corresponding meter depending if ingress or egress is |
| 31 | +// desired. |
| 32 | +func (h *bidirectionalMeters) Get(ingress bool) *hsMeters { |
| 33 | + if ingress { |
| 34 | + return h.ingress |
| 35 | + } |
| 36 | + return h.egress |
| 37 | +} |
| 38 | + |
| 39 | +// hsMeters is a collection of meters which track metrics related to the |
| 40 | +// eth subprotocol handshake. |
| 41 | +type hsMeters struct { |
| 42 | + // peerError measures the number of errors related to incorrect peer |
| 43 | + // behaviour, such as invalid message code, size, encoding, etc. |
| 44 | + peerError metrics.Meter |
| 45 | + |
| 46 | + // timeoutError measures the number of timeouts. |
| 47 | + timeoutError metrics.Meter |
| 48 | + |
| 49 | + // networkIDMismatch measures the number of network id mismatch errors. |
| 50 | + networkIDMismatch metrics.Meter |
| 51 | + |
| 52 | + // protocolVersionMismatch measures the number of differing protocol |
| 53 | + // versions. |
| 54 | + protocolVersionMismatch metrics.Meter |
| 55 | + |
| 56 | + // genesisMismatch measures the number of differing genesises. |
| 57 | + genesisMismatch metrics.Meter |
| 58 | + |
| 59 | + // forkidRejected measures the number of differing forkids. |
| 60 | + forkidRejected metrics.Meter |
| 61 | +} |
| 62 | + |
| 63 | +// newHandshakeMeters registers and returns handshake meters for the given |
| 64 | +// base. |
| 65 | +func newHandshakeMeters(base string) *hsMeters { |
| 66 | + return &hsMeters{ |
| 67 | + peerError: metrics.NewRegisteredMeter(base+"error/peer", nil), |
| 68 | + timeoutError: metrics.NewRegisteredMeter(base+"error/timeout", nil), |
| 69 | + networkIDMismatch: metrics.NewRegisteredMeter(base+"error/network", nil), |
| 70 | + protocolVersionMismatch: metrics.NewRegisteredMeter(base+"error/version", nil), |
| 71 | + genesisMismatch: metrics.NewRegisteredMeter(base+"error/genesis", nil), |
| 72 | + forkidRejected: metrics.NewRegisteredMeter(base+"error/forkid", nil), |
| 73 | + } |
| 74 | +} |
| 75 | + |
| 76 | +func init() { |
| 77 | + meters = bidirectionalMeters{ |
| 78 | + ingress: newHandshakeMeters("eth/protocols/eth/ingress/handshake/"), |
| 79 | + egress: newHandshakeMeters("eth/protocols/eth/egress/handshake/"), |
| 80 | + } |
| 81 | +} |
0 commit comments