aboutsummaryrefslogtreecommitdiffstats
path: root/p2p/metrics.go
diff options
context:
space:
mode:
authorJeffrey Wilcke <geffobscura@gmail.com>2015-06-30 08:22:19 +0800
committerJeffrey Wilcke <geffobscura@gmail.com>2015-06-30 08:22:19 +0800
commit7625b07dd9a2a7b5c5a504c1276eea04596ac871 (patch)
treece2a757cd4e0591fc15815b2dfae528ae517d36e /p2p/metrics.go
parent72e2613a9fe3205fa5a67b72b832e03b2357ee88 (diff)
parent8f504063f465e0ca10c6bb53ee914d10a3d45c86 (diff)
downloadgo-tangerine-7625b07dd9a2a7b5c5a504c1276eea04596ac871.tar
go-tangerine-7625b07dd9a2a7b5c5a504c1276eea04596ac871.tar.gz
go-tangerine-7625b07dd9a2a7b5c5a504c1276eea04596ac871.tar.bz2
go-tangerine-7625b07dd9a2a7b5c5a504c1276eea04596ac871.tar.lz
go-tangerine-7625b07dd9a2a7b5c5a504c1276eea04596ac871.tar.xz
go-tangerine-7625b07dd9a2a7b5c5a504c1276eea04596ac871.tar.zst
go-tangerine-7625b07dd9a2a7b5c5a504c1276eea04596ac871.zip
Merge branch 'release/0.9.34'v0.9.34
Diffstat (limited to 'p2p/metrics.go')
-rw-r--r--p2p/metrics.go49
1 files changed, 49 insertions, 0 deletions
diff --git a/p2p/metrics.go b/p2p/metrics.go
new file mode 100644
index 000000000..4b519e438
--- /dev/null
+++ b/p2p/metrics.go
@@ -0,0 +1,49 @@
+// Contains the meters and timers used by the networking layer.
+
+package p2p
+
+import (
+ "net"
+
+ "github.com/ethereum/go-ethereum/metrics"
+)
+
+var (
+ ingressConnectMeter = metrics.NewMeter("p2p/InboundConnects")
+ ingressTrafficMeter = metrics.NewMeter("p2p/InboundTraffic")
+ egressConnectMeter = metrics.NewMeter("p2p/OutboundConnects")
+ egressTrafficMeter = metrics.NewMeter("p2p/OutboundTraffic")
+)
+
+// meteredConn is a wrapper around a network TCP connection that meters both the
+// inbound and outbound network traffic.
+type meteredConn struct {
+ *net.TCPConn // Network connection to wrap with metering
+}
+
+// newMeteredConn creates a new metered connection, also bumping the ingress or
+// egress connection meter.
+func newMeteredConn(conn net.Conn, ingress bool) net.Conn {
+ if ingress {
+ ingressConnectMeter.Mark(1)
+ } else {
+ egressConnectMeter.Mark(1)
+ }
+ return &meteredConn{conn.(*net.TCPConn)}
+}
+
+// Read delegates a network read to the underlying connection, bumping the ingress
+// traffic meter along the way.
+func (c *meteredConn) Read(b []byte) (n int, err error) {
+ n, err = c.TCPConn.Read(b)
+ ingressTrafficMeter.Mark(int64(n))
+ return
+}
+
+// Write delegates a network write to the underlying connection, bumping the
+// egress traffic meter along the way.
+func (c *meteredConn) Write(b []byte) (n int, err error) {
+ n, err = c.TCPConn.Write(b)
+ egressTrafficMeter.Mark(int64(n))
+ return
+}