Skip to content
This repository has been archived by the owner on Aug 2, 2021. It is now read-only.

Commit

Permalink
p2p/discv5: add egress/ingress traffic metrics to discv5 udp transpor…
Browse files Browse the repository at this point in the history
…t (#16369)
  • Loading branch information
dshulyak authored and acud committed Jun 4, 2018
1 parent 463ff93 commit 9f8f2e7
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
8 changes: 8 additions & 0 deletions p2p/discv5/metrics.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package discv5

import "github.com/ethereum/go-ethereum/metrics"

var (
ingressTrafficMeter = metrics.NewRegisteredMeter("discv5/InboundTraffic", nil)
egressTrafficMeter = metrics.NewRegisteredMeter("discv5/OutboundTraffic", nil)
)
5 changes: 4 additions & 1 deletion p2p/discv5/udp.go
Original file line number Diff line number Diff line change
Expand Up @@ -334,8 +334,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
Expand Down Expand Up @@ -374,6 +376,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))
Expand Down

0 comments on commit 9f8f2e7

Please sign in to comment.