p2p/discv5: add egress/ingress traffic metrics to discv5 udp transport (#16369)
This commit is contained in:
parent
84f8c0cc1f
commit
7677ec1f34
|
@ -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)
|
||||
)
|
|
@ -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
|
||||
|
@ -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))
|
||||
|
|
Loading…
Reference in New Issue