Add metrics to discv5 (#749)
This commit is contained in:
parent
e9c2292776
commit
74ce515ab2
|
@ -0,0 +1,38 @@
|
|||
diff --git c/p2p/discv5/metrics.go w/p2p/discv5/metrics.go
|
||||
new file mode 100644
|
||||
index 000000000..1092935cf
|
||||
--- /dev/null
|
||||
+++ w/p2p/discv5/metrics.go
|
||||
@@ -0,0 +1,8 @@
|
||||
+package discv5
|
||||
+
|
||||
+import "github.com/ethereum/go-ethereum/metrics"
|
||||
+
|
||||
+var (
|
||||
+ ingressTrafficMeter = metrics.NewMeter("discv5/InboundTraffic")
|
||||
+ egressTrafficMeter = metrics.NewMeter("discv5/OutboundTraffic")
|
||||
+)
|
||||
diff --git c/p2p/discv5/udp.go w/p2p/discv5/udp.go
|
||||
index 6ce72d2c1..308cf8637 100644
|
||||
--- c/p2p/discv5/udp.go
|
||||
+++ w/p2p/discv5/udp.go
|
||||
@@ -342,8 +342,10 @@ func (t *udp) sendPacket(toid NodeID, toaddr *net.UDPAddr, ptype byte, req inter
|
||||
return hash, err
|
||||
}
|
||||
log.Trace(fmt.Sprintf(">>> %v to %x@%v", nodeEvent(ptype), toid[:8], toaddr))
|
||||
- if _, err = t.conn.WriteToUDP(packet, toaddr); err != nil {
|
||||
+ if nbytes, err := t.conn.WriteToUDP(packet, toaddr); err != nil {
|
||||
log.Trace(fmt.Sprint("UDP send failed:", err))
|
||||
+ } else {
|
||||
+ egressTrafficMeter.Mark(int64(nbytes))
|
||||
}
|
||||
//fmt.Println(err)
|
||||
return hash, err
|
||||
@@ -382,6 +384,7 @@ func (t *udp) readLoop() {
|
||||
buf := make([]byte, 1280)
|
||||
for {
|
||||
nbytes, from, err := t.conn.ReadFromUDP(buf)
|
||||
+ ingressTrafficMeter.Mark(int64(nbytes))
|
||||
if netutil.IsTemporaryError(err) {
|
||||
// Ignore temporary read errors.
|
||||
log.Debug(fmt.Sprintf("Temporary read error: %v", err))
|
|
@ -0,0 +1,8 @@
|
|||
package discv5
|
||||
|
||||
import "github.com/ethereum/go-ethereum/metrics"
|
||||
|
||||
var (
|
||||
ingressTrafficMeter = metrics.NewMeter("discv5/InboundTraffic")
|
||||
egressTrafficMeter = metrics.NewMeter("discv5/OutboundTraffic")
|
||||
)
|
|
@ -342,8 +342,10 @@ func (t *udp) sendPacket(toid NodeID, toaddr *net.UDPAddr, ptype byte, req inter
|
|||
return hash, err
|
||||
}
|
||||
log.Trace(fmt.Sprintf(">>> %v to %x@%v", nodeEvent(ptype), toid[:8], toaddr))
|
||||
if _, err = t.conn.WriteToUDP(packet, toaddr); err != nil {
|
||||
if nbytes, err := t.conn.WriteToUDP(packet, toaddr); err != nil {
|
||||
log.Trace(fmt.Sprint("UDP send failed:", err))
|
||||
} else {
|
||||
egressTrafficMeter.Mark(int64(nbytes))
|
||||
}
|
||||
//fmt.Println(err)
|
||||
return hash, err
|
||||
|
@ -382,6 +384,7 @@ func (t *udp) readLoop() {
|
|||
buf := make([]byte, 1280)
|
||||
for {
|
||||
nbytes, from, err := t.conn.ReadFromUDP(buf)
|
||||
ingressTrafficMeter.Mark(int64(nbytes))
|
||||
if netutil.IsTemporaryError(err) {
|
||||
// Ignore temporary read errors.
|
||||
log.Debug(fmt.Sprintf("Temporary read error: %v", err))
|
||||
|
|
Loading…
Reference in New Issue